]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.17.3-201411150027.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.17.3-201411150027.patch
CommitLineData
8572ad5d
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 764f599..c600e2f 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 1edd5fd..107ff46 100644
317--- a/Documentation/kernel-parameters.txt
318+++ b/Documentation/kernel-parameters.txt
319@@ -1155,6 +1155,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@@ -2175,6 +2179,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@@ -2467,6 +2475,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 57a45b1..62f9358 100644
374--- a/Makefile
375+++ b/Makefile
376@@ -303,8 +303,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
377
378 HOSTCC = gcc
379 HOSTCXX = g++
380-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
381-HOSTCXXFLAGS = -O2
382+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
383+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
384+HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
385
386 ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
387 HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
388@@ -450,8 +451,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
389 # Rules shared between *config targets and build targets
390
391 # Basic helpers built in scripts/
392-PHONY += scripts_basic
393-scripts_basic:
394+PHONY += scripts_basic gcc-plugins
395+scripts_basic: gcc-plugins
396 $(Q)$(MAKE) $(build)=scripts/basic
397 $(Q)rm -f .tmp_quiet_recordmcount
398
399@@ -625,6 +626,72 @@ endif
400 # Tell gcc to never replace conditional load with a non-conditional one
401 KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
402
403+ifndef DISABLE_PAX_PLUGINS
404+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
405+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
406+else
407+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
408+endif
409+ifneq ($(PLUGINCC),)
410+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
411+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
412+endif
413+ifdef CONFIG_PAX_MEMORY_STACKLEAK
414+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
415+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
416+endif
417+ifdef CONFIG_KALLOCSTAT_PLUGIN
418+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
419+endif
420+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
421+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
422+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
423+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
424+endif
425+ifdef CONFIG_GRKERNSEC_RANDSTRUCT
426+RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
427+ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
428+RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
429+endif
430+endif
431+ifdef CONFIG_CHECKER_PLUGIN
432+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
433+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
434+endif
435+endif
436+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
437+ifdef CONFIG_PAX_SIZE_OVERFLOW
438+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
439+endif
440+ifdef CONFIG_PAX_LATENT_ENTROPY
441+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
442+endif
443+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
444+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
445+endif
446+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
447+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
448+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
449+GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
450+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
451+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
452+ifeq ($(KBUILD_EXTMOD),)
453+gcc-plugins:
454+ $(Q)$(MAKE) $(build)=tools/gcc
455+else
456+gcc-plugins: ;
457+endif
458+else
459+gcc-plugins:
460+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
461+ $(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.))
462+else
463+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
464+endif
465+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
466+endif
467+endif
468+
469 ifdef CONFIG_READABLE_ASM
470 # Disable optimizations that make assembler listings hard to read.
471 # reorder blocks reorders the control in the function
472@@ -717,7 +784,7 @@ KBUILD_CFLAGS += $(call cc-option, -gsplit-dwarf, -g)
473 else
474 KBUILD_CFLAGS += -g
475 endif
476-KBUILD_AFLAGS += -Wa,-gdwarf-2
477+KBUILD_AFLAGS += -Wa,--gdwarf-2
478 endif
479 ifdef CONFIG_DEBUG_INFO_DWARF4
480 KBUILD_CFLAGS += $(call cc-option, -gdwarf-4,)
481@@ -867,7 +934,7 @@ export mod_sign_cmd
482
483
484 ifeq ($(KBUILD_EXTMOD),)
485-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
486+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
487
488 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
489 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
490@@ -916,6 +983,8 @@ endif
491
492 # The actual objects are generated when descending,
493 # make sure no implicit rule kicks in
494+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
495+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
496 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
497
498 # Handle descending into subdirectories listed in $(vmlinux-dirs)
499@@ -925,7 +994,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
500 # Error messages still appears in the original language
501
502 PHONY += $(vmlinux-dirs)
503-$(vmlinux-dirs): prepare scripts
504+$(vmlinux-dirs): gcc-plugins prepare scripts
505 $(Q)$(MAKE) $(build)=$@
506
507 define filechk_kernel.release
508@@ -968,10 +1037,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
509
510 archprepare: archheaders archscripts prepare1 scripts_basic
511
512+prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
513+prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
514 prepare0: archprepare FORCE
515 $(Q)$(MAKE) $(build)=.
516
517 # All the preparing..
518+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
519 prepare: prepare0
520
521 # Generate some files
522@@ -1086,6 +1158,8 @@ all: modules
523 # using awk while concatenating to the final file.
524
525 PHONY += modules
526+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
527+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
528 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
529 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
530 @$(kecho) ' Building modules, stage 2.';
531@@ -1101,7 +1175,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
532
533 # Target to prepare building external modules
534 PHONY += modules_prepare
535-modules_prepare: prepare scripts
536+modules_prepare: gcc-plugins prepare scripts
537
538 # Target to install modules
539 PHONY += modules_install
540@@ -1167,7 +1241,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
541 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
542 signing_key.priv signing_key.x509 x509.genkey \
543 extra_certificates signing_key.x509.keyid \
544- signing_key.x509.signer include/linux/version.h
545+ signing_key.x509.signer include/linux/version.h \
546+ tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
547+ tools/gcc/size_overflow_plugin/size_overflow_hash.h \
548+ tools/gcc/randomize_layout_seed.h
549
550 # clean - Delete most, but leave enough to build external modules
551 #
552@@ -1206,7 +1283,7 @@ distclean: mrproper
553 @find $(srctree) $(RCS_FIND_IGNORE) \
554 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
555 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
556- -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
557+ -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
558 -type f -print | xargs rm -f
559
560
561@@ -1372,6 +1449,8 @@ PHONY += $(module-dirs) modules
562 $(module-dirs): crmodverdir $(objtree)/Module.symvers
563 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
564
565+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
566+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
567 modules: $(module-dirs)
568 @$(kecho) ' Building modules, stage 2.';
569 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
570@@ -1512,17 +1591,21 @@ else
571 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
572 endif
573
574-%.s: %.c prepare scripts FORCE
575+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
576+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
577+%.s: %.c gcc-plugins prepare scripts FORCE
578 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
579 %.i: %.c prepare scripts FORCE
580 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
581-%.o: %.c prepare scripts FORCE
582+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
583+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
584+%.o: %.c gcc-plugins prepare scripts FORCE
585 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
586 %.lst: %.c prepare scripts FORCE
587 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
588-%.s: %.S prepare scripts FORCE
589+%.s: %.S gcc-plugins prepare scripts FORCE
590 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
591-%.o: %.S prepare scripts FORCE
592+%.o: %.S gcc-plugins prepare scripts FORCE
593 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
594 %.symtypes: %.c prepare scripts FORCE
595 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
596@@ -1532,11 +1615,15 @@ endif
597 $(cmd_crmodverdir)
598 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
599 $(build)=$(build-dir)
600-%/: prepare scripts FORCE
601+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
602+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
603+%/: gcc-plugins prepare scripts FORCE
604 $(cmd_crmodverdir)
605 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
606 $(build)=$(build-dir)
607-%.ko: prepare scripts FORCE
608+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
609+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
610+%.ko: gcc-plugins prepare scripts FORCE
611 $(cmd_crmodverdir)
612 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
613 $(build)=$(build-dir) $(@:.ko=.o)
614diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
615index ed60a1e..47f1a55 100644
616--- a/arch/alpha/include/asm/atomic.h
617+++ b/arch/alpha/include/asm/atomic.h
618@@ -292,4 +292,14 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
619 #define atomic_dec(v) atomic_sub(1,(v))
620 #define atomic64_dec(v) atomic64_sub(1,(v))
621
622+#define atomic64_read_unchecked(v) atomic64_read(v)
623+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
624+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
625+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
626+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
627+#define atomic64_inc_unchecked(v) atomic64_inc(v)
628+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
629+#define atomic64_dec_unchecked(v) atomic64_dec(v)
630+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
631+
632 #endif /* _ALPHA_ATOMIC_H */
633diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
634index ad368a9..fbe0f25 100644
635--- a/arch/alpha/include/asm/cache.h
636+++ b/arch/alpha/include/asm/cache.h
637@@ -4,19 +4,19 @@
638 #ifndef __ARCH_ALPHA_CACHE_H
639 #define __ARCH_ALPHA_CACHE_H
640
641+#include <linux/const.h>
642
643 /* Bytes per L1 (data) cache line. */
644 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
645-# define L1_CACHE_BYTES 64
646 # define L1_CACHE_SHIFT 6
647 #else
648 /* Both EV4 and EV5 are write-through, read-allocate,
649 direct-mapped, physical.
650 */
651-# define L1_CACHE_BYTES 32
652 # define L1_CACHE_SHIFT 5
653 #endif
654
655+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
656 #define SMP_CACHE_BYTES L1_CACHE_BYTES
657
658 #endif
659diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
660index 968d999..d36b2df 100644
661--- a/arch/alpha/include/asm/elf.h
662+++ b/arch/alpha/include/asm/elf.h
663@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
664
665 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
666
667+#ifdef CONFIG_PAX_ASLR
668+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
669+
670+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
671+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
672+#endif
673+
674 /* $0 is set by ld.so to a pointer to a function which might be
675 registered using atexit. This provides a mean for the dynamic
676 linker to call DT_FINI functions for shared libraries that have
677diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
678index aab14a0..b4fa3e7 100644
679--- a/arch/alpha/include/asm/pgalloc.h
680+++ b/arch/alpha/include/asm/pgalloc.h
681@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
682 pgd_set(pgd, pmd);
683 }
684
685+static inline void
686+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
687+{
688+ pgd_populate(mm, pgd, pmd);
689+}
690+
691 extern pgd_t *pgd_alloc(struct mm_struct *mm);
692
693 static inline void
694diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
695index d8f9b7e..f6222fa 100644
696--- a/arch/alpha/include/asm/pgtable.h
697+++ b/arch/alpha/include/asm/pgtable.h
698@@ -102,6 +102,17 @@ struct vm_area_struct;
699 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
700 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
701 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
702+
703+#ifdef CONFIG_PAX_PAGEEXEC
704+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
705+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
706+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
707+#else
708+# define PAGE_SHARED_NOEXEC PAGE_SHARED
709+# define PAGE_COPY_NOEXEC PAGE_COPY
710+# define PAGE_READONLY_NOEXEC PAGE_READONLY
711+#endif
712+
713 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
714
715 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
716diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
717index 2fd00b7..cfd5069 100644
718--- a/arch/alpha/kernel/module.c
719+++ b/arch/alpha/kernel/module.c
720@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
721
722 /* The small sections were sorted to the end of the segment.
723 The following should definitely cover them. */
724- gp = (u64)me->module_core + me->core_size - 0x8000;
725+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
726 got = sechdrs[me->arch.gotsecindex].sh_addr;
727
728 for (i = 0; i < n; i++) {
729diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
730index 1402fcc..0b1abd2 100644
731--- a/arch/alpha/kernel/osf_sys.c
732+++ b/arch/alpha/kernel/osf_sys.c
733@@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
734 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
735
736 static unsigned long
737-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
738- unsigned long limit)
739+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
740+ unsigned long limit, unsigned long flags)
741 {
742 struct vm_unmapped_area_info info;
743+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
744
745 info.flags = 0;
746 info.length = len;
747@@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
748 info.high_limit = limit;
749 info.align_mask = 0;
750 info.align_offset = 0;
751+ info.threadstack_offset = offset;
752 return vm_unmapped_area(&info);
753 }
754
755@@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
756 merely specific addresses, but regions of memory -- perhaps
757 this feature should be incorporated into all ports? */
758
759+#ifdef CONFIG_PAX_RANDMMAP
760+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
761+#endif
762+
763 if (addr) {
764- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
765+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
766 if (addr != (unsigned long) -ENOMEM)
767 return addr;
768 }
769
770 /* Next, try allocating at TASK_UNMAPPED_BASE. */
771- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
772- len, limit);
773+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
774+
775 if (addr != (unsigned long) -ENOMEM)
776 return addr;
777
778 /* Finally, try allocating in low memory. */
779- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
780+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
781
782 return addr;
783 }
784diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
785index 98838a0..b304fb4 100644
786--- a/arch/alpha/mm/fault.c
787+++ b/arch/alpha/mm/fault.c
788@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
789 __reload_thread(pcb);
790 }
791
792+#ifdef CONFIG_PAX_PAGEEXEC
793+/*
794+ * PaX: decide what to do with offenders (regs->pc = fault address)
795+ *
796+ * returns 1 when task should be killed
797+ * 2 when patched PLT trampoline was detected
798+ * 3 when unpatched PLT trampoline was detected
799+ */
800+static int pax_handle_fetch_fault(struct pt_regs *regs)
801+{
802+
803+#ifdef CONFIG_PAX_EMUPLT
804+ int err;
805+
806+ do { /* PaX: patched PLT emulation #1 */
807+ unsigned int ldah, ldq, jmp;
808+
809+ err = get_user(ldah, (unsigned int *)regs->pc);
810+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
811+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
812+
813+ if (err)
814+ break;
815+
816+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
817+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
818+ jmp == 0x6BFB0000U)
819+ {
820+ unsigned long r27, addr;
821+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
822+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
823+
824+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
825+ err = get_user(r27, (unsigned long *)addr);
826+ if (err)
827+ break;
828+
829+ regs->r27 = r27;
830+ regs->pc = r27;
831+ return 2;
832+ }
833+ } while (0);
834+
835+ do { /* PaX: patched PLT emulation #2 */
836+ unsigned int ldah, lda, br;
837+
838+ err = get_user(ldah, (unsigned int *)regs->pc);
839+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
840+ err |= get_user(br, (unsigned int *)(regs->pc+8));
841+
842+ if (err)
843+ break;
844+
845+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
846+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
847+ (br & 0xFFE00000U) == 0xC3E00000U)
848+ {
849+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
850+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
851+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
852+
853+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
854+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
855+ return 2;
856+ }
857+ } while (0);
858+
859+ do { /* PaX: unpatched PLT emulation */
860+ unsigned int br;
861+
862+ err = get_user(br, (unsigned int *)regs->pc);
863+
864+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
865+ unsigned int br2, ldq, nop, jmp;
866+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
867+
868+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
869+ err = get_user(br2, (unsigned int *)addr);
870+ err |= get_user(ldq, (unsigned int *)(addr+4));
871+ err |= get_user(nop, (unsigned int *)(addr+8));
872+ err |= get_user(jmp, (unsigned int *)(addr+12));
873+ err |= get_user(resolver, (unsigned long *)(addr+16));
874+
875+ if (err)
876+ break;
877+
878+ if (br2 == 0xC3600000U &&
879+ ldq == 0xA77B000CU &&
880+ nop == 0x47FF041FU &&
881+ jmp == 0x6B7B0000U)
882+ {
883+ regs->r28 = regs->pc+4;
884+ regs->r27 = addr+16;
885+ regs->pc = resolver;
886+ return 3;
887+ }
888+ }
889+ } while (0);
890+#endif
891+
892+ return 1;
893+}
894+
895+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
896+{
897+ unsigned long i;
898+
899+ printk(KERN_ERR "PAX: bytes at PC: ");
900+ for (i = 0; i < 5; i++) {
901+ unsigned int c;
902+ if (get_user(c, (unsigned int *)pc+i))
903+ printk(KERN_CONT "???????? ");
904+ else
905+ printk(KERN_CONT "%08x ", c);
906+ }
907+ printk("\n");
908+}
909+#endif
910
911 /*
912 * This routine handles page faults. It determines the address,
913@@ -133,8 +251,29 @@ retry:
914 good_area:
915 si_code = SEGV_ACCERR;
916 if (cause < 0) {
917- if (!(vma->vm_flags & VM_EXEC))
918+ if (!(vma->vm_flags & VM_EXEC)) {
919+
920+#ifdef CONFIG_PAX_PAGEEXEC
921+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
922+ goto bad_area;
923+
924+ up_read(&mm->mmap_sem);
925+ switch (pax_handle_fetch_fault(regs)) {
926+
927+#ifdef CONFIG_PAX_EMUPLT
928+ case 2:
929+ case 3:
930+ return;
931+#endif
932+
933+ }
934+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
935+ do_group_exit(SIGKILL);
936+#else
937 goto bad_area;
938+#endif
939+
940+ }
941 } else if (!cause) {
942 /* Allow reads even for write-only mappings */
943 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
944diff --git a/arch/arc/kernel/kgdb.c b/arch/arc/kernel/kgdb.c
945index a2ff5c5..ecf6a78 100644
946--- a/arch/arc/kernel/kgdb.c
947+++ b/arch/arc/kernel/kgdb.c
948@@ -158,11 +158,6 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
949 return -1;
950 }
951
952-unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs)
953-{
954- return instruction_pointer(regs);
955-}
956-
957 int kgdb_arch_init(void)
958 {
959 single_step_data.armed = 0;
960diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
961index 32cbbd5..c102df9 100644
962--- a/arch/arm/Kconfig
963+++ b/arch/arm/Kconfig
964@@ -1719,7 +1719,7 @@ config ALIGNMENT_TRAP
965
966 config UACCESS_WITH_MEMCPY
967 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
968- depends on MMU
969+ depends on MMU && !PAX_MEMORY_UDEREF
970 default y if CPU_FEROCEON
971 help
972 Implement faster copy_to_user and clear_user methods for CPU
973@@ -1983,6 +1983,7 @@ config XIP_PHYS_ADDR
974 config KEXEC
975 bool "Kexec system call (EXPERIMENTAL)"
976 depends on (!SMP || PM_SLEEP_SMP)
977+ depends on !GRKERNSEC_KMEM
978 help
979 kexec is a system call that implements the ability to shutdown your
980 current kernel, and to start another kernel. It is like a reboot
981diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
982index 3040359..a494fa3 100644
983--- a/arch/arm/include/asm/atomic.h
984+++ b/arch/arm/include/asm/atomic.h
985@@ -18,17 +18,41 @@
986 #include <asm/barrier.h>
987 #include <asm/cmpxchg.h>
988
989+#ifdef CONFIG_GENERIC_ATOMIC64
990+#include <asm-generic/atomic64.h>
991+#endif
992+
993 #define ATOMIC_INIT(i) { (i) }
994
995 #ifdef __KERNEL__
996
997+#ifdef CONFIG_THUMB2_KERNEL
998+#define REFCOUNT_TRAP_INSN "bkpt 0xf1"
999+#else
1000+#define REFCOUNT_TRAP_INSN "bkpt 0xf103"
1001+#endif
1002+
1003+#define _ASM_EXTABLE(from, to) \
1004+" .pushsection __ex_table,\"a\"\n"\
1005+" .align 3\n" \
1006+" .long " #from ", " #to"\n" \
1007+" .popsection"
1008+
1009 /*
1010 * On ARM, ordinary assignment (str instruction) doesn't clear the local
1011 * strex/ldrex monitor on some implementations. The reason we can use it for
1012 * atomic_set() is the clrex or dummy strex done on every exception return.
1013 */
1014 #define atomic_read(v) (*(volatile int *)&(v)->counter)
1015+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
1016+{
1017+ return v->counter;
1018+}
1019 #define atomic_set(v,i) (((v)->counter) = (i))
1020+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
1021+{
1022+ v->counter = i;
1023+}
1024
1025 #if __LINUX_ARM_ARCH__ >= 6
1026
1027@@ -44,6 +68,36 @@ static inline void atomic_add(int i, atomic_t *v)
1028
1029 prefetchw(&v->counter);
1030 __asm__ __volatile__("@ atomic_add\n"
1031+"1: ldrex %1, [%3]\n"
1032+" adds %0, %1, %4\n"
1033+
1034+#ifdef CONFIG_PAX_REFCOUNT
1035+" bvc 3f\n"
1036+"2: " REFCOUNT_TRAP_INSN "\n"
1037+"3:\n"
1038+#endif
1039+
1040+" strex %1, %0, [%3]\n"
1041+" teq %1, #0\n"
1042+" bne 1b"
1043+
1044+#ifdef CONFIG_PAX_REFCOUNT
1045+"\n4:\n"
1046+ _ASM_EXTABLE(2b, 4b)
1047+#endif
1048+
1049+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1050+ : "r" (&v->counter), "Ir" (i)
1051+ : "cc");
1052+}
1053+
1054+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1055+{
1056+ unsigned long tmp;
1057+ int result;
1058+
1059+ prefetchw(&v->counter);
1060+ __asm__ __volatile__("@ atomic_add_unchecked\n"
1061 "1: ldrex %0, [%3]\n"
1062 " add %0, %0, %4\n"
1063 " strex %1, %0, [%3]\n"
1064@@ -63,6 +117,43 @@ static inline int atomic_add_return(int i, atomic_t *v)
1065 prefetchw(&v->counter);
1066
1067 __asm__ __volatile__("@ atomic_add_return\n"
1068+"1: ldrex %1, [%3]\n"
1069+" adds %0, %1, %4\n"
1070+
1071+#ifdef CONFIG_PAX_REFCOUNT
1072+" bvc 3f\n"
1073+" mov %0, %1\n"
1074+"2: " REFCOUNT_TRAP_INSN "\n"
1075+"3:\n"
1076+#endif
1077+
1078+" strex %1, %0, [%3]\n"
1079+" teq %1, #0\n"
1080+" bne 1b"
1081+
1082+#ifdef CONFIG_PAX_REFCOUNT
1083+"\n4:\n"
1084+ _ASM_EXTABLE(2b, 4b)
1085+#endif
1086+
1087+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1088+ : "r" (&v->counter), "Ir" (i)
1089+ : "cc");
1090+
1091+ smp_mb();
1092+
1093+ return result;
1094+}
1095+
1096+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1097+{
1098+ unsigned long tmp;
1099+ int result;
1100+
1101+ smp_mb();
1102+ prefetchw(&v->counter);
1103+
1104+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
1105 "1: ldrex %0, [%3]\n"
1106 " add %0, %0, %4\n"
1107 " strex %1, %0, [%3]\n"
1108@@ -84,6 +175,36 @@ static inline void atomic_sub(int i, atomic_t *v)
1109
1110 prefetchw(&v->counter);
1111 __asm__ __volatile__("@ atomic_sub\n"
1112+"1: ldrex %1, [%3]\n"
1113+" subs %0, %1, %4\n"
1114+
1115+#ifdef CONFIG_PAX_REFCOUNT
1116+" bvc 3f\n"
1117+"2: " REFCOUNT_TRAP_INSN "\n"
1118+"3:\n"
1119+#endif
1120+
1121+" strex %1, %0, [%3]\n"
1122+" teq %1, #0\n"
1123+" bne 1b"
1124+
1125+#ifdef CONFIG_PAX_REFCOUNT
1126+"\n4:\n"
1127+ _ASM_EXTABLE(2b, 4b)
1128+#endif
1129+
1130+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1131+ : "r" (&v->counter), "Ir" (i)
1132+ : "cc");
1133+}
1134+
1135+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1136+{
1137+ unsigned long tmp;
1138+ int result;
1139+
1140+ prefetchw(&v->counter);
1141+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
1142 "1: ldrex %0, [%3]\n"
1143 " sub %0, %0, %4\n"
1144 " strex %1, %0, [%3]\n"
1145@@ -103,11 +224,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1146 prefetchw(&v->counter);
1147
1148 __asm__ __volatile__("@ atomic_sub_return\n"
1149-"1: ldrex %0, [%3]\n"
1150-" sub %0, %0, %4\n"
1151+"1: ldrex %1, [%3]\n"
1152+" subs %0, %1, %4\n"
1153+
1154+#ifdef CONFIG_PAX_REFCOUNT
1155+" bvc 3f\n"
1156+" mov %0, %1\n"
1157+"2: " REFCOUNT_TRAP_INSN "\n"
1158+"3:\n"
1159+#endif
1160+
1161 " strex %1, %0, [%3]\n"
1162 " teq %1, #0\n"
1163 " bne 1b"
1164+
1165+#ifdef CONFIG_PAX_REFCOUNT
1166+"\n4:\n"
1167+ _ASM_EXTABLE(2b, 4b)
1168+#endif
1169+
1170 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1171 : "r" (&v->counter), "Ir" (i)
1172 : "cc");
1173@@ -152,12 +287,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1174 __asm__ __volatile__ ("@ atomic_add_unless\n"
1175 "1: ldrex %0, [%4]\n"
1176 " teq %0, %5\n"
1177-" beq 2f\n"
1178-" add %1, %0, %6\n"
1179+" beq 4f\n"
1180+" adds %1, %0, %6\n"
1181+
1182+#ifdef CONFIG_PAX_REFCOUNT
1183+" bvc 3f\n"
1184+"2: " REFCOUNT_TRAP_INSN "\n"
1185+"3:\n"
1186+#endif
1187+
1188 " strex %2, %1, [%4]\n"
1189 " teq %2, #0\n"
1190 " bne 1b\n"
1191-"2:"
1192+"4:"
1193+
1194+#ifdef CONFIG_PAX_REFCOUNT
1195+ _ASM_EXTABLE(2b, 4b)
1196+#endif
1197+
1198 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1199 : "r" (&v->counter), "r" (u), "r" (a)
1200 : "cc");
1201@@ -168,6 +315,28 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1202 return oldval;
1203 }
1204
1205+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1206+{
1207+ unsigned long oldval, res;
1208+
1209+ smp_mb();
1210+
1211+ do {
1212+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1213+ "ldrex %1, [%3]\n"
1214+ "mov %0, #0\n"
1215+ "teq %1, %4\n"
1216+ "strexeq %0, %5, [%3]\n"
1217+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1218+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1219+ : "cc");
1220+ } while (res);
1221+
1222+ smp_mb();
1223+
1224+ return oldval;
1225+}
1226+
1227 #else /* ARM_ARCH_6 */
1228
1229 #ifdef CONFIG_SMP
1230@@ -186,7 +355,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1231
1232 return val;
1233 }
1234+
1235+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1236+{
1237+ return atomic_add_return(i, v);
1238+}
1239+
1240 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1241+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1242+{
1243+ (void) atomic_add_return(i, v);
1244+}
1245
1246 static inline int atomic_sub_return(int i, atomic_t *v)
1247 {
1248@@ -201,6 +380,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1249 return val;
1250 }
1251 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1252+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1253+{
1254+ (void) atomic_sub_return(i, v);
1255+}
1256
1257 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1258 {
1259@@ -216,6 +399,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1260 return ret;
1261 }
1262
1263+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1264+{
1265+ return atomic_cmpxchg(v, old, new);
1266+}
1267+
1268 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1269 {
1270 int c, old;
1271@@ -229,13 +417,33 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1272 #endif /* __LINUX_ARM_ARCH__ */
1273
1274 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1275+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1276+{
1277+ return xchg(&v->counter, new);
1278+}
1279
1280 #define atomic_inc(v) atomic_add(1, v)
1281+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1282+{
1283+ atomic_add_unchecked(1, v);
1284+}
1285 #define atomic_dec(v) atomic_sub(1, v)
1286+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1287+{
1288+ atomic_sub_unchecked(1, v);
1289+}
1290
1291 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1292+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1293+{
1294+ return atomic_add_return_unchecked(1, v) == 0;
1295+}
1296 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1297 #define atomic_inc_return(v) (atomic_add_return(1, v))
1298+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1299+{
1300+ return atomic_add_return_unchecked(1, v);
1301+}
1302 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1303 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1304
1305@@ -246,6 +454,14 @@ typedef struct {
1306 long long counter;
1307 } atomic64_t;
1308
1309+#ifdef CONFIG_PAX_REFCOUNT
1310+typedef struct {
1311+ long long counter;
1312+} atomic64_unchecked_t;
1313+#else
1314+typedef atomic64_t atomic64_unchecked_t;
1315+#endif
1316+
1317 #define ATOMIC64_INIT(i) { (i) }
1318
1319 #ifdef CONFIG_ARM_LPAE
1320@@ -262,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1321 return result;
1322 }
1323
1324+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1325+{
1326+ long long result;
1327+
1328+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1329+" ldrd %0, %H0, [%1]"
1330+ : "=&r" (result)
1331+ : "r" (&v->counter), "Qo" (v->counter)
1332+ );
1333+
1334+ return result;
1335+}
1336+
1337 static inline void atomic64_set(atomic64_t *v, long long i)
1338 {
1339 __asm__ __volatile__("@ atomic64_set\n"
1340@@ -270,6 +499,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1341 : "r" (&v->counter), "r" (i)
1342 );
1343 }
1344+
1345+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1346+{
1347+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1348+" strd %2, %H2, [%1]"
1349+ : "=Qo" (v->counter)
1350+ : "r" (&v->counter), "r" (i)
1351+ );
1352+}
1353 #else
1354 static inline long long atomic64_read(const atomic64_t *v)
1355 {
1356@@ -284,6 +522,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1357 return result;
1358 }
1359
1360+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1361+{
1362+ long long result;
1363+
1364+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1365+" ldrexd %0, %H0, [%1]"
1366+ : "=&r" (result)
1367+ : "r" (&v->counter), "Qo" (v->counter)
1368+ );
1369+
1370+ return result;
1371+}
1372+
1373 static inline void atomic64_set(atomic64_t *v, long long i)
1374 {
1375 long long tmp;
1376@@ -298,6 +549,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1377 : "r" (&v->counter), "r" (i)
1378 : "cc");
1379 }
1380+
1381+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1382+{
1383+ long long tmp;
1384+
1385+ prefetchw(&v->counter);
1386+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1387+"1: ldrexd %0, %H0, [%2]\n"
1388+" strexd %0, %3, %H3, [%2]\n"
1389+" teq %0, #0\n"
1390+" bne 1b"
1391+ : "=&r" (tmp), "=Qo" (v->counter)
1392+ : "r" (&v->counter), "r" (i)
1393+ : "cc");
1394+}
1395 #endif
1396
1397 static inline void atomic64_add(long long i, atomic64_t *v)
1398@@ -309,6 +575,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1399 __asm__ __volatile__("@ atomic64_add\n"
1400 "1: ldrexd %0, %H0, [%3]\n"
1401 " adds %Q0, %Q0, %Q4\n"
1402+" adcs %R0, %R0, %R4\n"
1403+
1404+#ifdef CONFIG_PAX_REFCOUNT
1405+" bvc 3f\n"
1406+"2: " REFCOUNT_TRAP_INSN "\n"
1407+"3:\n"
1408+#endif
1409+
1410+" strexd %1, %0, %H0, [%3]\n"
1411+" teq %1, #0\n"
1412+" bne 1b"
1413+
1414+#ifdef CONFIG_PAX_REFCOUNT
1415+"\n4:\n"
1416+ _ASM_EXTABLE(2b, 4b)
1417+#endif
1418+
1419+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1420+ : "r" (&v->counter), "r" (i)
1421+ : "cc");
1422+}
1423+
1424+static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1425+{
1426+ long long result;
1427+ unsigned long tmp;
1428+
1429+ prefetchw(&v->counter);
1430+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1431+"1: ldrexd %0, %H0, [%3]\n"
1432+" adds %Q0, %Q0, %Q4\n"
1433 " adc %R0, %R0, %R4\n"
1434 " strexd %1, %0, %H0, [%3]\n"
1435 " teq %1, #0\n"
1436@@ -329,6 +626,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1437 __asm__ __volatile__("@ atomic64_add_return\n"
1438 "1: ldrexd %0, %H0, [%3]\n"
1439 " adds %Q0, %Q0, %Q4\n"
1440+" adcs %R0, %R0, %R4\n"
1441+
1442+#ifdef CONFIG_PAX_REFCOUNT
1443+" bvc 3f\n"
1444+" mov %0, %1\n"
1445+" mov %H0, %H1\n"
1446+"2: " REFCOUNT_TRAP_INSN "\n"
1447+"3:\n"
1448+#endif
1449+
1450+" strexd %1, %0, %H0, [%3]\n"
1451+" teq %1, #0\n"
1452+" bne 1b"
1453+
1454+#ifdef CONFIG_PAX_REFCOUNT
1455+"\n4:\n"
1456+ _ASM_EXTABLE(2b, 4b)
1457+#endif
1458+
1459+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1460+ : "r" (&v->counter), "r" (i)
1461+ : "cc");
1462+
1463+ smp_mb();
1464+
1465+ return result;
1466+}
1467+
1468+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1469+{
1470+ long long result;
1471+ unsigned long tmp;
1472+
1473+ smp_mb();
1474+
1475+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1476+"1: ldrexd %0, %H0, [%3]\n"
1477+" adds %Q0, %Q0, %Q4\n"
1478 " adc %R0, %R0, %R4\n"
1479 " strexd %1, %0, %H0, [%3]\n"
1480 " teq %1, #0\n"
1481@@ -351,6 +686,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1482 __asm__ __volatile__("@ atomic64_sub\n"
1483 "1: ldrexd %0, %H0, [%3]\n"
1484 " subs %Q0, %Q0, %Q4\n"
1485+" sbcs %R0, %R0, %R4\n"
1486+
1487+#ifdef CONFIG_PAX_REFCOUNT
1488+" bvc 3f\n"
1489+"2: " REFCOUNT_TRAP_INSN "\n"
1490+"3:\n"
1491+#endif
1492+
1493+" strexd %1, %0, %H0, [%3]\n"
1494+" teq %1, #0\n"
1495+" bne 1b"
1496+
1497+#ifdef CONFIG_PAX_REFCOUNT
1498+"\n4:\n"
1499+ _ASM_EXTABLE(2b, 4b)
1500+#endif
1501+
1502+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1503+ : "r" (&v->counter), "r" (i)
1504+ : "cc");
1505+}
1506+
1507+static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1508+{
1509+ long long result;
1510+ unsigned long tmp;
1511+
1512+ prefetchw(&v->counter);
1513+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1514+"1: ldrexd %0, %H0, [%3]\n"
1515+" subs %Q0, %Q0, %Q4\n"
1516 " sbc %R0, %R0, %R4\n"
1517 " strexd %1, %0, %H0, [%3]\n"
1518 " teq %1, #0\n"
1519@@ -371,10 +737,25 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1520 __asm__ __volatile__("@ atomic64_sub_return\n"
1521 "1: ldrexd %0, %H0, [%3]\n"
1522 " subs %Q0, %Q0, %Q4\n"
1523-" sbc %R0, %R0, %R4\n"
1524+" sbcs %R0, %R0, %R4\n"
1525+
1526+#ifdef CONFIG_PAX_REFCOUNT
1527+" bvc 3f\n"
1528+" mov %0, %1\n"
1529+" mov %H0, %H1\n"
1530+"2: " REFCOUNT_TRAP_INSN "\n"
1531+"3:\n"
1532+#endif
1533+
1534 " strexd %1, %0, %H0, [%3]\n"
1535 " teq %1, #0\n"
1536 " bne 1b"
1537+
1538+#ifdef CONFIG_PAX_REFCOUNT
1539+"\n4:\n"
1540+ _ASM_EXTABLE(2b, 4b)
1541+#endif
1542+
1543 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1544 : "r" (&v->counter), "r" (i)
1545 : "cc");
1546@@ -410,6 +791,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1547 return oldval;
1548 }
1549
1550+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1551+ long long new)
1552+{
1553+ long long oldval;
1554+ unsigned long res;
1555+
1556+ smp_mb();
1557+
1558+ do {
1559+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1560+ "ldrexd %1, %H1, [%3]\n"
1561+ "mov %0, #0\n"
1562+ "teq %1, %4\n"
1563+ "teqeq %H1, %H4\n"
1564+ "strexdeq %0, %5, %H5, [%3]"
1565+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1566+ : "r" (&ptr->counter), "r" (old), "r" (new)
1567+ : "cc");
1568+ } while (res);
1569+
1570+ smp_mb();
1571+
1572+ return oldval;
1573+}
1574+
1575 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1576 {
1577 long long result;
1578@@ -435,21 +841,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1579 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1580 {
1581 long long result;
1582- unsigned long tmp;
1583+ u64 tmp;
1584
1585 smp_mb();
1586 prefetchw(&v->counter);
1587
1588 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1589-"1: ldrexd %0, %H0, [%3]\n"
1590-" subs %Q0, %Q0, #1\n"
1591-" sbc %R0, %R0, #0\n"
1592+"1: ldrexd %1, %H1, [%3]\n"
1593+" subs %Q0, %Q1, #1\n"
1594+" sbcs %R0, %R1, #0\n"
1595+
1596+#ifdef CONFIG_PAX_REFCOUNT
1597+" bvc 3f\n"
1598+" mov %Q0, %Q1\n"
1599+" mov %R0, %R1\n"
1600+"2: " REFCOUNT_TRAP_INSN "\n"
1601+"3:\n"
1602+#endif
1603+
1604 " teq %R0, #0\n"
1605-" bmi 2f\n"
1606+" bmi 4f\n"
1607 " strexd %1, %0, %H0, [%3]\n"
1608 " teq %1, #0\n"
1609 " bne 1b\n"
1610-"2:"
1611+"4:\n"
1612+
1613+#ifdef CONFIG_PAX_REFCOUNT
1614+ _ASM_EXTABLE(2b, 4b)
1615+#endif
1616+
1617 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1618 : "r" (&v->counter)
1619 : "cc");
1620@@ -473,13 +893,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1621 " teq %0, %5\n"
1622 " teqeq %H0, %H5\n"
1623 " moveq %1, #0\n"
1624-" beq 2f\n"
1625+" beq 4f\n"
1626 " adds %Q0, %Q0, %Q6\n"
1627-" adc %R0, %R0, %R6\n"
1628+" adcs %R0, %R0, %R6\n"
1629+
1630+#ifdef CONFIG_PAX_REFCOUNT
1631+" bvc 3f\n"
1632+"2: " REFCOUNT_TRAP_INSN "\n"
1633+"3:\n"
1634+#endif
1635+
1636 " strexd %2, %0, %H0, [%4]\n"
1637 " teq %2, #0\n"
1638 " bne 1b\n"
1639-"2:"
1640+"4:\n"
1641+
1642+#ifdef CONFIG_PAX_REFCOUNT
1643+ _ASM_EXTABLE(2b, 4b)
1644+#endif
1645+
1646 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1647 : "r" (&v->counter), "r" (u), "r" (a)
1648 : "cc");
1649@@ -492,10 +924,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1650
1651 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1652 #define atomic64_inc(v) atomic64_add(1LL, (v))
1653+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1654 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1655+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1656 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1657 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1658 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1659+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1660 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1661 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1662 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1663diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1664index c6a3e73..35cca85 100644
1665--- a/arch/arm/include/asm/barrier.h
1666+++ b/arch/arm/include/asm/barrier.h
1667@@ -63,7 +63,7 @@
1668 do { \
1669 compiletime_assert_atomic_type(*p); \
1670 smp_mb(); \
1671- ACCESS_ONCE(*p) = (v); \
1672+ ACCESS_ONCE_RW(*p) = (v); \
1673 } while (0)
1674
1675 #define smp_load_acquire(p) \
1676diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1677index 75fe66b..ba3dee4 100644
1678--- a/arch/arm/include/asm/cache.h
1679+++ b/arch/arm/include/asm/cache.h
1680@@ -4,8 +4,10 @@
1681 #ifndef __ASMARM_CACHE_H
1682 #define __ASMARM_CACHE_H
1683
1684+#include <linux/const.h>
1685+
1686 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1687-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1688+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1689
1690 /*
1691 * Memory returned by kmalloc() may be used for DMA, so we must make
1692@@ -24,5 +26,6 @@
1693 #endif
1694
1695 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1696+#define __read_only __attribute__ ((__section__(".data..read_only")))
1697
1698 #endif
1699diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1700index 10e78d0..dc8505d 100644
1701--- a/arch/arm/include/asm/cacheflush.h
1702+++ b/arch/arm/include/asm/cacheflush.h
1703@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1704 void (*dma_unmap_area)(const void *, size_t, int);
1705
1706 void (*dma_flush_range)(const void *, const void *);
1707-};
1708+} __no_const;
1709
1710 /*
1711 * Select the calling method
1712diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1713index 5233151..87a71fa 100644
1714--- a/arch/arm/include/asm/checksum.h
1715+++ b/arch/arm/include/asm/checksum.h
1716@@ -37,7 +37,19 @@ __wsum
1717 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1718
1719 __wsum
1720-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1721+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1722+
1723+static inline __wsum
1724+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1725+{
1726+ __wsum ret;
1727+ pax_open_userland();
1728+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1729+ pax_close_userland();
1730+ return ret;
1731+}
1732+
1733+
1734
1735 /*
1736 * Fold a partial checksum without adding pseudo headers
1737diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1738index abb2c37..96db950 100644
1739--- a/arch/arm/include/asm/cmpxchg.h
1740+++ b/arch/arm/include/asm/cmpxchg.h
1741@@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1742
1743 #define xchg(ptr,x) \
1744 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1745+#define xchg_unchecked(ptr,x) \
1746+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1747
1748 #include <asm-generic/cmpxchg-local.h>
1749
1750diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1751index 6ddbe44..b5e38b1 100644
1752--- a/arch/arm/include/asm/domain.h
1753+++ b/arch/arm/include/asm/domain.h
1754@@ -48,18 +48,37 @@
1755 * Domain types
1756 */
1757 #define DOMAIN_NOACCESS 0
1758-#define DOMAIN_CLIENT 1
1759 #ifdef CONFIG_CPU_USE_DOMAINS
1760+#define DOMAIN_USERCLIENT 1
1761+#define DOMAIN_KERNELCLIENT 1
1762 #define DOMAIN_MANAGER 3
1763+#define DOMAIN_VECTORS DOMAIN_USER
1764 #else
1765+
1766+#ifdef CONFIG_PAX_KERNEXEC
1767 #define DOMAIN_MANAGER 1
1768+#define DOMAIN_KERNEXEC 3
1769+#else
1770+#define DOMAIN_MANAGER 1
1771+#endif
1772+
1773+#ifdef CONFIG_PAX_MEMORY_UDEREF
1774+#define DOMAIN_USERCLIENT 0
1775+#define DOMAIN_UDEREF 1
1776+#define DOMAIN_VECTORS DOMAIN_KERNEL
1777+#else
1778+#define DOMAIN_USERCLIENT 1
1779+#define DOMAIN_VECTORS DOMAIN_USER
1780+#endif
1781+#define DOMAIN_KERNELCLIENT 1
1782+
1783 #endif
1784
1785 #define domain_val(dom,type) ((type) << (2*(dom)))
1786
1787 #ifndef __ASSEMBLY__
1788
1789-#ifdef CONFIG_CPU_USE_DOMAINS
1790+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1791 static inline void set_domain(unsigned val)
1792 {
1793 asm volatile(
1794@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1795 isb();
1796 }
1797
1798-#define modify_domain(dom,type) \
1799- do { \
1800- struct thread_info *thread = current_thread_info(); \
1801- unsigned int domain = thread->cpu_domain; \
1802- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1803- thread->cpu_domain = domain | domain_val(dom, type); \
1804- set_domain(thread->cpu_domain); \
1805- } while (0)
1806-
1807+extern void modify_domain(unsigned int dom, unsigned int type);
1808 #else
1809 static inline void set_domain(unsigned val) { }
1810 static inline void modify_domain(unsigned dom, unsigned type) { }
1811diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1812index afb9caf..9a0bac0 100644
1813--- a/arch/arm/include/asm/elf.h
1814+++ b/arch/arm/include/asm/elf.h
1815@@ -115,7 +115,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1816 the loader. We need to make sure that it is out of the way of the program
1817 that it will "exec", and that there is sufficient room for the brk. */
1818
1819-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1820+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1821+
1822+#ifdef CONFIG_PAX_ASLR
1823+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1824+
1825+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1826+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1827+#endif
1828
1829 /* When the program starts, a1 contains a pointer to a function to be
1830 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1831@@ -125,10 +132,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1832 extern void elf_set_personality(const struct elf32_hdr *);
1833 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1834
1835-struct mm_struct;
1836-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1837-#define arch_randomize_brk arch_randomize_brk
1838-
1839 #ifdef CONFIG_MMU
1840 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1841 struct linux_binprm;
1842diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1843index de53547..52b9a28 100644
1844--- a/arch/arm/include/asm/fncpy.h
1845+++ b/arch/arm/include/asm/fncpy.h
1846@@ -81,7 +81,9 @@
1847 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1848 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1849 \
1850+ pax_open_kernel(); \
1851 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1852+ pax_close_kernel(); \
1853 flush_icache_range((unsigned long)(dest_buf), \
1854 (unsigned long)(dest_buf) + (size)); \
1855 \
1856diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1857index 53e69da..3fdc896 100644
1858--- a/arch/arm/include/asm/futex.h
1859+++ b/arch/arm/include/asm/futex.h
1860@@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1861 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1862 return -EFAULT;
1863
1864+ pax_open_userland();
1865+
1866 smp_mb();
1867 /* Prefetching cannot fault */
1868 prefetchw(uaddr);
1869@@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1870 : "cc", "memory");
1871 smp_mb();
1872
1873+ pax_close_userland();
1874+
1875 *uval = val;
1876 return ret;
1877 }
1878@@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1879 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1880 return -EFAULT;
1881
1882+ pax_open_userland();
1883+
1884 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1885 "1: " TUSER(ldr) " %1, [%4]\n"
1886 " teq %1, %2\n"
1887@@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1888 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1889 : "cc", "memory");
1890
1891+ pax_close_userland();
1892+
1893 *uval = val;
1894 return ret;
1895 }
1896@@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1897 return -EFAULT;
1898
1899 pagefault_disable(); /* implies preempt_disable() */
1900+ pax_open_userland();
1901
1902 switch (op) {
1903 case FUTEX_OP_SET:
1904@@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1905 ret = -ENOSYS;
1906 }
1907
1908+ pax_close_userland();
1909 pagefault_enable(); /* subsumes preempt_enable() */
1910
1911 if (!ret) {
1912diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1913index 83eb2f7..ed77159 100644
1914--- a/arch/arm/include/asm/kmap_types.h
1915+++ b/arch/arm/include/asm/kmap_types.h
1916@@ -4,6 +4,6 @@
1917 /*
1918 * This is the "bare minimum". AIO seems to require this.
1919 */
1920-#define KM_TYPE_NR 16
1921+#define KM_TYPE_NR 17
1922
1923 #endif
1924diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1925index 9e614a1..3302cca 100644
1926--- a/arch/arm/include/asm/mach/dma.h
1927+++ b/arch/arm/include/asm/mach/dma.h
1928@@ -22,7 +22,7 @@ struct dma_ops {
1929 int (*residue)(unsigned int, dma_t *); /* optional */
1930 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1931 const char *type;
1932-};
1933+} __do_const;
1934
1935 struct dma_struct {
1936 void *addr; /* single DMA address */
1937diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1938index f98c7f3..e5c626d 100644
1939--- a/arch/arm/include/asm/mach/map.h
1940+++ b/arch/arm/include/asm/mach/map.h
1941@@ -23,17 +23,19 @@ struct map_desc {
1942
1943 /* types 0-3 are defined in asm/io.h */
1944 enum {
1945- MT_UNCACHED = 4,
1946- MT_CACHECLEAN,
1947- MT_MINICLEAN,
1948+ MT_UNCACHED_RW = 4,
1949+ MT_CACHECLEAN_RO,
1950+ MT_MINICLEAN_RO,
1951 MT_LOW_VECTORS,
1952 MT_HIGH_VECTORS,
1953- MT_MEMORY_RWX,
1954+ __MT_MEMORY_RWX,
1955 MT_MEMORY_RW,
1956- MT_ROM,
1957- MT_MEMORY_RWX_NONCACHED,
1958+ MT_MEMORY_RX,
1959+ MT_ROM_RX,
1960+ MT_MEMORY_RW_NONCACHED,
1961+ MT_MEMORY_RX_NONCACHED,
1962 MT_MEMORY_RW_DTCM,
1963- MT_MEMORY_RWX_ITCM,
1964+ MT_MEMORY_RX_ITCM,
1965 MT_MEMORY_RW_SO,
1966 MT_MEMORY_DMA_READY,
1967 };
1968diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1969index 891a56b..48f337e 100644
1970--- a/arch/arm/include/asm/outercache.h
1971+++ b/arch/arm/include/asm/outercache.h
1972@@ -36,7 +36,7 @@ struct outer_cache_fns {
1973
1974 /* This is an ARM L2C thing */
1975 void (*write_sec)(unsigned long, unsigned);
1976-};
1977+} __no_const;
1978
1979 extern struct outer_cache_fns outer_cache;
1980
1981diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1982index 4355f0e..cd9168e 100644
1983--- a/arch/arm/include/asm/page.h
1984+++ b/arch/arm/include/asm/page.h
1985@@ -23,6 +23,7 @@
1986
1987 #else
1988
1989+#include <linux/compiler.h>
1990 #include <asm/glue.h>
1991
1992 /*
1993@@ -114,7 +115,7 @@ struct cpu_user_fns {
1994 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1995 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1996 unsigned long vaddr, struct vm_area_struct *vma);
1997-};
1998+} __no_const;
1999
2000 #ifdef MULTI_USER
2001 extern struct cpu_user_fns cpu_user;
2002diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
2003index 78a7793..e3dc06c 100644
2004--- a/arch/arm/include/asm/pgalloc.h
2005+++ b/arch/arm/include/asm/pgalloc.h
2006@@ -17,6 +17,7 @@
2007 #include <asm/processor.h>
2008 #include <asm/cacheflush.h>
2009 #include <asm/tlbflush.h>
2010+#include <asm/system_info.h>
2011
2012 #define check_pgt_cache() do { } while (0)
2013
2014@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2015 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
2016 }
2017
2018+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2019+{
2020+ pud_populate(mm, pud, pmd);
2021+}
2022+
2023 #else /* !CONFIG_ARM_LPAE */
2024
2025 /*
2026@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2027 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
2028 #define pmd_free(mm, pmd) do { } while (0)
2029 #define pud_populate(mm,pmd,pte) BUG()
2030+#define pud_populate_kernel(mm,pmd,pte) BUG()
2031
2032 #endif /* CONFIG_ARM_LPAE */
2033
2034@@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
2035 __free_page(pte);
2036 }
2037
2038+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
2039+{
2040+#ifdef CONFIG_ARM_LPAE
2041+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
2042+#else
2043+ if (addr & SECTION_SIZE)
2044+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
2045+ else
2046+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
2047+#endif
2048+ flush_pmd_entry(pmdp);
2049+}
2050+
2051 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
2052 pmdval_t prot)
2053 {
2054@@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
2055 static inline void
2056 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
2057 {
2058- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
2059+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
2060 }
2061 #define pmd_pgtable(pmd) pmd_page(pmd)
2062
2063diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
2064index 5cfba15..f415e1a 100644
2065--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
2066+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
2067@@ -20,12 +20,15 @@
2068 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
2069 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
2070 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
2071+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
2072 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
2073 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
2074 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
2075+
2076 /*
2077 * - section
2078 */
2079+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
2080 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
2081 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
2082 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
2083@@ -37,6 +40,7 @@
2084 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
2085 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
2086 #define PMD_SECT_AF (_AT(pmdval_t, 0))
2087+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
2088
2089 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
2090 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
2091@@ -66,6 +70,7 @@
2092 * - extended small page/tiny page
2093 */
2094 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
2095+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
2096 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
2097 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
2098 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
2099diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
2100index 219ac88..73ec32a 100644
2101--- a/arch/arm/include/asm/pgtable-2level.h
2102+++ b/arch/arm/include/asm/pgtable-2level.h
2103@@ -126,6 +126,9 @@
2104 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
2105 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
2106
2107+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
2108+#define L_PTE_PXN (_AT(pteval_t, 0))
2109+
2110 /*
2111 * These are the memory types, defined to be compatible with
2112 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
2113diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
2114index 9fd61c7..f8f1cff 100644
2115--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
2116+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
2117@@ -76,6 +76,7 @@
2118 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2119 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
2120 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
2121+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2122 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
2123
2124 /*
2125diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
2126index 06e0bc0..c65bca8 100644
2127--- a/arch/arm/include/asm/pgtable-3level.h
2128+++ b/arch/arm/include/asm/pgtable-3level.h
2129@@ -81,6 +81,7 @@
2130 #define L_PTE_USER (_AT(pteval_t, 1) << 6) /* AP[1] */
2131 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2132 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
2133+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2134 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2135 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55)
2136 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56)
2137@@ -92,10 +93,12 @@
2138 #define L_PMD_SECT_SPLITTING (_AT(pmdval_t, 1) << 56)
2139 #define L_PMD_SECT_NONE (_AT(pmdval_t, 1) << 57)
2140 #define L_PMD_SECT_RDONLY (_AT(pteval_t, 1) << 58)
2141+#define PMD_SECT_RDONLY PMD_SECT_AP2
2142
2143 /*
2144 * To be used in assembly code with the upper page attributes.
2145 */
2146+#define L_PTE_PXN_HIGH (1 << (53 - 32))
2147 #define L_PTE_XN_HIGH (1 << (54 - 32))
2148 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2149
2150diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2151index 01baef0..73c156e 100644
2152--- a/arch/arm/include/asm/pgtable.h
2153+++ b/arch/arm/include/asm/pgtable.h
2154@@ -33,6 +33,9 @@
2155 #include <asm/pgtable-2level.h>
2156 #endif
2157
2158+#define ktla_ktva(addr) (addr)
2159+#define ktva_ktla(addr) (addr)
2160+
2161 /*
2162 * Just any arbitrary offset to the start of the vmalloc VM area: the
2163 * current 8MB value just means that there will be a 8MB "hole" after the
2164@@ -48,6 +51,9 @@
2165 #define LIBRARY_TEXT_START 0x0c000000
2166
2167 #ifndef __ASSEMBLY__
2168+extern pteval_t __supported_pte_mask;
2169+extern pmdval_t __supported_pmd_mask;
2170+
2171 extern void __pte_error(const char *file, int line, pte_t);
2172 extern void __pmd_error(const char *file, int line, pmd_t);
2173 extern void __pgd_error(const char *file, int line, pgd_t);
2174@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2175 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2176 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2177
2178+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2179+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2180+
2181+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2182+#include <asm/domain.h>
2183+#include <linux/thread_info.h>
2184+#include <linux/preempt.h>
2185+
2186+static inline int test_domain(int domain, int domaintype)
2187+{
2188+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2189+}
2190+#endif
2191+
2192+#ifdef CONFIG_PAX_KERNEXEC
2193+static inline unsigned long pax_open_kernel(void) {
2194+#ifdef CONFIG_ARM_LPAE
2195+ /* TODO */
2196+#else
2197+ preempt_disable();
2198+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2199+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2200+#endif
2201+ return 0;
2202+}
2203+
2204+static inline unsigned long pax_close_kernel(void) {
2205+#ifdef CONFIG_ARM_LPAE
2206+ /* TODO */
2207+#else
2208+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2209+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2210+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2211+ preempt_enable_no_resched();
2212+#endif
2213+ return 0;
2214+}
2215+#else
2216+static inline unsigned long pax_open_kernel(void) { return 0; }
2217+static inline unsigned long pax_close_kernel(void) { return 0; }
2218+#endif
2219+
2220 /*
2221 * This is the lowest virtual address we can permit any user space
2222 * mapping to be mapped at. This is particularly important for
2223@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2224 /*
2225 * The pgprot_* and protection_map entries will be fixed up in runtime
2226 * to include the cachable and bufferable bits based on memory policy,
2227- * as well as any architecture dependent bits like global/ASID and SMP
2228- * shared mapping bits.
2229+ * as well as any architecture dependent bits like global/ASID, PXN,
2230+ * and SMP shared mapping bits.
2231 */
2232 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2233
2234@@ -269,7 +317,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2235 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2236 {
2237 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2238- L_PTE_NONE | L_PTE_VALID;
2239+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2240 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2241 return pte;
2242 }
2243diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2244index c25ef3e..735f14b 100644
2245--- a/arch/arm/include/asm/psci.h
2246+++ b/arch/arm/include/asm/psci.h
2247@@ -32,7 +32,7 @@ struct psci_operations {
2248 int (*affinity_info)(unsigned long target_affinity,
2249 unsigned long lowest_affinity_level);
2250 int (*migrate_info_type)(void);
2251-};
2252+} __no_const;
2253
2254 extern struct psci_operations psci_ops;
2255 extern struct smp_operations psci_smp_ops;
2256diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2257index 2ec765c..beb1fe16 100644
2258--- a/arch/arm/include/asm/smp.h
2259+++ b/arch/arm/include/asm/smp.h
2260@@ -113,7 +113,7 @@ struct smp_operations {
2261 int (*cpu_disable)(unsigned int cpu);
2262 #endif
2263 #endif
2264-};
2265+} __no_const;
2266
2267 struct of_cpu_method {
2268 const char *method;
2269diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2270index fc44d37..acc63c4 100644
2271--- a/arch/arm/include/asm/thread_info.h
2272+++ b/arch/arm/include/asm/thread_info.h
2273@@ -89,9 +89,9 @@ struct thread_info {
2274 .flags = 0, \
2275 .preempt_count = INIT_PREEMPT_COUNT, \
2276 .addr_limit = KERNEL_DS, \
2277- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2278- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2279- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2280+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2281+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2282+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2283 .restart_block = { \
2284 .fn = do_no_restart_syscall, \
2285 }, \
2286@@ -165,7 +165,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2287 #define TIF_SYSCALL_AUDIT 9
2288 #define TIF_SYSCALL_TRACEPOINT 10
2289 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2290-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2291+/* within 8 bits of TIF_SYSCALL_TRACE
2292+ * to meet flexible second operand requirements
2293+ */
2294+#define TIF_GRSEC_SETXID 12
2295+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2296 #define TIF_USING_IWMMXT 17
2297 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2298 #define TIF_RESTORE_SIGMASK 20
2299@@ -179,10 +183,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2300 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2301 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2302 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2303+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2304
2305 /* Checks for any syscall work in entry-common.S */
2306 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2307- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2308+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2309
2310 /*
2311 * Change these and you break ASM code in entry-common.S
2312diff --git a/arch/arm/include/asm/tls.h b/arch/arm/include/asm/tls.h
2313index 5f833f7..76e6644 100644
2314--- a/arch/arm/include/asm/tls.h
2315+++ b/arch/arm/include/asm/tls.h
2316@@ -3,6 +3,7 @@
2317
2318 #include <linux/compiler.h>
2319 #include <asm/thread_info.h>
2320+#include <asm/pgtable.h>
2321
2322 #ifdef __ASSEMBLY__
2323 #include <asm/asm-offsets.h>
2324@@ -89,7 +90,9 @@ static inline void set_tls(unsigned long val)
2325 * at 0xffff0fe0 must be used instead. (see
2326 * entry-armv.S for details)
2327 */
2328+ pax_open_kernel();
2329 *((unsigned int *)0xffff0ff0) = val;
2330+ pax_close_kernel();
2331 #endif
2332 }
2333
2334diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2335index 4767eb9..bf00668 100644
2336--- a/arch/arm/include/asm/uaccess.h
2337+++ b/arch/arm/include/asm/uaccess.h
2338@@ -18,6 +18,7 @@
2339 #include <asm/domain.h>
2340 #include <asm/unified.h>
2341 #include <asm/compiler.h>
2342+#include <asm/pgtable.h>
2343
2344 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2345 #include <asm-generic/uaccess-unaligned.h>
2346@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2347 static inline void set_fs(mm_segment_t fs)
2348 {
2349 current_thread_info()->addr_limit = fs;
2350- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2351+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2352 }
2353
2354 #define segment_eq(a,b) ((a) == (b))
2355
2356+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2357+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2358+
2359+static inline void pax_open_userland(void)
2360+{
2361+
2362+#ifdef CONFIG_PAX_MEMORY_UDEREF
2363+ if (segment_eq(get_fs(), USER_DS)) {
2364+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2365+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2366+ }
2367+#endif
2368+
2369+}
2370+
2371+static inline void pax_close_userland(void)
2372+{
2373+
2374+#ifdef CONFIG_PAX_MEMORY_UDEREF
2375+ if (segment_eq(get_fs(), USER_DS)) {
2376+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2377+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2378+ }
2379+#endif
2380+
2381+}
2382+
2383 #define __addr_ok(addr) ({ \
2384 unsigned long flag; \
2385 __asm__("cmp %2, %0; movlo %0, #0" \
2386@@ -198,8 +226,12 @@ extern int __get_user_64t_4(void *);
2387
2388 #define get_user(x,p) \
2389 ({ \
2390+ int __e; \
2391 might_fault(); \
2392- __get_user_check(x,p); \
2393+ pax_open_userland(); \
2394+ __e = __get_user_check(x,p); \
2395+ pax_close_userland(); \
2396+ __e; \
2397 })
2398
2399 extern int __put_user_1(void *, unsigned int);
2400@@ -244,8 +276,12 @@ extern int __put_user_8(void *, unsigned long long);
2401
2402 #define put_user(x,p) \
2403 ({ \
2404+ int __e; \
2405 might_fault(); \
2406- __put_user_check(x,p); \
2407+ pax_open_userland(); \
2408+ __e = __put_user_check(x,p); \
2409+ pax_close_userland(); \
2410+ __e; \
2411 })
2412
2413 #else /* CONFIG_MMU */
2414@@ -269,6 +305,7 @@ static inline void set_fs(mm_segment_t fs)
2415
2416 #endif /* CONFIG_MMU */
2417
2418+#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2419 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2420
2421 #define user_addr_max() \
2422@@ -286,13 +323,17 @@ static inline void set_fs(mm_segment_t fs)
2423 #define __get_user(x,ptr) \
2424 ({ \
2425 long __gu_err = 0; \
2426+ pax_open_userland(); \
2427 __get_user_err((x),(ptr),__gu_err); \
2428+ pax_close_userland(); \
2429 __gu_err; \
2430 })
2431
2432 #define __get_user_error(x,ptr,err) \
2433 ({ \
2434+ pax_open_userland(); \
2435 __get_user_err((x),(ptr),err); \
2436+ pax_close_userland(); \
2437 (void) 0; \
2438 })
2439
2440@@ -368,13 +409,17 @@ do { \
2441 #define __put_user(x,ptr) \
2442 ({ \
2443 long __pu_err = 0; \
2444+ pax_open_userland(); \
2445 __put_user_err((x),(ptr),__pu_err); \
2446+ pax_close_userland(); \
2447 __pu_err; \
2448 })
2449
2450 #define __put_user_error(x,ptr,err) \
2451 ({ \
2452+ pax_open_userland(); \
2453 __put_user_err((x),(ptr),err); \
2454+ pax_close_userland(); \
2455 (void) 0; \
2456 })
2457
2458@@ -474,11 +519,44 @@ do { \
2459
2460
2461 #ifdef CONFIG_MMU
2462-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2463-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2464+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2465+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2466+
2467+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2468+{
2469+ unsigned long ret;
2470+
2471+ check_object_size(to, n, false);
2472+ pax_open_userland();
2473+ ret = ___copy_from_user(to, from, n);
2474+ pax_close_userland();
2475+ return ret;
2476+}
2477+
2478+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2479+{
2480+ unsigned long ret;
2481+
2482+ check_object_size(from, n, true);
2483+ pax_open_userland();
2484+ ret = ___copy_to_user(to, from, n);
2485+ pax_close_userland();
2486+ return ret;
2487+}
2488+
2489 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2490-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2491+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2492 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2493+
2494+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2495+{
2496+ unsigned long ret;
2497+ pax_open_userland();
2498+ ret = ___clear_user(addr, n);
2499+ pax_close_userland();
2500+ return ret;
2501+}
2502+
2503 #else
2504 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2505 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2506@@ -487,6 +565,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2507
2508 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2509 {
2510+ if ((long)n < 0)
2511+ return n;
2512+
2513 if (access_ok(VERIFY_READ, from, n))
2514 n = __copy_from_user(to, from, n);
2515 else /* security hole - plug it */
2516@@ -496,6 +577,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2517
2518 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2519 {
2520+ if ((long)n < 0)
2521+ return n;
2522+
2523 if (access_ok(VERIFY_WRITE, to, n))
2524 n = __copy_to_user(to, from, n);
2525 return n;
2526diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2527index 5af0ed1..cea83883 100644
2528--- a/arch/arm/include/uapi/asm/ptrace.h
2529+++ b/arch/arm/include/uapi/asm/ptrace.h
2530@@ -92,7 +92,7 @@
2531 * ARMv7 groups of PSR bits
2532 */
2533 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2534-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2535+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2536 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2537 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2538
2539diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2540index a88671c..1cc895e 100644
2541--- a/arch/arm/kernel/armksyms.c
2542+++ b/arch/arm/kernel/armksyms.c
2543@@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2544
2545 /* networking */
2546 EXPORT_SYMBOL(csum_partial);
2547-EXPORT_SYMBOL(csum_partial_copy_from_user);
2548+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2549 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2550 EXPORT_SYMBOL(__csum_ipv6_magic);
2551
2552@@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2553 #ifdef CONFIG_MMU
2554 EXPORT_SYMBOL(copy_page);
2555
2556-EXPORT_SYMBOL(__copy_from_user);
2557-EXPORT_SYMBOL(__copy_to_user);
2558-EXPORT_SYMBOL(__clear_user);
2559+EXPORT_SYMBOL(___copy_from_user);
2560+EXPORT_SYMBOL(___copy_to_user);
2561+EXPORT_SYMBOL(___clear_user);
2562
2563 EXPORT_SYMBOL(__get_user_1);
2564 EXPORT_SYMBOL(__get_user_2);
2565diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2566index 36276cd..9d7b13b 100644
2567--- a/arch/arm/kernel/entry-armv.S
2568+++ b/arch/arm/kernel/entry-armv.S
2569@@ -47,6 +47,87 @@
2570 9997:
2571 .endm
2572
2573+ .macro pax_enter_kernel
2574+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2575+ @ make aligned space for saved DACR
2576+ sub sp, sp, #8
2577+ @ save regs
2578+ stmdb sp!, {r1, r2}
2579+ @ read DACR from cpu_domain into r1
2580+ mov r2, sp
2581+ @ assume 8K pages, since we have to split the immediate in two
2582+ bic r2, r2, #(0x1fc0)
2583+ bic r2, r2, #(0x3f)
2584+ ldr r1, [r2, #TI_CPU_DOMAIN]
2585+ @ store old DACR on stack
2586+ str r1, [sp, #8]
2587+#ifdef CONFIG_PAX_KERNEXEC
2588+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2589+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2590+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2591+#endif
2592+#ifdef CONFIG_PAX_MEMORY_UDEREF
2593+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2594+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2595+#endif
2596+ @ write r1 to current_thread_info()->cpu_domain
2597+ str r1, [r2, #TI_CPU_DOMAIN]
2598+ @ write r1 to DACR
2599+ mcr p15, 0, r1, c3, c0, 0
2600+ @ instruction sync
2601+ instr_sync
2602+ @ restore regs
2603+ ldmia sp!, {r1, r2}
2604+#endif
2605+ .endm
2606+
2607+ .macro pax_open_userland
2608+#ifdef CONFIG_PAX_MEMORY_UDEREF
2609+ @ save regs
2610+ stmdb sp!, {r0, r1}
2611+ @ read DACR from cpu_domain into r1
2612+ mov r0, sp
2613+ @ assume 8K pages, since we have to split the immediate in two
2614+ bic r0, r0, #(0x1fc0)
2615+ bic r0, r0, #(0x3f)
2616+ ldr r1, [r0, #TI_CPU_DOMAIN]
2617+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2618+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2619+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2620+ @ write r1 to current_thread_info()->cpu_domain
2621+ str r1, [r0, #TI_CPU_DOMAIN]
2622+ @ write r1 to DACR
2623+ mcr p15, 0, r1, c3, c0, 0
2624+ @ instruction sync
2625+ instr_sync
2626+ @ restore regs
2627+ ldmia sp!, {r0, r1}
2628+#endif
2629+ .endm
2630+
2631+ .macro pax_close_userland
2632+#ifdef CONFIG_PAX_MEMORY_UDEREF
2633+ @ save regs
2634+ stmdb sp!, {r0, r1}
2635+ @ read DACR from cpu_domain into r1
2636+ mov r0, sp
2637+ @ assume 8K pages, since we have to split the immediate in two
2638+ bic r0, r0, #(0x1fc0)
2639+ bic r0, r0, #(0x3f)
2640+ ldr r1, [r0, #TI_CPU_DOMAIN]
2641+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2642+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2643+ @ write r1 to current_thread_info()->cpu_domain
2644+ str r1, [r0, #TI_CPU_DOMAIN]
2645+ @ write r1 to DACR
2646+ mcr p15, 0, r1, c3, c0, 0
2647+ @ instruction sync
2648+ instr_sync
2649+ @ restore regs
2650+ ldmia sp!, {r0, r1}
2651+#endif
2652+ .endm
2653+
2654 .macro pabt_helper
2655 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2656 #ifdef MULTI_PABORT
2657@@ -89,11 +170,15 @@
2658 * Invalid mode handlers
2659 */
2660 .macro inv_entry, reason
2661+
2662+ pax_enter_kernel
2663+
2664 sub sp, sp, #S_FRAME_SIZE
2665 ARM( stmib sp, {r1 - lr} )
2666 THUMB( stmia sp, {r0 - r12} )
2667 THUMB( str sp, [sp, #S_SP] )
2668 THUMB( str lr, [sp, #S_LR] )
2669+
2670 mov r1, #\reason
2671 .endm
2672
2673@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2674 .macro svc_entry, stack_hole=0
2675 UNWIND(.fnstart )
2676 UNWIND(.save {r0 - pc} )
2677+
2678+ pax_enter_kernel
2679+
2680 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2681+
2682 #ifdef CONFIG_THUMB2_KERNEL
2683 SPFIX( str r0, [sp] ) @ temporarily saved
2684 SPFIX( mov r0, sp )
2685@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2686 ldmia r0, {r3 - r5}
2687 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2688 mov r6, #-1 @ "" "" "" ""
2689+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2690+ @ offset sp by 8 as done in pax_enter_kernel
2691+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2692+#else
2693 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2694+#endif
2695 SPFIX( addeq r2, r2, #4 )
2696 str r3, [sp, #-4]! @ save the "real" r0 copied
2697 @ from the exception stack
2698@@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2699 .macro usr_entry
2700 UNWIND(.fnstart )
2701 UNWIND(.cantunwind ) @ don't unwind the user space
2702+
2703+ pax_enter_kernel_user
2704+
2705 sub sp, sp, #S_FRAME_SIZE
2706 ARM( stmib sp, {r1 - r12} )
2707 THUMB( stmia sp, {r0 - r12} )
2708@@ -421,7 +518,9 @@ __und_usr:
2709 tst r3, #PSR_T_BIT @ Thumb mode?
2710 bne __und_usr_thumb
2711 sub r4, r2, #4 @ ARM instr at LR - 4
2712+ pax_open_userland
2713 1: ldrt r0, [r4]
2714+ pax_close_userland
2715 ARM_BE8(rev r0, r0) @ little endian instruction
2716
2717 @ r0 = 32-bit ARM instruction which caused the exception
2718@@ -455,11 +554,15 @@ __und_usr_thumb:
2719 */
2720 .arch armv6t2
2721 #endif
2722+ pax_open_userland
2723 2: ldrht r5, [r4]
2724+ pax_close_userland
2725 ARM_BE8(rev16 r5, r5) @ little endian instruction
2726 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2727 blo __und_usr_fault_16 @ 16bit undefined instruction
2728+ pax_open_userland
2729 3: ldrht r0, [r2]
2730+ pax_close_userland
2731 ARM_BE8(rev16 r0, r0) @ little endian instruction
2732 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2733 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2734@@ -489,7 +592,8 @@ ENDPROC(__und_usr)
2735 */
2736 .pushsection .fixup, "ax"
2737 .align 2
2738-4: str r4, [sp, #S_PC] @ retry current instruction
2739+4: pax_close_userland
2740+ str r4, [sp, #S_PC] @ retry current instruction
2741 ret r9
2742 .popsection
2743 .pushsection __ex_table,"a"
2744@@ -698,7 +802,7 @@ ENTRY(__switch_to)
2745 THUMB( str lr, [ip], #4 )
2746 ldr r4, [r2, #TI_TP_VALUE]
2747 ldr r5, [r2, #TI_TP_VALUE + 4]
2748-#ifdef CONFIG_CPU_USE_DOMAINS
2749+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2750 ldr r6, [r2, #TI_CPU_DOMAIN]
2751 #endif
2752 switch_tls r1, r4, r5, r3, r7
2753@@ -707,7 +811,7 @@ ENTRY(__switch_to)
2754 ldr r8, =__stack_chk_guard
2755 ldr r7, [r7, #TSK_STACK_CANARY]
2756 #endif
2757-#ifdef CONFIG_CPU_USE_DOMAINS
2758+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2759 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2760 #endif
2761 mov r5, r0
2762diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2763index e52fe5a..1b0a924 100644
2764--- a/arch/arm/kernel/entry-common.S
2765+++ b/arch/arm/kernel/entry-common.S
2766@@ -11,18 +11,46 @@
2767 #include <asm/assembler.h>
2768 #include <asm/unistd.h>
2769 #include <asm/ftrace.h>
2770+#include <asm/domain.h>
2771 #include <asm/unwind.h>
2772
2773+#include "entry-header.S"
2774+
2775 #ifdef CONFIG_NEED_RET_TO_USER
2776 #include <mach/entry-macro.S>
2777 #else
2778 .macro arch_ret_to_user, tmp1, tmp2
2779+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2780+ @ save regs
2781+ stmdb sp!, {r1, r2}
2782+ @ read DACR from cpu_domain into r1
2783+ mov r2, sp
2784+ @ assume 8K pages, since we have to split the immediate in two
2785+ bic r2, r2, #(0x1fc0)
2786+ bic r2, r2, #(0x3f)
2787+ ldr r1, [r2, #TI_CPU_DOMAIN]
2788+#ifdef CONFIG_PAX_KERNEXEC
2789+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2790+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2791+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2792+#endif
2793+#ifdef CONFIG_PAX_MEMORY_UDEREF
2794+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2795+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2796+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2797+#endif
2798+ @ write r1 to current_thread_info()->cpu_domain
2799+ str r1, [r2, #TI_CPU_DOMAIN]
2800+ @ write r1 to DACR
2801+ mcr p15, 0, r1, c3, c0, 0
2802+ @ instruction sync
2803+ instr_sync
2804+ @ restore regs
2805+ ldmia sp!, {r1, r2}
2806+#endif
2807 .endm
2808 #endif
2809
2810-#include "entry-header.S"
2811-
2812-
2813 .align 5
2814 /*
2815 * This is the fast syscall return path. We do as little as
2816@@ -406,6 +434,12 @@ ENTRY(vector_swi)
2817 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2818 #endif
2819
2820+ /*
2821+ * do this here to avoid a performance hit of wrapping the code above
2822+ * that directly dereferences userland to parse the SWI instruction
2823+ */
2824+ pax_enter_kernel_user
2825+
2826 adr tbl, sys_call_table @ load syscall table pointer
2827
2828 #if defined(CONFIG_OABI_COMPAT)
2829diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2830index 2fdf867..6e909e4 100644
2831--- a/arch/arm/kernel/entry-header.S
2832+++ b/arch/arm/kernel/entry-header.S
2833@@ -188,6 +188,60 @@
2834 msr cpsr_c, \rtemp @ switch back to the SVC mode
2835 .endm
2836
2837+ .macro pax_enter_kernel_user
2838+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2839+ @ save regs
2840+ stmdb sp!, {r0, r1}
2841+ @ read DACR from cpu_domain into r1
2842+ mov r0, sp
2843+ @ assume 8K pages, since we have to split the immediate in two
2844+ bic r0, r0, #(0x1fc0)
2845+ bic r0, r0, #(0x3f)
2846+ ldr r1, [r0, #TI_CPU_DOMAIN]
2847+#ifdef CONFIG_PAX_MEMORY_UDEREF
2848+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2849+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2850+#endif
2851+#ifdef CONFIG_PAX_KERNEXEC
2852+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2853+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2854+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2855+#endif
2856+ @ write r1 to current_thread_info()->cpu_domain
2857+ str r1, [r0, #TI_CPU_DOMAIN]
2858+ @ write r1 to DACR
2859+ mcr p15, 0, r1, c3, c0, 0
2860+ @ instruction sync
2861+ instr_sync
2862+ @ restore regs
2863+ ldmia sp!, {r0, r1}
2864+#endif
2865+ .endm
2866+
2867+ .macro pax_exit_kernel
2868+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2869+ @ save regs
2870+ stmdb sp!, {r0, r1}
2871+ @ read old DACR from stack into r1
2872+ ldr r1, [sp, #(8 + S_SP)]
2873+ sub r1, r1, #8
2874+ ldr r1, [r1]
2875+
2876+ @ write r1 to current_thread_info()->cpu_domain
2877+ mov r0, sp
2878+ @ assume 8K pages, since we have to split the immediate in two
2879+ bic r0, r0, #(0x1fc0)
2880+ bic r0, r0, #(0x3f)
2881+ str r1, [r0, #TI_CPU_DOMAIN]
2882+ @ write r1 to DACR
2883+ mcr p15, 0, r1, c3, c0, 0
2884+ @ instruction sync
2885+ instr_sync
2886+ @ restore regs
2887+ ldmia sp!, {r0, r1}
2888+#endif
2889+ .endm
2890+
2891 #ifndef CONFIG_THUMB2_KERNEL
2892 .macro svc_exit, rpsr, irq = 0
2893 .if \irq != 0
2894@@ -207,6 +261,9 @@
2895 blne trace_hardirqs_off
2896 #endif
2897 .endif
2898+
2899+ pax_exit_kernel
2900+
2901 msr spsr_cxsf, \rpsr
2902 #if defined(CONFIG_CPU_V6) || defined(CONFIG_CPU_32v6K)
2903 @ We must avoid clrex due to Cortex-A15 erratum #830321
2904@@ -254,6 +311,9 @@
2905 blne trace_hardirqs_off
2906 #endif
2907 .endif
2908+
2909+ pax_exit_kernel
2910+
2911 ldr lr, [sp, #S_SP] @ top of the stack
2912 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2913
2914diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2915index 918875d..cd5fa27 100644
2916--- a/arch/arm/kernel/fiq.c
2917+++ b/arch/arm/kernel/fiq.c
2918@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2919 void *base = vectors_page;
2920 unsigned offset = FIQ_OFFSET;
2921
2922+ pax_open_kernel();
2923 memcpy(base + offset, start, length);
2924+ pax_close_kernel();
2925+
2926 if (!cache_is_vipt_nonaliasing())
2927 flush_icache_range((unsigned long)base + offset, offset +
2928 length);
2929diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2930index 664eee8..f470938 100644
2931--- a/arch/arm/kernel/head.S
2932+++ b/arch/arm/kernel/head.S
2933@@ -437,7 +437,7 @@ __enable_mmu:
2934 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2935 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2936 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2937- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2938+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2939 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2940 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2941 #endif
2942diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2943index 6a4dffe..4a86a70 100644
2944--- a/arch/arm/kernel/module.c
2945+++ b/arch/arm/kernel/module.c
2946@@ -38,12 +38,39 @@
2947 #endif
2948
2949 #ifdef CONFIG_MMU
2950-void *module_alloc(unsigned long size)
2951+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2952 {
2953+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2954+ return NULL;
2955 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2956- GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2957+ GFP_KERNEL, prot, NUMA_NO_NODE,
2958 __builtin_return_address(0));
2959 }
2960+
2961+void *module_alloc(unsigned long size)
2962+{
2963+
2964+#ifdef CONFIG_PAX_KERNEXEC
2965+ return __module_alloc(size, PAGE_KERNEL);
2966+#else
2967+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2968+#endif
2969+
2970+}
2971+
2972+#ifdef CONFIG_PAX_KERNEXEC
2973+void module_free_exec(struct module *mod, void *module_region)
2974+{
2975+ module_free(mod, module_region);
2976+}
2977+EXPORT_SYMBOL(module_free_exec);
2978+
2979+void *module_alloc_exec(unsigned long size)
2980+{
2981+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2982+}
2983+EXPORT_SYMBOL(module_alloc_exec);
2984+#endif
2985 #endif
2986
2987 int
2988diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2989index 07314af..c46655c 100644
2990--- a/arch/arm/kernel/patch.c
2991+++ b/arch/arm/kernel/patch.c
2992@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2993 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2994 int size;
2995
2996+ pax_open_kernel();
2997 if (thumb2 && __opcode_is_thumb16(insn)) {
2998 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2999 size = sizeof(u16);
3000@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
3001 *(u32 *)addr = insn;
3002 size = sizeof(u32);
3003 }
3004+ pax_close_kernel();
3005
3006 flush_icache_range((uintptr_t)(addr),
3007 (uintptr_t)(addr) + size);
3008diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
3009index a35f6eb..7af43a0 100644
3010--- a/arch/arm/kernel/process.c
3011+++ b/arch/arm/kernel/process.c
3012@@ -212,6 +212,7 @@ void machine_power_off(void)
3013
3014 if (pm_power_off)
3015 pm_power_off();
3016+ BUG();
3017 }
3018
3019 /*
3020@@ -225,7 +226,7 @@ void machine_power_off(void)
3021 * executing pre-reset code, and using RAM that the primary CPU's code wishes
3022 * to use. Implementing such co-ordination would be essentially impossible.
3023 */
3024-void machine_restart(char *cmd)
3025+__noreturn void machine_restart(char *cmd)
3026 {
3027 local_irq_disable();
3028 smp_send_stop();
3029@@ -248,8 +249,8 @@ void __show_regs(struct pt_regs *regs)
3030
3031 show_regs_print_info(KERN_DEFAULT);
3032
3033- print_symbol("PC is at %s\n", instruction_pointer(regs));
3034- print_symbol("LR is at %s\n", regs->ARM_lr);
3035+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
3036+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
3037 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
3038 "sp : %08lx ip : %08lx fp : %08lx\n",
3039 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
3040@@ -427,12 +428,6 @@ unsigned long get_wchan(struct task_struct *p)
3041 return 0;
3042 }
3043
3044-unsigned long arch_randomize_brk(struct mm_struct *mm)
3045-{
3046- unsigned long range_end = mm->brk + 0x02000000;
3047- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
3048-}
3049-
3050 #ifdef CONFIG_MMU
3051 #ifdef CONFIG_KUSER_HELPERS
3052 /*
3053@@ -448,7 +443,7 @@ static struct vm_area_struct gate_vma = {
3054
3055 static int __init gate_vma_init(void)
3056 {
3057- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
3058+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
3059 return 0;
3060 }
3061 arch_initcall(gate_vma_init);
3062@@ -474,41 +469,16 @@ int in_gate_area_no_mm(unsigned long addr)
3063
3064 const char *arch_vma_name(struct vm_area_struct *vma)
3065 {
3066- return is_gate_vma(vma) ? "[vectors]" :
3067- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
3068- "[sigpage]" : NULL;
3069+ return is_gate_vma(vma) ? "[vectors]" : NULL;
3070 }
3071
3072-static struct page *signal_page;
3073-extern struct page *get_signal_page(void);
3074-
3075 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
3076 {
3077 struct mm_struct *mm = current->mm;
3078- unsigned long addr;
3079- int ret;
3080-
3081- if (!signal_page)
3082- signal_page = get_signal_page();
3083- if (!signal_page)
3084- return -ENOMEM;
3085
3086 down_write(&mm->mmap_sem);
3087- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
3088- if (IS_ERR_VALUE(addr)) {
3089- ret = addr;
3090- goto up_fail;
3091- }
3092-
3093- ret = install_special_mapping(mm, addr, PAGE_SIZE,
3094- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
3095- &signal_page);
3096-
3097- if (ret == 0)
3098- mm->context.sigpage = addr;
3099-
3100- up_fail:
3101+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
3102 up_write(&mm->mmap_sem);
3103- return ret;
3104+ return 0;
3105 }
3106 #endif
3107diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
3108index f73891b..cf3004e 100644
3109--- a/arch/arm/kernel/psci.c
3110+++ b/arch/arm/kernel/psci.c
3111@@ -28,7 +28,7 @@
3112 #include <asm/psci.h>
3113 #include <asm/system_misc.h>
3114
3115-struct psci_operations psci_ops;
3116+struct psci_operations psci_ops __read_only;
3117
3118 static int (*invoke_psci_fn)(u32, u32, u32, u32);
3119 typedef int (*psci_initcall_t)(const struct device_node *);
3120diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
3121index 0c27ed6..b67388e 100644
3122--- a/arch/arm/kernel/ptrace.c
3123+++ b/arch/arm/kernel/ptrace.c
3124@@ -928,10 +928,19 @@ static void tracehook_report_syscall(struct pt_regs *regs,
3125 regs->ARM_ip = ip;
3126 }
3127
3128+#ifdef CONFIG_GRKERNSEC_SETXID
3129+extern void gr_delayed_cred_worker(void);
3130+#endif
3131+
3132 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3133 {
3134 current_thread_info()->syscall = scno;
3135
3136+#ifdef CONFIG_GRKERNSEC_SETXID
3137+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3138+ gr_delayed_cred_worker();
3139+#endif
3140+
3141 /* Do the secure computing check first; failures should be fast. */
3142 if (secure_computing(scno) == -1)
3143 return -1;
3144diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3145index 84db893d..bd8213a 100644
3146--- a/arch/arm/kernel/setup.c
3147+++ b/arch/arm/kernel/setup.c
3148@@ -104,21 +104,23 @@ EXPORT_SYMBOL(elf_hwcap);
3149 unsigned int elf_hwcap2 __read_mostly;
3150 EXPORT_SYMBOL(elf_hwcap2);
3151
3152+pteval_t __supported_pte_mask __read_only;
3153+pmdval_t __supported_pmd_mask __read_only;
3154
3155 #ifdef MULTI_CPU
3156-struct processor processor __read_mostly;
3157+struct processor processor __read_only;
3158 #endif
3159 #ifdef MULTI_TLB
3160-struct cpu_tlb_fns cpu_tlb __read_mostly;
3161+struct cpu_tlb_fns cpu_tlb __read_only;
3162 #endif
3163 #ifdef MULTI_USER
3164-struct cpu_user_fns cpu_user __read_mostly;
3165+struct cpu_user_fns cpu_user __read_only;
3166 #endif
3167 #ifdef MULTI_CACHE
3168-struct cpu_cache_fns cpu_cache __read_mostly;
3169+struct cpu_cache_fns cpu_cache __read_only;
3170 #endif
3171 #ifdef CONFIG_OUTER_CACHE
3172-struct outer_cache_fns outer_cache __read_mostly;
3173+struct outer_cache_fns outer_cache __read_only;
3174 EXPORT_SYMBOL(outer_cache);
3175 #endif
3176
3177@@ -251,9 +253,13 @@ static int __get_cpu_architecture(void)
3178 asm("mrc p15, 0, %0, c0, c1, 4"
3179 : "=r" (mmfr0));
3180 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3181- (mmfr0 & 0x000000f0) >= 0x00000030)
3182+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3183 cpu_arch = CPU_ARCH_ARMv7;
3184- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3185+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3186+ __supported_pte_mask |= L_PTE_PXN;
3187+ __supported_pmd_mask |= PMD_PXNTABLE;
3188+ }
3189+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3190 (mmfr0 & 0x000000f0) == 0x00000020)
3191 cpu_arch = CPU_ARCH_ARMv6;
3192 else
3193diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3194index bd19834..e4d8c66 100644
3195--- a/arch/arm/kernel/signal.c
3196+++ b/arch/arm/kernel/signal.c
3197@@ -24,8 +24,6 @@
3198
3199 extern const unsigned long sigreturn_codes[7];
3200
3201-static unsigned long signal_return_offset;
3202-
3203 #ifdef CONFIG_CRUNCH
3204 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3205 {
3206@@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3207 * except when the MPU has protected the vectors
3208 * page from PL0
3209 */
3210- retcode = mm->context.sigpage + signal_return_offset +
3211- (idx << 2) + thumb;
3212+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3213 } else
3214 #endif
3215 {
3216@@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3217 } while (thread_flags & _TIF_WORK_MASK);
3218 return 0;
3219 }
3220-
3221-struct page *get_signal_page(void)
3222-{
3223- unsigned long ptr;
3224- unsigned offset;
3225- struct page *page;
3226- void *addr;
3227-
3228- page = alloc_pages(GFP_KERNEL, 0);
3229-
3230- if (!page)
3231- return NULL;
3232-
3233- addr = page_address(page);
3234-
3235- /* Give the signal return code some randomness */
3236- offset = 0x200 + (get_random_int() & 0x7fc);
3237- signal_return_offset = offset;
3238-
3239- /*
3240- * Copy signal return handlers into the vector page, and
3241- * set sigreturn to be a pointer to these.
3242- */
3243- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3244-
3245- ptr = (unsigned long)addr + offset;
3246- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3247-
3248- return page;
3249-}
3250diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3251index bbe22fc..d7737f5 100644
3252--- a/arch/arm/kernel/smp.c
3253+++ b/arch/arm/kernel/smp.c
3254@@ -76,7 +76,7 @@ enum ipi_msg_type {
3255
3256 static DECLARE_COMPLETION(cpu_running);
3257
3258-static struct smp_operations smp_ops;
3259+static struct smp_operations smp_ops __read_only;
3260
3261 void __init smp_set_ops(struct smp_operations *ops)
3262 {
3263diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3264index 7a3be1d..b00c7de 100644
3265--- a/arch/arm/kernel/tcm.c
3266+++ b/arch/arm/kernel/tcm.c
3267@@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3268 .virtual = ITCM_OFFSET,
3269 .pfn = __phys_to_pfn(ITCM_OFFSET),
3270 .length = 0,
3271- .type = MT_MEMORY_RWX_ITCM,
3272+ .type = MT_MEMORY_RX_ITCM,
3273 }
3274 };
3275
3276@@ -267,7 +267,9 @@ no_dtcm:
3277 start = &__sitcm_text;
3278 end = &__eitcm_text;
3279 ram = &__itcm_start;
3280+ pax_open_kernel();
3281 memcpy(start, ram, itcm_code_sz);
3282+ pax_close_kernel();
3283 pr_debug("CPU ITCM: copied code from %p - %p\n",
3284 start, end);
3285 itcm_present = true;
3286diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3287index a964c9f..cf2a5b1 100644
3288--- a/arch/arm/kernel/traps.c
3289+++ b/arch/arm/kernel/traps.c
3290@@ -64,7 +64,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3291 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3292 {
3293 #ifdef CONFIG_KALLSYMS
3294- printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3295+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3296 #else
3297 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3298 #endif
3299@@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3300 static int die_owner = -1;
3301 static unsigned int die_nest_count;
3302
3303+extern void gr_handle_kernel_exploit(void);
3304+
3305 static unsigned long oops_begin(void)
3306 {
3307 int cpu;
3308@@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3309 panic("Fatal exception in interrupt");
3310 if (panic_on_oops)
3311 panic("Fatal exception");
3312+
3313+ gr_handle_kernel_exploit();
3314+
3315 if (signr)
3316 do_exit(signr);
3317 }
3318@@ -887,7 +892,11 @@ void __init early_trap_init(void *vectors_base)
3319 kuser_init(vectors_base);
3320
3321 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3322- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3323+
3324+#ifndef CONFIG_PAX_MEMORY_UDEREF
3325+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3326+#endif
3327+
3328 #else /* ifndef CONFIG_CPU_V7M */
3329 /*
3330 * on V7-M there is no need to copy the vector table to a dedicated
3331diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3332index 6f57cb9..645f8c4 100644
3333--- a/arch/arm/kernel/vmlinux.lds.S
3334+++ b/arch/arm/kernel/vmlinux.lds.S
3335@@ -8,7 +8,11 @@
3336 #include <asm/thread_info.h>
3337 #include <asm/memory.h>
3338 #include <asm/page.h>
3339-
3340+
3341+#ifdef CONFIG_PAX_KERNEXEC
3342+#include <asm/pgtable.h>
3343+#endif
3344+
3345 #define PROC_INFO \
3346 . = ALIGN(4); \
3347 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3348@@ -34,7 +38,7 @@
3349 #endif
3350
3351 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3352- defined(CONFIG_GENERIC_BUG)
3353+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3354 #define ARM_EXIT_KEEP(x) x
3355 #define ARM_EXIT_DISCARD(x)
3356 #else
3357@@ -90,6 +94,11 @@ SECTIONS
3358 _text = .;
3359 HEAD_TEXT
3360 }
3361+
3362+#ifdef CONFIG_PAX_KERNEXEC
3363+ . = ALIGN(1<<SECTION_SHIFT);
3364+#endif
3365+
3366 .text : { /* Real text segment */
3367 _stext = .; /* Text and read-only data */
3368 __exception_text_start = .;
3369@@ -112,6 +121,8 @@ SECTIONS
3370 ARM_CPU_KEEP(PROC_INFO)
3371 }
3372
3373+ _etext = .; /* End of text section */
3374+
3375 RO_DATA(PAGE_SIZE)
3376
3377 . = ALIGN(4);
3378@@ -142,7 +153,9 @@ SECTIONS
3379
3380 NOTES
3381
3382- _etext = .; /* End of text and rodata section */
3383+#ifdef CONFIG_PAX_KERNEXEC
3384+ . = ALIGN(1<<SECTION_SHIFT);
3385+#endif
3386
3387 #ifndef CONFIG_XIP_KERNEL
3388 . = ALIGN(PAGE_SIZE);
3389@@ -220,6 +233,11 @@ SECTIONS
3390 . = PAGE_OFFSET + TEXT_OFFSET;
3391 #else
3392 __init_end = .;
3393+
3394+#ifdef CONFIG_PAX_KERNEXEC
3395+ . = ALIGN(1<<SECTION_SHIFT);
3396+#endif
3397+
3398 . = ALIGN(THREAD_SIZE);
3399 __data_loc = .;
3400 #endif
3401diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3402index a99e0cd..ab56421d 100644
3403--- a/arch/arm/kvm/arm.c
3404+++ b/arch/arm/kvm/arm.c
3405@@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3406 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3407
3408 /* The VMID used in the VTTBR */
3409-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3410+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3411 static u8 kvm_next_vmid;
3412 static DEFINE_SPINLOCK(kvm_vmid_lock);
3413
3414@@ -372,7 +372,7 @@ void force_vm_exit(const cpumask_t *mask)
3415 */
3416 static bool need_new_vmid_gen(struct kvm *kvm)
3417 {
3418- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3419+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3420 }
3421
3422 /**
3423@@ -405,7 +405,7 @@ static void update_vttbr(struct kvm *kvm)
3424
3425 /* First user of a new VMID generation? */
3426 if (unlikely(kvm_next_vmid == 0)) {
3427- atomic64_inc(&kvm_vmid_gen);
3428+ atomic64_inc_unchecked(&kvm_vmid_gen);
3429 kvm_next_vmid = 1;
3430
3431 /*
3432@@ -422,7 +422,7 @@ static void update_vttbr(struct kvm *kvm)
3433 kvm_call_hyp(__kvm_flush_vm_context);
3434 }
3435
3436- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3437+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3438 kvm->arch.vmid = kvm_next_vmid;
3439 kvm_next_vmid++;
3440
3441@@ -997,7 +997,7 @@ static void check_kvm_target_cpu(void *ret)
3442 /**
3443 * Initialize Hyp-mode and memory mappings on all CPUs.
3444 */
3445-int kvm_arch_init(void *opaque)
3446+int kvm_arch_init(const void *opaque)
3447 {
3448 int err;
3449 int ret, cpu;
3450diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3451index 14a0d98..7771a7d 100644
3452--- a/arch/arm/lib/clear_user.S
3453+++ b/arch/arm/lib/clear_user.S
3454@@ -12,14 +12,14 @@
3455
3456 .text
3457
3458-/* Prototype: int __clear_user(void *addr, size_t sz)
3459+/* Prototype: int ___clear_user(void *addr, size_t sz)
3460 * Purpose : clear some user memory
3461 * Params : addr - user memory address to clear
3462 * : sz - number of bytes to clear
3463 * Returns : number of bytes NOT cleared
3464 */
3465 ENTRY(__clear_user_std)
3466-WEAK(__clear_user)
3467+WEAK(___clear_user)
3468 stmfd sp!, {r1, lr}
3469 mov r2, #0
3470 cmp r1, #4
3471@@ -44,7 +44,7 @@ WEAK(__clear_user)
3472 USER( strnebt r2, [r0])
3473 mov r0, #0
3474 ldmfd sp!, {r1, pc}
3475-ENDPROC(__clear_user)
3476+ENDPROC(___clear_user)
3477 ENDPROC(__clear_user_std)
3478
3479 .pushsection .fixup,"ax"
3480diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3481index 66a477a..bee61d3 100644
3482--- a/arch/arm/lib/copy_from_user.S
3483+++ b/arch/arm/lib/copy_from_user.S
3484@@ -16,7 +16,7 @@
3485 /*
3486 * Prototype:
3487 *
3488- * size_t __copy_from_user(void *to, const void *from, size_t n)
3489+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3490 *
3491 * Purpose:
3492 *
3493@@ -84,11 +84,11 @@
3494
3495 .text
3496
3497-ENTRY(__copy_from_user)
3498+ENTRY(___copy_from_user)
3499
3500 #include "copy_template.S"
3501
3502-ENDPROC(__copy_from_user)
3503+ENDPROC(___copy_from_user)
3504
3505 .pushsection .fixup,"ax"
3506 .align 0
3507diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3508index 6ee2f67..d1cce76 100644
3509--- a/arch/arm/lib/copy_page.S
3510+++ b/arch/arm/lib/copy_page.S
3511@@ -10,6 +10,7 @@
3512 * ASM optimised string functions
3513 */
3514 #include <linux/linkage.h>
3515+#include <linux/const.h>
3516 #include <asm/assembler.h>
3517 #include <asm/asm-offsets.h>
3518 #include <asm/cache.h>
3519diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3520index d066df6..df28194 100644
3521--- a/arch/arm/lib/copy_to_user.S
3522+++ b/arch/arm/lib/copy_to_user.S
3523@@ -16,7 +16,7 @@
3524 /*
3525 * Prototype:
3526 *
3527- * size_t __copy_to_user(void *to, const void *from, size_t n)
3528+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3529 *
3530 * Purpose:
3531 *
3532@@ -88,11 +88,11 @@
3533 .text
3534
3535 ENTRY(__copy_to_user_std)
3536-WEAK(__copy_to_user)
3537+WEAK(___copy_to_user)
3538
3539 #include "copy_template.S"
3540
3541-ENDPROC(__copy_to_user)
3542+ENDPROC(___copy_to_user)
3543 ENDPROC(__copy_to_user_std)
3544
3545 .pushsection .fixup,"ax"
3546diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3547index 7d08b43..f7ca7ea 100644
3548--- a/arch/arm/lib/csumpartialcopyuser.S
3549+++ b/arch/arm/lib/csumpartialcopyuser.S
3550@@ -57,8 +57,8 @@
3551 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3552 */
3553
3554-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3555-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3556+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3557+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3558
3559 #include "csumpartialcopygeneric.S"
3560
3561diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3562index 312d43e..21d2322 100644
3563--- a/arch/arm/lib/delay.c
3564+++ b/arch/arm/lib/delay.c
3565@@ -29,7 +29,7 @@
3566 /*
3567 * Default to the loop-based delay implementation.
3568 */
3569-struct arm_delay_ops arm_delay_ops = {
3570+struct arm_delay_ops arm_delay_ops __read_only = {
3571 .delay = __loop_delay,
3572 .const_udelay = __loop_const_udelay,
3573 .udelay = __loop_udelay,
3574diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3575index 3e58d71..029817c 100644
3576--- a/arch/arm/lib/uaccess_with_memcpy.c
3577+++ b/arch/arm/lib/uaccess_with_memcpy.c
3578@@ -136,7 +136,7 @@ out:
3579 }
3580
3581 unsigned long
3582-__copy_to_user(void __user *to, const void *from, unsigned long n)
3583+___copy_to_user(void __user *to, const void *from, unsigned long n)
3584 {
3585 /*
3586 * This test is stubbed out of the main function above to keep
3587@@ -190,7 +190,7 @@ out:
3588 return n;
3589 }
3590
3591-unsigned long __clear_user(void __user *addr, unsigned long n)
3592+unsigned long ___clear_user(void __user *addr, unsigned long n)
3593 {
3594 /* See rational for this in __copy_to_user() above. */
3595 if (n < 64)
3596diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3597index f7a07a5..258e1f7 100644
3598--- a/arch/arm/mach-at91/setup.c
3599+++ b/arch/arm/mach-at91/setup.c
3600@@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3601
3602 desc->pfn = __phys_to_pfn(base);
3603 desc->length = length;
3604- desc->type = MT_MEMORY_RWX_NONCACHED;
3605+ desc->type = MT_MEMORY_RW_NONCACHED;
3606
3607 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3608 base, length, desc->virtual);
3609diff --git a/arch/arm/mach-keystone/keystone.c b/arch/arm/mach-keystone/keystone.c
3610index 7f352de..6dc0929 100644
3611--- a/arch/arm/mach-keystone/keystone.c
3612+++ b/arch/arm/mach-keystone/keystone.c
3613@@ -27,7 +27,7 @@
3614
3615 #include "keystone.h"
3616
3617-static struct notifier_block platform_nb;
3618+static notifier_block_no_const platform_nb;
3619 static unsigned long keystone_dma_pfn_offset __read_mostly;
3620
3621 static int keystone_platform_notifier(struct notifier_block *nb,
3622diff --git a/arch/arm/mach-mvebu/coherency.c b/arch/arm/mach-mvebu/coherency.c
3623index 2bdc323..cf1c607 100644
3624--- a/arch/arm/mach-mvebu/coherency.c
3625+++ b/arch/arm/mach-mvebu/coherency.c
3626@@ -316,7 +316,7 @@ static void __init armada_370_coherency_init(struct device_node *np)
3627
3628 /*
3629 * This ioremap hook is used on Armada 375/38x to ensure that PCIe
3630- * memory areas are mapped as MT_UNCACHED instead of MT_DEVICE. This
3631+ * memory areas are mapped as MT_UNCACHED_RW instead of MT_DEVICE. This
3632 * is needed as a workaround for a deadlock issue between the PCIe
3633 * interface and the cache controller.
3634 */
3635@@ -329,7 +329,7 @@ armada_pcie_wa_ioremap_caller(phys_addr_t phys_addr, size_t size,
3636 mvebu_mbus_get_pcie_mem_aperture(&pcie_mem);
3637
3638 if (pcie_mem.start <= phys_addr && (phys_addr + size) <= pcie_mem.end)
3639- mtype = MT_UNCACHED;
3640+ mtype = MT_UNCACHED_RW;
3641
3642 return __arm_ioremap_caller(phys_addr, size, mtype, caller);
3643 }
3644diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3645index aead77a..a2253fa 100644
3646--- a/arch/arm/mach-omap2/board-n8x0.c
3647+++ b/arch/arm/mach-omap2/board-n8x0.c
3648@@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3649 }
3650 #endif
3651
3652-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3653+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3654 .late_init = n8x0_menelaus_late_init,
3655 };
3656
3657diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3658index 2f97228..6ce10e1 100644
3659--- a/arch/arm/mach-omap2/gpmc.c
3660+++ b/arch/arm/mach-omap2/gpmc.c
3661@@ -151,7 +151,6 @@ struct omap3_gpmc_regs {
3662 };
3663
3664 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3665-static struct irq_chip gpmc_irq_chip;
3666 static int gpmc_irq_start;
3667
3668 static struct resource gpmc_mem_root;
3669@@ -736,6 +735,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3670
3671 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3672
3673+static struct irq_chip gpmc_irq_chip = {
3674+ .name = "gpmc",
3675+ .irq_startup = gpmc_irq_noop_ret,
3676+ .irq_enable = gpmc_irq_enable,
3677+ .irq_disable = gpmc_irq_disable,
3678+ .irq_shutdown = gpmc_irq_noop,
3679+ .irq_ack = gpmc_irq_noop,
3680+ .irq_mask = gpmc_irq_noop,
3681+ .irq_unmask = gpmc_irq_noop,
3682+
3683+};
3684+
3685 static int gpmc_setup_irq(void)
3686 {
3687 int i;
3688@@ -750,15 +761,6 @@ static int gpmc_setup_irq(void)
3689 return gpmc_irq_start;
3690 }
3691
3692- gpmc_irq_chip.name = "gpmc";
3693- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3694- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3695- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3696- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3697- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3698- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3699- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3700-
3701 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3702 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3703
3704diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3705index 4001325..b14e2a0 100644
3706--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3707+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3708@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3709 int (*finish_suspend)(unsigned long cpu_state);
3710 void (*resume)(void);
3711 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3712-};
3713+} __no_const;
3714
3715 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3716 static struct powerdomain *mpuss_pd;
3717@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3718 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3719 {}
3720
3721-struct cpu_pm_ops omap_pm_ops = {
3722+static struct cpu_pm_ops omap_pm_ops __read_only = {
3723 .finish_suspend = default_finish_suspend,
3724 .resume = dummy_cpu_resume,
3725 .scu_prepare = dummy_scu_prepare,
3726diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3727index 37843a7..a98df13 100644
3728--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3729+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3730@@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3731 return NOTIFY_OK;
3732 }
3733
3734-static struct notifier_block __refdata irq_hotplug_notifier = {
3735+static struct notifier_block irq_hotplug_notifier = {
3736 .notifier_call = irq_cpu_hotplug_notify,
3737 };
3738
3739diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3740index d22c30d..23697a1 100644
3741--- a/arch/arm/mach-omap2/omap_device.c
3742+++ b/arch/arm/mach-omap2/omap_device.c
3743@@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3744 struct platform_device __init *omap_device_build(const char *pdev_name,
3745 int pdev_id,
3746 struct omap_hwmod *oh,
3747- void *pdata, int pdata_len)
3748+ const void *pdata, int pdata_len)
3749 {
3750 struct omap_hwmod *ohs[] = { oh };
3751
3752@@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3753 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3754 int pdev_id,
3755 struct omap_hwmod **ohs,
3756- int oh_cnt, void *pdata,
3757+ int oh_cnt, const void *pdata,
3758 int pdata_len)
3759 {
3760 int ret = -ENOMEM;
3761diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3762index 78c02b3..c94109a 100644
3763--- a/arch/arm/mach-omap2/omap_device.h
3764+++ b/arch/arm/mach-omap2/omap_device.h
3765@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3766 /* Core code interface */
3767
3768 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3769- struct omap_hwmod *oh, void *pdata,
3770+ struct omap_hwmod *oh, const void *pdata,
3771 int pdata_len);
3772
3773 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3774 struct omap_hwmod **oh, int oh_cnt,
3775- void *pdata, int pdata_len);
3776+ const void *pdata, int pdata_len);
3777
3778 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3779 struct omap_hwmod **ohs, int oh_cnt);
3780diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3781index 9e91a4e..357ed0d 100644
3782--- a/arch/arm/mach-omap2/omap_hwmod.c
3783+++ b/arch/arm/mach-omap2/omap_hwmod.c
3784@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3785 int (*init_clkdm)(struct omap_hwmod *oh);
3786 void (*update_context_lost)(struct omap_hwmod *oh);
3787 int (*get_context_lost)(struct omap_hwmod *oh);
3788-};
3789+} __no_const;
3790
3791 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3792-static struct omap_hwmod_soc_ops soc_ops;
3793+static struct omap_hwmod_soc_ops soc_ops __read_only;
3794
3795 /* omap_hwmod_list contains all registered struct omap_hwmods */
3796 static LIST_HEAD(omap_hwmod_list);
3797diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3798index 95fee54..cfa9cf1 100644
3799--- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3800+++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3801@@ -10,6 +10,7 @@
3802
3803 #include <linux/kernel.h>
3804 #include <linux/init.h>
3805+#include <asm/pgtable.h>
3806
3807 #include "powerdomain.h"
3808
3809@@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3810
3811 void __init am43xx_powerdomains_init(void)
3812 {
3813- omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3814+ pax_open_kernel();
3815+ *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3816+ pax_close_kernel();
3817 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3818 pwrdm_register_pwrdms(powerdomains_am43xx);
3819 pwrdm_complete_init();
3820diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3821index 97d6607..8429d14 100644
3822--- a/arch/arm/mach-omap2/wd_timer.c
3823+++ b/arch/arm/mach-omap2/wd_timer.c
3824@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3825 struct omap_hwmod *oh;
3826 char *oh_name = "wd_timer2";
3827 char *dev_name = "omap_wdt";
3828- struct omap_wd_timer_platform_data pdata;
3829+ static struct omap_wd_timer_platform_data pdata = {
3830+ .read_reset_sources = prm_read_reset_sources
3831+ };
3832
3833 if (!cpu_class_is_omap2() || of_have_populated_dt())
3834 return 0;
3835@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3836 return -EINVAL;
3837 }
3838
3839- pdata.read_reset_sources = prm_read_reset_sources;
3840-
3841 pdev = omap_device_build(dev_name, id, oh, &pdata,
3842 sizeof(struct omap_wd_timer_platform_data));
3843 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3844diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3845index b30bf5c..d0825bf 100644
3846--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3847+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3848@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3849 bool entered_lp2 = false;
3850
3851 if (tegra_pending_sgi())
3852- ACCESS_ONCE(abort_flag) = true;
3853+ ACCESS_ONCE_RW(abort_flag) = true;
3854
3855 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3856
3857diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3858index 2dea8b5..6499da2 100644
3859--- a/arch/arm/mach-ux500/setup.h
3860+++ b/arch/arm/mach-ux500/setup.h
3861@@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3862 .type = MT_DEVICE, \
3863 }
3864
3865-#define __MEM_DEV_DESC(x, sz) { \
3866- .virtual = IO_ADDRESS(x), \
3867- .pfn = __phys_to_pfn(x), \
3868- .length = sz, \
3869- .type = MT_MEMORY_RWX, \
3870-}
3871-
3872 extern struct smp_operations ux500_smp_ops;
3873 extern void ux500_cpu_die(unsigned int cpu);
3874
3875diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3876index ae69809..2665202 100644
3877--- a/arch/arm/mm/Kconfig
3878+++ b/arch/arm/mm/Kconfig
3879@@ -446,6 +446,7 @@ config CPU_32v5
3880
3881 config CPU_32v6
3882 bool
3883+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3884 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3885
3886 config CPU_32v6K
3887@@ -600,6 +601,7 @@ config CPU_CP15_MPU
3888
3889 config CPU_USE_DOMAINS
3890 bool
3891+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3892 help
3893 This option enables or disables the use of domain switching
3894 via the set_fs() function.
3895@@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
3896 config KUSER_HELPERS
3897 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3898 default y
3899+ depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3900 help
3901 Warning: disabling this option may break user programs.
3902
3903@@ -811,7 +814,7 @@ config KUSER_HELPERS
3904 See Documentation/arm/kernel_user_helpers.txt for details.
3905
3906 However, the fixed address nature of these helpers can be used
3907- by ROP (return orientated programming) authors when creating
3908+ by ROP (Return Oriented Programming) authors when creating
3909 exploits.
3910
3911 If all of the binaries and libraries which run on your platform
3912diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3913index 83792f4..c25d36b 100644
3914--- a/arch/arm/mm/alignment.c
3915+++ b/arch/arm/mm/alignment.c
3916@@ -216,10 +216,12 @@ union offset_union {
3917 #define __get16_unaligned_check(ins,val,addr) \
3918 do { \
3919 unsigned int err = 0, v, a = addr; \
3920+ pax_open_userland(); \
3921 __get8_unaligned_check(ins,v,a,err); \
3922 val = v << ((BE) ? 8 : 0); \
3923 __get8_unaligned_check(ins,v,a,err); \
3924 val |= v << ((BE) ? 0 : 8); \
3925+ pax_close_userland(); \
3926 if (err) \
3927 goto fault; \
3928 } while (0)
3929@@ -233,6 +235,7 @@ union offset_union {
3930 #define __get32_unaligned_check(ins,val,addr) \
3931 do { \
3932 unsigned int err = 0, v, a = addr; \
3933+ pax_open_userland(); \
3934 __get8_unaligned_check(ins,v,a,err); \
3935 val = v << ((BE) ? 24 : 0); \
3936 __get8_unaligned_check(ins,v,a,err); \
3937@@ -241,6 +244,7 @@ union offset_union {
3938 val |= v << ((BE) ? 8 : 16); \
3939 __get8_unaligned_check(ins,v,a,err); \
3940 val |= v << ((BE) ? 0 : 24); \
3941+ pax_close_userland(); \
3942 if (err) \
3943 goto fault; \
3944 } while (0)
3945@@ -254,6 +258,7 @@ union offset_union {
3946 #define __put16_unaligned_check(ins,val,addr) \
3947 do { \
3948 unsigned int err = 0, v = val, a = addr; \
3949+ pax_open_userland(); \
3950 __asm__( FIRST_BYTE_16 \
3951 ARM( "1: "ins" %1, [%2], #1\n" ) \
3952 THUMB( "1: "ins" %1, [%2]\n" ) \
3953@@ -273,6 +278,7 @@ union offset_union {
3954 " .popsection\n" \
3955 : "=r" (err), "=&r" (v), "=&r" (a) \
3956 : "0" (err), "1" (v), "2" (a)); \
3957+ pax_close_userland(); \
3958 if (err) \
3959 goto fault; \
3960 } while (0)
3961@@ -286,6 +292,7 @@ union offset_union {
3962 #define __put32_unaligned_check(ins,val,addr) \
3963 do { \
3964 unsigned int err = 0, v = val, a = addr; \
3965+ pax_open_userland(); \
3966 __asm__( FIRST_BYTE_32 \
3967 ARM( "1: "ins" %1, [%2], #1\n" ) \
3968 THUMB( "1: "ins" %1, [%2]\n" ) \
3969@@ -315,6 +322,7 @@ union offset_union {
3970 " .popsection\n" \
3971 : "=r" (err), "=&r" (v), "=&r" (a) \
3972 : "0" (err), "1" (v), "2" (a)); \
3973+ pax_close_userland(); \
3974 if (err) \
3975 goto fault; \
3976 } while (0)
3977diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3978index 5f2c988..221412d 100644
3979--- a/arch/arm/mm/cache-l2x0.c
3980+++ b/arch/arm/mm/cache-l2x0.c
3981@@ -41,7 +41,7 @@ struct l2c_init_data {
3982 void (*fixup)(void __iomem *, u32, struct outer_cache_fns *);
3983 void (*save)(void __iomem *);
3984 struct outer_cache_fns outer_cache;
3985-};
3986+} __do_const;
3987
3988 #define CACHE_LINE_SIZE 32
3989
3990diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3991index 6eb97b3..ac509f6 100644
3992--- a/arch/arm/mm/context.c
3993+++ b/arch/arm/mm/context.c
3994@@ -43,7 +43,7 @@
3995 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3996
3997 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3998-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3999+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
4000 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
4001
4002 static DEFINE_PER_CPU(atomic64_t, active_asids);
4003@@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
4004 {
4005 static u32 cur_idx = 1;
4006 u64 asid = atomic64_read(&mm->context.id);
4007- u64 generation = atomic64_read(&asid_generation);
4008+ u64 generation = atomic64_read_unchecked(&asid_generation);
4009
4010 if (asid != 0 && is_reserved_asid(asid)) {
4011 /*
4012@@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
4013 */
4014 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
4015 if (asid == NUM_USER_ASIDS) {
4016- generation = atomic64_add_return(ASID_FIRST_VERSION,
4017+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
4018 &asid_generation);
4019 flush_context(cpu);
4020 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
4021@@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
4022 cpu_set_reserved_ttbr0();
4023
4024 asid = atomic64_read(&mm->context.id);
4025- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
4026+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
4027 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
4028 goto switch_mm_fastpath;
4029
4030 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
4031 /* Check that our ASID belongs to the current generation. */
4032 asid = atomic64_read(&mm->context.id);
4033- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
4034+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
4035 asid = new_context(mm, cpu);
4036 atomic64_set(&mm->context.id, asid);
4037 }
4038diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
4039index eb8830a..e8ff52e 100644
4040--- a/arch/arm/mm/fault.c
4041+++ b/arch/arm/mm/fault.c
4042@@ -25,6 +25,7 @@
4043 #include <asm/system_misc.h>
4044 #include <asm/system_info.h>
4045 #include <asm/tlbflush.h>
4046+#include <asm/sections.h>
4047
4048 #include "fault.h"
4049
4050@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
4051 if (fixup_exception(regs))
4052 return;
4053
4054+#ifdef CONFIG_PAX_MEMORY_UDEREF
4055+ if (addr < TASK_SIZE) {
4056+ if (current->signal->curr_ip)
4057+ 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),
4058+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4059+ else
4060+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4061+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4062+ }
4063+#endif
4064+
4065+#ifdef CONFIG_PAX_KERNEXEC
4066+ if ((fsr & FSR_WRITE) &&
4067+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
4068+ (MODULES_VADDR <= addr && addr < MODULES_END)))
4069+ {
4070+ if (current->signal->curr_ip)
4071+ 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),
4072+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4073+ else
4074+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
4075+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
4076+ }
4077+#endif
4078+
4079 /*
4080 * No handler, we'll have to terminate things with extreme prejudice.
4081 */
4082@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
4083 }
4084 #endif
4085
4086+#ifdef CONFIG_PAX_PAGEEXEC
4087+ if (fsr & FSR_LNX_PF) {
4088+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
4089+ do_group_exit(SIGKILL);
4090+ }
4091+#endif
4092+
4093 tsk->thread.address = addr;
4094 tsk->thread.error_code = fsr;
4095 tsk->thread.trap_no = 14;
4096@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4097 }
4098 #endif /* CONFIG_MMU */
4099
4100+#ifdef CONFIG_PAX_PAGEEXEC
4101+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4102+{
4103+ long i;
4104+
4105+ printk(KERN_ERR "PAX: bytes at PC: ");
4106+ for (i = 0; i < 20; i++) {
4107+ unsigned char c;
4108+ if (get_user(c, (__force unsigned char __user *)pc+i))
4109+ printk(KERN_CONT "?? ");
4110+ else
4111+ printk(KERN_CONT "%02x ", c);
4112+ }
4113+ printk("\n");
4114+
4115+ printk(KERN_ERR "PAX: bytes at SP-4: ");
4116+ for (i = -1; i < 20; i++) {
4117+ unsigned long c;
4118+ if (get_user(c, (__force unsigned long __user *)sp+i))
4119+ printk(KERN_CONT "???????? ");
4120+ else
4121+ printk(KERN_CONT "%08lx ", c);
4122+ }
4123+ printk("\n");
4124+}
4125+#endif
4126+
4127 /*
4128 * First Level Translation Fault Handler
4129 *
4130@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4131 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4132 struct siginfo info;
4133
4134+#ifdef CONFIG_PAX_MEMORY_UDEREF
4135+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4136+ if (current->signal->curr_ip)
4137+ 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),
4138+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4139+ else
4140+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4141+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4142+ goto die;
4143+ }
4144+#endif
4145+
4146 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4147 return;
4148
4149+die:
4150 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4151 inf->name, fsr, addr);
4152
4153@@ -574,15 +647,104 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4154 ifsr_info[nr].name = name;
4155 }
4156
4157+asmlinkage int sys_sigreturn(struct pt_regs *regs);
4158+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4159+
4160 asmlinkage void __exception
4161 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4162 {
4163 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4164 struct siginfo info;
4165+ unsigned long pc = instruction_pointer(regs);
4166+
4167+ if (user_mode(regs)) {
4168+ unsigned long sigpage = current->mm->context.sigpage;
4169+
4170+ if (sigpage <= pc && pc < sigpage + 7*4) {
4171+ if (pc < sigpage + 3*4)
4172+ sys_sigreturn(regs);
4173+ else
4174+ sys_rt_sigreturn(regs);
4175+ return;
4176+ }
4177+ if (pc == 0xffff0f60UL) {
4178+ /*
4179+ * PaX: __kuser_cmpxchg64 emulation
4180+ */
4181+ // TODO
4182+ //regs->ARM_pc = regs->ARM_lr;
4183+ //return;
4184+ }
4185+ if (pc == 0xffff0fa0UL) {
4186+ /*
4187+ * PaX: __kuser_memory_barrier emulation
4188+ */
4189+ // dmb(); implied by the exception
4190+ regs->ARM_pc = regs->ARM_lr;
4191+ return;
4192+ }
4193+ if (pc == 0xffff0fc0UL) {
4194+ /*
4195+ * PaX: __kuser_cmpxchg emulation
4196+ */
4197+ // TODO
4198+ //long new;
4199+ //int op;
4200+
4201+ //op = FUTEX_OP_SET << 28;
4202+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4203+ //regs->ARM_r0 = old != new;
4204+ //regs->ARM_pc = regs->ARM_lr;
4205+ //return;
4206+ }
4207+ if (pc == 0xffff0fe0UL) {
4208+ /*
4209+ * PaX: __kuser_get_tls emulation
4210+ */
4211+ regs->ARM_r0 = current_thread_info()->tp_value[0];
4212+ regs->ARM_pc = regs->ARM_lr;
4213+ return;
4214+ }
4215+ }
4216+
4217+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4218+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4219+ if (current->signal->curr_ip)
4220+ 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),
4221+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4222+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4223+ else
4224+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4225+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4226+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4227+ goto die;
4228+ }
4229+#endif
4230+
4231+#ifdef CONFIG_PAX_REFCOUNT
4232+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4233+#ifdef CONFIG_THUMB2_KERNEL
4234+ unsigned short bkpt;
4235+
4236+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le16(bkpt) == 0xbef1) {
4237+#else
4238+ unsigned int bkpt;
4239+
4240+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4241+#endif
4242+ current->thread.error_code = ifsr;
4243+ current->thread.trap_no = 0;
4244+ pax_report_refcount_overflow(regs);
4245+ fixup_exception(regs);
4246+ return;
4247+ }
4248+ }
4249+#endif
4250
4251 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4252 return;
4253
4254+die:
4255 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4256 inf->name, ifsr, addr);
4257
4258diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4259index cf08bdf..772656c 100644
4260--- a/arch/arm/mm/fault.h
4261+++ b/arch/arm/mm/fault.h
4262@@ -3,6 +3,7 @@
4263
4264 /*
4265 * Fault status register encodings. We steal bit 31 for our own purposes.
4266+ * Set when the FSR value is from an instruction fault.
4267 */
4268 #define FSR_LNX_PF (1 << 31)
4269 #define FSR_WRITE (1 << 11)
4270@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4271 }
4272 #endif
4273
4274+/* valid for LPAE and !LPAE */
4275+static inline int is_xn_fault(unsigned int fsr)
4276+{
4277+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4278+}
4279+
4280+static inline int is_domain_fault(unsigned int fsr)
4281+{
4282+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4283+}
4284+
4285 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4286 unsigned long search_exception_table(unsigned long addr);
4287
4288diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4289index 659c75d..6f8c029 100644
4290--- a/arch/arm/mm/init.c
4291+++ b/arch/arm/mm/init.c
4292@@ -31,6 +31,8 @@
4293 #include <asm/setup.h>
4294 #include <asm/tlb.h>
4295 #include <asm/fixmap.h>
4296+#include <asm/system_info.h>
4297+#include <asm/cp15.h>
4298
4299 #include <asm/mach/arch.h>
4300 #include <asm/mach/map.h>
4301@@ -619,7 +621,46 @@ void free_initmem(void)
4302 {
4303 #ifdef CONFIG_HAVE_TCM
4304 extern char __tcm_start, __tcm_end;
4305+#endif
4306
4307+#ifdef CONFIG_PAX_KERNEXEC
4308+ unsigned long addr;
4309+ pgd_t *pgd;
4310+ pud_t *pud;
4311+ pmd_t *pmd;
4312+ int cpu_arch = cpu_architecture();
4313+ unsigned int cr = get_cr();
4314+
4315+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4316+ /* make pages tables, etc before .text NX */
4317+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4318+ pgd = pgd_offset_k(addr);
4319+ pud = pud_offset(pgd, addr);
4320+ pmd = pmd_offset(pud, addr);
4321+ __section_update(pmd, addr, PMD_SECT_XN);
4322+ }
4323+ /* make init NX */
4324+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4325+ pgd = pgd_offset_k(addr);
4326+ pud = pud_offset(pgd, addr);
4327+ pmd = pmd_offset(pud, addr);
4328+ __section_update(pmd, addr, PMD_SECT_XN);
4329+ }
4330+ /* make kernel code/rodata RX */
4331+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4332+ pgd = pgd_offset_k(addr);
4333+ pud = pud_offset(pgd, addr);
4334+ pmd = pmd_offset(pud, addr);
4335+#ifdef CONFIG_ARM_LPAE
4336+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4337+#else
4338+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4339+#endif
4340+ }
4341+ }
4342+#endif
4343+
4344+#ifdef CONFIG_HAVE_TCM
4345 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4346 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4347 #endif
4348diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4349index d1e5ad7..84dcbf2 100644
4350--- a/arch/arm/mm/ioremap.c
4351+++ b/arch/arm/mm/ioremap.c
4352@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4353 unsigned int mtype;
4354
4355 if (cached)
4356- mtype = MT_MEMORY_RWX;
4357+ mtype = MT_MEMORY_RX;
4358 else
4359- mtype = MT_MEMORY_RWX_NONCACHED;
4360+ mtype = MT_MEMORY_RX_NONCACHED;
4361
4362 return __arm_ioremap_caller(phys_addr, size, mtype,
4363 __builtin_return_address(0));
4364diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4365index 5e85ed3..b10a7ed 100644
4366--- a/arch/arm/mm/mmap.c
4367+++ b/arch/arm/mm/mmap.c
4368@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4369 struct vm_area_struct *vma;
4370 int do_align = 0;
4371 int aliasing = cache_is_vipt_aliasing();
4372+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4373 struct vm_unmapped_area_info info;
4374
4375 /*
4376@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4377 if (len > TASK_SIZE)
4378 return -ENOMEM;
4379
4380+#ifdef CONFIG_PAX_RANDMMAP
4381+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4382+#endif
4383+
4384 if (addr) {
4385 if (do_align)
4386 addr = COLOUR_ALIGN(addr, pgoff);
4387@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4388 addr = PAGE_ALIGN(addr);
4389
4390 vma = find_vma(mm, addr);
4391- if (TASK_SIZE - len >= addr &&
4392- (!vma || addr + len <= vma->vm_start))
4393+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4394 return addr;
4395 }
4396
4397@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4398 info.high_limit = TASK_SIZE;
4399 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4400 info.align_offset = pgoff << PAGE_SHIFT;
4401+ info.threadstack_offset = offset;
4402 return vm_unmapped_area(&info);
4403 }
4404
4405@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4406 unsigned long addr = addr0;
4407 int do_align = 0;
4408 int aliasing = cache_is_vipt_aliasing();
4409+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4410 struct vm_unmapped_area_info info;
4411
4412 /*
4413@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4414 return addr;
4415 }
4416
4417+#ifdef CONFIG_PAX_RANDMMAP
4418+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4419+#endif
4420+
4421 /* requesting a specific address */
4422 if (addr) {
4423 if (do_align)
4424@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4425 else
4426 addr = PAGE_ALIGN(addr);
4427 vma = find_vma(mm, addr);
4428- if (TASK_SIZE - len >= addr &&
4429- (!vma || addr + len <= vma->vm_start))
4430+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4431 return addr;
4432 }
4433
4434@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4435 info.high_limit = mm->mmap_base;
4436 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4437 info.align_offset = pgoff << PAGE_SHIFT;
4438+ info.threadstack_offset = offset;
4439 addr = vm_unmapped_area(&info);
4440
4441 /*
4442@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4443 {
4444 unsigned long random_factor = 0UL;
4445
4446+#ifdef CONFIG_PAX_RANDMMAP
4447+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4448+#endif
4449+
4450 /* 8 bits of randomness in 20 address space bits */
4451 if ((current->flags & PF_RANDOMIZE) &&
4452 !(current->personality & ADDR_NO_RANDOMIZE))
4453@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4454
4455 if (mmap_is_legacy()) {
4456 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4457+
4458+#ifdef CONFIG_PAX_RANDMMAP
4459+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4460+ mm->mmap_base += mm->delta_mmap;
4461+#endif
4462+
4463 mm->get_unmapped_area = arch_get_unmapped_area;
4464 } else {
4465 mm->mmap_base = mmap_base(random_factor);
4466+
4467+#ifdef CONFIG_PAX_RANDMMAP
4468+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4469+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4470+#endif
4471+
4472 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4473 }
4474 }
4475diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4476index 8348ed6..b73a807 100644
4477--- a/arch/arm/mm/mmu.c
4478+++ b/arch/arm/mm/mmu.c
4479@@ -40,6 +40,22 @@
4480 #include "mm.h"
4481 #include "tcm.h"
4482
4483+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4484+void modify_domain(unsigned int dom, unsigned int type)
4485+{
4486+ struct thread_info *thread = current_thread_info();
4487+ unsigned int domain = thread->cpu_domain;
4488+ /*
4489+ * DOMAIN_MANAGER might be defined to some other value,
4490+ * use the arch-defined constant
4491+ */
4492+ domain &= ~domain_val(dom, 3);
4493+ thread->cpu_domain = domain | domain_val(dom, type);
4494+ set_domain(thread->cpu_domain);
4495+}
4496+EXPORT_SYMBOL(modify_domain);
4497+#endif
4498+
4499 /*
4500 * empty_zero_page is a special page that is used for
4501 * zero-initialized data and COW.
4502@@ -239,7 +255,15 @@ __setup("noalign", noalign_setup);
4503 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4504 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4505
4506-static struct mem_type mem_types[] = {
4507+#ifdef CONFIG_PAX_KERNEXEC
4508+#define L_PTE_KERNEXEC L_PTE_RDONLY
4509+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4510+#else
4511+#define L_PTE_KERNEXEC L_PTE_DIRTY
4512+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4513+#endif
4514+
4515+static struct mem_type mem_types[] __read_only = {
4516 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4517 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4518 L_PTE_SHARED,
4519@@ -268,19 +292,19 @@ static struct mem_type mem_types[] = {
4520 .prot_sect = PROT_SECT_DEVICE,
4521 .domain = DOMAIN_IO,
4522 },
4523- [MT_UNCACHED] = {
4524+ [MT_UNCACHED_RW] = {
4525 .prot_pte = PROT_PTE_DEVICE,
4526 .prot_l1 = PMD_TYPE_TABLE,
4527 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4528 .domain = DOMAIN_IO,
4529 },
4530- [MT_CACHECLEAN] = {
4531- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4532+ [MT_CACHECLEAN_RO] = {
4533+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4534 .domain = DOMAIN_KERNEL,
4535 },
4536 #ifndef CONFIG_ARM_LPAE
4537- [MT_MINICLEAN] = {
4538- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4539+ [MT_MINICLEAN_RO] = {
4540+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4541 .domain = DOMAIN_KERNEL,
4542 },
4543 #endif
4544@@ -288,15 +312,15 @@ static struct mem_type mem_types[] = {
4545 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4546 L_PTE_RDONLY,
4547 .prot_l1 = PMD_TYPE_TABLE,
4548- .domain = DOMAIN_USER,
4549+ .domain = DOMAIN_VECTORS,
4550 },
4551 [MT_HIGH_VECTORS] = {
4552 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4553 L_PTE_USER | L_PTE_RDONLY,
4554 .prot_l1 = PMD_TYPE_TABLE,
4555- .domain = DOMAIN_USER,
4556+ .domain = DOMAIN_VECTORS,
4557 },
4558- [MT_MEMORY_RWX] = {
4559+ [__MT_MEMORY_RWX] = {
4560 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4561 .prot_l1 = PMD_TYPE_TABLE,
4562 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4563@@ -309,17 +333,30 @@ static struct mem_type mem_types[] = {
4564 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4565 .domain = DOMAIN_KERNEL,
4566 },
4567- [MT_ROM] = {
4568- .prot_sect = PMD_TYPE_SECT,
4569+ [MT_MEMORY_RX] = {
4570+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4571+ .prot_l1 = PMD_TYPE_TABLE,
4572+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4573+ .domain = DOMAIN_KERNEL,
4574+ },
4575+ [MT_ROM_RX] = {
4576+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4577 .domain = DOMAIN_KERNEL,
4578 },
4579- [MT_MEMORY_RWX_NONCACHED] = {
4580+ [MT_MEMORY_RW_NONCACHED] = {
4581 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4582 L_PTE_MT_BUFFERABLE,
4583 .prot_l1 = PMD_TYPE_TABLE,
4584 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4585 .domain = DOMAIN_KERNEL,
4586 },
4587+ [MT_MEMORY_RX_NONCACHED] = {
4588+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4589+ L_PTE_MT_BUFFERABLE,
4590+ .prot_l1 = PMD_TYPE_TABLE,
4591+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4592+ .domain = DOMAIN_KERNEL,
4593+ },
4594 [MT_MEMORY_RW_DTCM] = {
4595 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4596 L_PTE_XN,
4597@@ -327,9 +364,10 @@ static struct mem_type mem_types[] = {
4598 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4599 .domain = DOMAIN_KERNEL,
4600 },
4601- [MT_MEMORY_RWX_ITCM] = {
4602- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4603+ [MT_MEMORY_RX_ITCM] = {
4604+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4605 .prot_l1 = PMD_TYPE_TABLE,
4606+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4607 .domain = DOMAIN_KERNEL,
4608 },
4609 [MT_MEMORY_RW_SO] = {
4610@@ -547,9 +585,14 @@ static void __init build_mem_type_table(void)
4611 * Mark cache clean areas and XIP ROM read only
4612 * from SVC mode and no access from userspace.
4613 */
4614- mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4615- mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4616- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4617+ mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4618+#ifdef CONFIG_PAX_KERNEXEC
4619+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4620+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4621+ mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4622+#endif
4623+ mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4624+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4625 #endif
4626
4627 /*
4628@@ -566,13 +609,17 @@ static void __init build_mem_type_table(void)
4629 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4630 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4631 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4632- mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4633- mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4634+ mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4635+ mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4636 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4637 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4638+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4639+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4640 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4641- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4642- mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4643+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4644+ mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4645+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4646+ mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4647 }
4648 }
4649
4650@@ -583,15 +630,20 @@ static void __init build_mem_type_table(void)
4651 if (cpu_arch >= CPU_ARCH_ARMv6) {
4652 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4653 /* Non-cacheable Normal is XCB = 001 */
4654- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4655+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4656+ PMD_SECT_BUFFERED;
4657+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4658 PMD_SECT_BUFFERED;
4659 } else {
4660 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4661- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4662+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4663+ PMD_SECT_TEX(1);
4664+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4665 PMD_SECT_TEX(1);
4666 }
4667 } else {
4668- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4669+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4670+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4671 }
4672
4673 #ifdef CONFIG_ARM_LPAE
4674@@ -607,6 +659,8 @@ static void __init build_mem_type_table(void)
4675 vecs_pgprot |= PTE_EXT_AF;
4676 #endif
4677
4678+ user_pgprot |= __supported_pte_mask;
4679+
4680 for (i = 0; i < 16; i++) {
4681 pteval_t v = pgprot_val(protection_map[i]);
4682 protection_map[i] = __pgprot(v | user_pgprot);
4683@@ -624,21 +678,24 @@ static void __init build_mem_type_table(void)
4684
4685 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4686 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4687- mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4688- mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4689+ mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4690+ mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4691 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4692 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4693+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4694+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4695 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4696- mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4697- mem_types[MT_ROM].prot_sect |= cp->pmd;
4698+ mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4699+ mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4700+ mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4701
4702 switch (cp->pmd) {
4703 case PMD_SECT_WT:
4704- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4705+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4706 break;
4707 case PMD_SECT_WB:
4708 case PMD_SECT_WBWA:
4709- mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4710+ mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4711 break;
4712 }
4713 pr_info("Memory policy: %sData cache %s\n",
4714@@ -856,7 +913,7 @@ static void __init create_mapping(struct map_desc *md)
4715 return;
4716 }
4717
4718- if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4719+ if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4720 md->virtual >= PAGE_OFFSET &&
4721 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4722 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4723@@ -1224,18 +1281,15 @@ void __init arm_mm_memblock_reserve(void)
4724 * called function. This means you can't use any function or debugging
4725 * method which may touch any device, otherwise the kernel _will_ crash.
4726 */
4727+
4728+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4729+
4730 static void __init devicemaps_init(const struct machine_desc *mdesc)
4731 {
4732 struct map_desc map;
4733 unsigned long addr;
4734- void *vectors;
4735
4736- /*
4737- * Allocate the vector page early.
4738- */
4739- vectors = early_alloc(PAGE_SIZE * 2);
4740-
4741- early_trap_init(vectors);
4742+ early_trap_init(&vectors);
4743
4744 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4745 pmd_clear(pmd_off_k(addr));
4746@@ -1248,7 +1302,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4747 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4748 map.virtual = MODULES_VADDR;
4749 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4750- map.type = MT_ROM;
4751+ map.type = MT_ROM_RX;
4752 create_mapping(&map);
4753 #endif
4754
4755@@ -1259,14 +1313,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4756 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4757 map.virtual = FLUSH_BASE;
4758 map.length = SZ_1M;
4759- map.type = MT_CACHECLEAN;
4760+ map.type = MT_CACHECLEAN_RO;
4761 create_mapping(&map);
4762 #endif
4763 #ifdef FLUSH_BASE_MINICACHE
4764 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4765 map.virtual = FLUSH_BASE_MINICACHE;
4766 map.length = SZ_1M;
4767- map.type = MT_MINICLEAN;
4768+ map.type = MT_MINICLEAN_RO;
4769 create_mapping(&map);
4770 #endif
4771
4772@@ -1275,7 +1329,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4773 * location (0xffff0000). If we aren't using high-vectors, also
4774 * create a mapping at the low-vectors virtual address.
4775 */
4776- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4777+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4778 map.virtual = 0xffff0000;
4779 map.length = PAGE_SIZE;
4780 #ifdef CONFIG_KUSER_HELPERS
4781@@ -1335,8 +1389,10 @@ static void __init kmap_init(void)
4782 static void __init map_lowmem(void)
4783 {
4784 struct memblock_region *reg;
4785+#ifndef CONFIG_PAX_KERNEXEC
4786 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4787 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4788+#endif
4789
4790 /* Map all the lowmem memory banks. */
4791 for_each_memblock(memory, reg) {
4792@@ -1349,11 +1405,48 @@ static void __init map_lowmem(void)
4793 if (start >= end)
4794 break;
4795
4796+#ifdef CONFIG_PAX_KERNEXEC
4797+ map.pfn = __phys_to_pfn(start);
4798+ map.virtual = __phys_to_virt(start);
4799+ map.length = end - start;
4800+
4801+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4802+ struct map_desc kernel;
4803+ struct map_desc initmap;
4804+
4805+ /* when freeing initmem we will make this RW */
4806+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4807+ initmap.virtual = (unsigned long)__init_begin;
4808+ initmap.length = _sdata - __init_begin;
4809+ initmap.type = __MT_MEMORY_RWX;
4810+ create_mapping(&initmap);
4811+
4812+ /* when freeing initmem we will make this RX */
4813+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4814+ kernel.virtual = (unsigned long)_stext;
4815+ kernel.length = __init_begin - _stext;
4816+ kernel.type = __MT_MEMORY_RWX;
4817+ create_mapping(&kernel);
4818+
4819+ if (map.virtual < (unsigned long)_stext) {
4820+ map.length = (unsigned long)_stext - map.virtual;
4821+ map.type = __MT_MEMORY_RWX;
4822+ create_mapping(&map);
4823+ }
4824+
4825+ map.pfn = __phys_to_pfn(__pa(_sdata));
4826+ map.virtual = (unsigned long)_sdata;
4827+ map.length = end - __pa(_sdata);
4828+ }
4829+
4830+ map.type = MT_MEMORY_RW;
4831+ create_mapping(&map);
4832+#else
4833 if (end < kernel_x_start || start >= kernel_x_end) {
4834 map.pfn = __phys_to_pfn(start);
4835 map.virtual = __phys_to_virt(start);
4836 map.length = end - start;
4837- map.type = MT_MEMORY_RWX;
4838+ map.type = __MT_MEMORY_RWX;
4839
4840 create_mapping(&map);
4841 } else {
4842@@ -1370,7 +1463,7 @@ static void __init map_lowmem(void)
4843 map.pfn = __phys_to_pfn(kernel_x_start);
4844 map.virtual = __phys_to_virt(kernel_x_start);
4845 map.length = kernel_x_end - kernel_x_start;
4846- map.type = MT_MEMORY_RWX;
4847+ map.type = __MT_MEMORY_RWX;
4848
4849 create_mapping(&map);
4850
4851@@ -1383,6 +1476,7 @@ static void __init map_lowmem(void)
4852 create_mapping(&map);
4853 }
4854 }
4855+#endif
4856 }
4857 }
4858
4859diff --git a/arch/arm/net/bpf_jit_32.c b/arch/arm/net/bpf_jit_32.c
4860index a37b989..5c9ae75 100644
4861--- a/arch/arm/net/bpf_jit_32.c
4862+++ b/arch/arm/net/bpf_jit_32.c
4863@@ -71,7 +71,11 @@ struct jit_ctx {
4864 #endif
4865 };
4866
4867+#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
4868+int bpf_jit_enable __read_only;
4869+#else
4870 int bpf_jit_enable __read_mostly;
4871+#endif
4872
4873 static u64 jit_get_skb_b(struct sk_buff *skb, unsigned offset)
4874 {
4875@@ -930,5 +934,6 @@ void bpf_jit_free(struct bpf_prog *fp)
4876 {
4877 if (fp->jited)
4878 module_free(NULL, fp->bpf_func);
4879- kfree(fp);
4880+
4881+ bpf_prog_unlock_free(fp);
4882 }
4883diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4884index 5b217f4..c23f40e 100644
4885--- a/arch/arm/plat-iop/setup.c
4886+++ b/arch/arm/plat-iop/setup.c
4887@@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4888 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4889 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4890 .length = IOP3XX_PERIPHERAL_SIZE,
4891- .type = MT_UNCACHED,
4892+ .type = MT_UNCACHED_RW,
4893 },
4894 };
4895
4896diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4897index a5bc92d..0bb4730 100644
4898--- a/arch/arm/plat-omap/sram.c
4899+++ b/arch/arm/plat-omap/sram.c
4900@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4901 * Looks like we need to preserve some bootloader code at the
4902 * beginning of SRAM for jumping to flash for reboot to work...
4903 */
4904+ pax_open_kernel();
4905 memset_io(omap_sram_base + omap_sram_skip, 0,
4906 omap_sram_size - omap_sram_skip);
4907+ pax_close_kernel();
4908 }
4909diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4910index ce6d763..cfea917 100644
4911--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4912+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4913@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4914 int (*started)(unsigned ch);
4915 int (*flush)(unsigned ch);
4916 int (*stop)(unsigned ch);
4917-};
4918+} __no_const;
4919
4920 extern void *samsung_dmadev_get_ops(void);
4921 extern void *s3c_dma_get_ops(void);
4922diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4923index 6389d60..b5d3bdd 100644
4924--- a/arch/arm64/include/asm/barrier.h
4925+++ b/arch/arm64/include/asm/barrier.h
4926@@ -41,7 +41,7 @@
4927 do { \
4928 compiletime_assert_atomic_type(*p); \
4929 barrier(); \
4930- ACCESS_ONCE(*p) = (v); \
4931+ ACCESS_ONCE_RW(*p) = (v); \
4932 } while (0)
4933
4934 #define smp_load_acquire(p) \
4935diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4936index 3bf8f4e..5dd5491 100644
4937--- a/arch/arm64/include/asm/uaccess.h
4938+++ b/arch/arm64/include/asm/uaccess.h
4939@@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4940 flag; \
4941 })
4942
4943+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4944 #define access_ok(type, addr, size) __range_ok(addr, size)
4945 #define user_addr_max get_fs
4946
4947diff --git a/arch/arm64/lib/clear_user.S b/arch/arm64/lib/clear_user.S
4948index 6e0ed93..c17967f 100644
4949--- a/arch/arm64/lib/clear_user.S
4950+++ b/arch/arm64/lib/clear_user.S
4951@@ -46,7 +46,7 @@ USER(9f, strh wzr, [x0], #2 )
4952 sub x1, x1, #2
4953 4: adds x1, x1, #1
4954 b.mi 5f
4955- strb wzr, [x0]
4956+USER(9f, strb wzr, [x0] )
4957 5: mov x0, #0
4958 ret
4959 ENDPROC(__clear_user)
4960diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4961index c3a58a1..78fbf54 100644
4962--- a/arch/avr32/include/asm/cache.h
4963+++ b/arch/avr32/include/asm/cache.h
4964@@ -1,8 +1,10 @@
4965 #ifndef __ASM_AVR32_CACHE_H
4966 #define __ASM_AVR32_CACHE_H
4967
4968+#include <linux/const.h>
4969+
4970 #define L1_CACHE_SHIFT 5
4971-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4972+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4973
4974 /*
4975 * Memory returned by kmalloc() may be used for DMA, so we must make
4976diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4977index d232888..87c8df1 100644
4978--- a/arch/avr32/include/asm/elf.h
4979+++ b/arch/avr32/include/asm/elf.h
4980@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4981 the loader. We need to make sure that it is out of the way of the program
4982 that it will "exec", and that there is sufficient room for the brk. */
4983
4984-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4985+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4986
4987+#ifdef CONFIG_PAX_ASLR
4988+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4989+
4990+#define PAX_DELTA_MMAP_LEN 15
4991+#define PAX_DELTA_STACK_LEN 15
4992+#endif
4993
4994 /* This yields a mask that user programs can use to figure out what
4995 instruction set this CPU supports. This could be done in user space,
4996diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4997index 479330b..53717a8 100644
4998--- a/arch/avr32/include/asm/kmap_types.h
4999+++ b/arch/avr32/include/asm/kmap_types.h
5000@@ -2,9 +2,9 @@
5001 #define __ASM_AVR32_KMAP_TYPES_H
5002
5003 #ifdef CONFIG_DEBUG_HIGHMEM
5004-# define KM_TYPE_NR 29
5005+# define KM_TYPE_NR 30
5006 #else
5007-# define KM_TYPE_NR 14
5008+# define KM_TYPE_NR 15
5009 #endif
5010
5011 #endif /* __ASM_AVR32_KMAP_TYPES_H */
5012diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
5013index 0eca933..eb78c7b 100644
5014--- a/arch/avr32/mm/fault.c
5015+++ b/arch/avr32/mm/fault.c
5016@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
5017
5018 int exception_trace = 1;
5019
5020+#ifdef CONFIG_PAX_PAGEEXEC
5021+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5022+{
5023+ unsigned long i;
5024+
5025+ printk(KERN_ERR "PAX: bytes at PC: ");
5026+ for (i = 0; i < 20; i++) {
5027+ unsigned char c;
5028+ if (get_user(c, (unsigned char *)pc+i))
5029+ printk(KERN_CONT "???????? ");
5030+ else
5031+ printk(KERN_CONT "%02x ", c);
5032+ }
5033+ printk("\n");
5034+}
5035+#endif
5036+
5037 /*
5038 * This routine handles page faults. It determines the address and the
5039 * problem, and then passes it off to one of the appropriate routines.
5040@@ -176,6 +193,16 @@ bad_area:
5041 up_read(&mm->mmap_sem);
5042
5043 if (user_mode(regs)) {
5044+
5045+#ifdef CONFIG_PAX_PAGEEXEC
5046+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
5047+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
5048+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
5049+ do_group_exit(SIGKILL);
5050+ }
5051+ }
5052+#endif
5053+
5054 if (exception_trace && printk_ratelimit())
5055 printk("%s%s[%d]: segfault at %08lx pc %08lx "
5056 "sp %08lx ecr %lu\n",
5057diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
5058index 568885a..f8008df 100644
5059--- a/arch/blackfin/include/asm/cache.h
5060+++ b/arch/blackfin/include/asm/cache.h
5061@@ -7,6 +7,7 @@
5062 #ifndef __ARCH_BLACKFIN_CACHE_H
5063 #define __ARCH_BLACKFIN_CACHE_H
5064
5065+#include <linux/const.h>
5066 #include <linux/linkage.h> /* for asmlinkage */
5067
5068 /*
5069@@ -14,7 +15,7 @@
5070 * Blackfin loads 32 bytes for cache
5071 */
5072 #define L1_CACHE_SHIFT 5
5073-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5074+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5075 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5076
5077 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5078diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
5079index aea2718..3639a60 100644
5080--- a/arch/cris/include/arch-v10/arch/cache.h
5081+++ b/arch/cris/include/arch-v10/arch/cache.h
5082@@ -1,8 +1,9 @@
5083 #ifndef _ASM_ARCH_CACHE_H
5084 #define _ASM_ARCH_CACHE_H
5085
5086+#include <linux/const.h>
5087 /* Etrax 100LX have 32-byte cache-lines. */
5088-#define L1_CACHE_BYTES 32
5089 #define L1_CACHE_SHIFT 5
5090+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5091
5092 #endif /* _ASM_ARCH_CACHE_H */
5093diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
5094index 7caf25d..ee65ac5 100644
5095--- a/arch/cris/include/arch-v32/arch/cache.h
5096+++ b/arch/cris/include/arch-v32/arch/cache.h
5097@@ -1,11 +1,12 @@
5098 #ifndef _ASM_CRIS_ARCH_CACHE_H
5099 #define _ASM_CRIS_ARCH_CACHE_H
5100
5101+#include <linux/const.h>
5102 #include <arch/hwregs/dma.h>
5103
5104 /* A cache-line is 32 bytes. */
5105-#define L1_CACHE_BYTES 32
5106 #define L1_CACHE_SHIFT 5
5107+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5108
5109 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5110
5111diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
5112index f6c3a16..cd422a4 100644
5113--- a/arch/frv/include/asm/atomic.h
5114+++ b/arch/frv/include/asm/atomic.h
5115@@ -181,6 +181,16 @@ static inline void atomic64_dec(atomic64_t *v)
5116 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
5117 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
5118
5119+#define atomic64_read_unchecked(v) atomic64_read(v)
5120+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5121+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5122+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5123+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5124+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5125+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5126+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5127+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5128+
5129 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5130 {
5131 int c, old;
5132diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
5133index 2797163..c2a401d 100644
5134--- a/arch/frv/include/asm/cache.h
5135+++ b/arch/frv/include/asm/cache.h
5136@@ -12,10 +12,11 @@
5137 #ifndef __ASM_CACHE_H
5138 #define __ASM_CACHE_H
5139
5140+#include <linux/const.h>
5141
5142 /* bytes per L1 cache line */
5143 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
5144-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5145+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5146
5147 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5148 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
5149diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
5150index 43901f2..0d8b865 100644
5151--- a/arch/frv/include/asm/kmap_types.h
5152+++ b/arch/frv/include/asm/kmap_types.h
5153@@ -2,6 +2,6 @@
5154 #ifndef _ASM_KMAP_TYPES_H
5155 #define _ASM_KMAP_TYPES_H
5156
5157-#define KM_TYPE_NR 17
5158+#define KM_TYPE_NR 18
5159
5160 #endif
5161diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5162index 836f147..4cf23f5 100644
5163--- a/arch/frv/mm/elf-fdpic.c
5164+++ b/arch/frv/mm/elf-fdpic.c
5165@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5166 {
5167 struct vm_area_struct *vma;
5168 struct vm_unmapped_area_info info;
5169+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5170
5171 if (len > TASK_SIZE)
5172 return -ENOMEM;
5173@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5174 if (addr) {
5175 addr = PAGE_ALIGN(addr);
5176 vma = find_vma(current->mm, addr);
5177- if (TASK_SIZE - len >= addr &&
5178- (!vma || addr + len <= vma->vm_start))
5179+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5180 goto success;
5181 }
5182
5183@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5184 info.high_limit = (current->mm->start_stack - 0x00200000);
5185 info.align_mask = 0;
5186 info.align_offset = 0;
5187+ info.threadstack_offset = offset;
5188 addr = vm_unmapped_area(&info);
5189 if (!(addr & ~PAGE_MASK))
5190 goto success;
5191diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5192index 2635117..fa223cb 100644
5193--- a/arch/hexagon/include/asm/cache.h
5194+++ b/arch/hexagon/include/asm/cache.h
5195@@ -21,9 +21,11 @@
5196 #ifndef __ASM_CACHE_H
5197 #define __ASM_CACHE_H
5198
5199+#include <linux/const.h>
5200+
5201 /* Bytes per L1 cache line */
5202-#define L1_CACHE_SHIFT (5)
5203-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5204+#define L1_CACHE_SHIFT 5
5205+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5206
5207 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5208 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5209diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5210index c84c88b..2a6e1ba 100644
5211--- a/arch/ia64/Kconfig
5212+++ b/arch/ia64/Kconfig
5213@@ -549,6 +549,7 @@ source "drivers/sn/Kconfig"
5214 config KEXEC
5215 bool "kexec system call"
5216 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5217+ depends on !GRKERNSEC_KMEM
5218 help
5219 kexec is a system call that implements the ability to shutdown your
5220 current kernel, and to start another kernel. It is like a reboot
5221diff --git a/arch/ia64/Makefile b/arch/ia64/Makefile
5222index 5441b14..039a446 100644
5223--- a/arch/ia64/Makefile
5224+++ b/arch/ia64/Makefile
5225@@ -99,5 +99,6 @@ endef
5226 archprepare: make_nr_irqs_h FORCE
5227 PHONY += make_nr_irqs_h FORCE
5228
5229+make_nr_irqs_h: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
5230 make_nr_irqs_h: FORCE
5231 $(Q)$(MAKE) $(build)=arch/ia64/kernel include/generated/nr-irqs.h
5232diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5233index 0f8bf48..40ea950 100644
5234--- a/arch/ia64/include/asm/atomic.h
5235+++ b/arch/ia64/include/asm/atomic.h
5236@@ -209,4 +209,14 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5237 #define atomic64_inc(v) atomic64_add(1, (v))
5238 #define atomic64_dec(v) atomic64_sub(1, (v))
5239
5240+#define atomic64_read_unchecked(v) atomic64_read(v)
5241+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5242+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5243+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5244+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5245+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5246+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5247+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5248+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5249+
5250 #endif /* _ASM_IA64_ATOMIC_H */
5251diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5252index a48957c..e097b56 100644
5253--- a/arch/ia64/include/asm/barrier.h
5254+++ b/arch/ia64/include/asm/barrier.h
5255@@ -67,7 +67,7 @@
5256 do { \
5257 compiletime_assert_atomic_type(*p); \
5258 barrier(); \
5259- ACCESS_ONCE(*p) = (v); \
5260+ ACCESS_ONCE_RW(*p) = (v); \
5261 } while (0)
5262
5263 #define smp_load_acquire(p) \
5264diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5265index 988254a..e1ee885 100644
5266--- a/arch/ia64/include/asm/cache.h
5267+++ b/arch/ia64/include/asm/cache.h
5268@@ -1,6 +1,7 @@
5269 #ifndef _ASM_IA64_CACHE_H
5270 #define _ASM_IA64_CACHE_H
5271
5272+#include <linux/const.h>
5273
5274 /*
5275 * Copyright (C) 1998-2000 Hewlett-Packard Co
5276@@ -9,7 +10,7 @@
5277
5278 /* Bytes per L1 (data) cache line. */
5279 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5280-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5281+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5282
5283 #ifdef CONFIG_SMP
5284 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5285diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5286index 5a83c5c..4d7f553 100644
5287--- a/arch/ia64/include/asm/elf.h
5288+++ b/arch/ia64/include/asm/elf.h
5289@@ -42,6 +42,13 @@
5290 */
5291 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5292
5293+#ifdef CONFIG_PAX_ASLR
5294+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5295+
5296+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5297+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5298+#endif
5299+
5300 #define PT_IA_64_UNWIND 0x70000001
5301
5302 /* IA-64 relocations: */
5303diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5304index 5767cdf..7462574 100644
5305--- a/arch/ia64/include/asm/pgalloc.h
5306+++ b/arch/ia64/include/asm/pgalloc.h
5307@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5308 pgd_val(*pgd_entry) = __pa(pud);
5309 }
5310
5311+static inline void
5312+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5313+{
5314+ pgd_populate(mm, pgd_entry, pud);
5315+}
5316+
5317 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5318 {
5319 return quicklist_alloc(0, GFP_KERNEL, NULL);
5320@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5321 pud_val(*pud_entry) = __pa(pmd);
5322 }
5323
5324+static inline void
5325+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5326+{
5327+ pud_populate(mm, pud_entry, pmd);
5328+}
5329+
5330 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5331 {
5332 return quicklist_alloc(0, GFP_KERNEL, NULL);
5333diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5334index 7935115..c0eca6a 100644
5335--- a/arch/ia64/include/asm/pgtable.h
5336+++ b/arch/ia64/include/asm/pgtable.h
5337@@ -12,7 +12,7 @@
5338 * David Mosberger-Tang <davidm@hpl.hp.com>
5339 */
5340
5341-
5342+#include <linux/const.h>
5343 #include <asm/mman.h>
5344 #include <asm/page.h>
5345 #include <asm/processor.h>
5346@@ -142,6 +142,17 @@
5347 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5348 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5349 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5350+
5351+#ifdef CONFIG_PAX_PAGEEXEC
5352+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5353+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5354+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5355+#else
5356+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5357+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5358+# define PAGE_COPY_NOEXEC PAGE_COPY
5359+#endif
5360+
5361 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5362 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5363 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5364diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5365index 45698cd..e8e2dbc 100644
5366--- a/arch/ia64/include/asm/spinlock.h
5367+++ b/arch/ia64/include/asm/spinlock.h
5368@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5369 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5370
5371 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5372- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5373+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5374 }
5375
5376 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5377diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5378index 449c8c0..3d4b1e9 100644
5379--- a/arch/ia64/include/asm/uaccess.h
5380+++ b/arch/ia64/include/asm/uaccess.h
5381@@ -70,6 +70,7 @@
5382 && ((segment).seg == KERNEL_DS.seg \
5383 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5384 })
5385+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5386 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5387
5388 /*
5389@@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5390 static inline unsigned long
5391 __copy_to_user (void __user *to, const void *from, unsigned long count)
5392 {
5393+ if (count > INT_MAX)
5394+ return count;
5395+
5396+ if (!__builtin_constant_p(count))
5397+ check_object_size(from, count, true);
5398+
5399 return __copy_user(to, (__force void __user *) from, count);
5400 }
5401
5402 static inline unsigned long
5403 __copy_from_user (void *to, const void __user *from, unsigned long count)
5404 {
5405+ if (count > INT_MAX)
5406+ return count;
5407+
5408+ if (!__builtin_constant_p(count))
5409+ check_object_size(to, count, false);
5410+
5411 return __copy_user((__force void __user *) to, from, count);
5412 }
5413
5414@@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5415 ({ \
5416 void __user *__cu_to = (to); \
5417 const void *__cu_from = (from); \
5418- long __cu_len = (n); \
5419+ unsigned long __cu_len = (n); \
5420 \
5421- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5422+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5423+ if (!__builtin_constant_p(n)) \
5424+ check_object_size(__cu_from, __cu_len, true); \
5425 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5426+ } \
5427 __cu_len; \
5428 })
5429
5430@@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5431 ({ \
5432 void *__cu_to = (to); \
5433 const void __user *__cu_from = (from); \
5434- long __cu_len = (n); \
5435+ unsigned long __cu_len = (n); \
5436 \
5437 __chk_user_ptr(__cu_from); \
5438- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5439+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5440+ if (!__builtin_constant_p(n)) \
5441+ check_object_size(__cu_to, __cu_len, false); \
5442 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5443+ } \
5444 __cu_len; \
5445 })
5446
5447diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5448index 24603be..948052d 100644
5449--- a/arch/ia64/kernel/module.c
5450+++ b/arch/ia64/kernel/module.c
5451@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5452 void
5453 module_free (struct module *mod, void *module_region)
5454 {
5455- if (mod && mod->arch.init_unw_table &&
5456- module_region == mod->module_init) {
5457+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5458 unw_remove_unwind_table(mod->arch.init_unw_table);
5459 mod->arch.init_unw_table = NULL;
5460 }
5461@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5462 }
5463
5464 static inline int
5465+in_init_rx (const struct module *mod, uint64_t addr)
5466+{
5467+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5468+}
5469+
5470+static inline int
5471+in_init_rw (const struct module *mod, uint64_t addr)
5472+{
5473+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5474+}
5475+
5476+static inline int
5477 in_init (const struct module *mod, uint64_t addr)
5478 {
5479- return addr - (uint64_t) mod->module_init < mod->init_size;
5480+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5481+}
5482+
5483+static inline int
5484+in_core_rx (const struct module *mod, uint64_t addr)
5485+{
5486+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5487+}
5488+
5489+static inline int
5490+in_core_rw (const struct module *mod, uint64_t addr)
5491+{
5492+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5493 }
5494
5495 static inline int
5496 in_core (const struct module *mod, uint64_t addr)
5497 {
5498- return addr - (uint64_t) mod->module_core < mod->core_size;
5499+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5500 }
5501
5502 static inline int
5503@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5504 break;
5505
5506 case RV_BDREL:
5507- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5508+ if (in_init_rx(mod, val))
5509+ val -= (uint64_t) mod->module_init_rx;
5510+ else if (in_init_rw(mod, val))
5511+ val -= (uint64_t) mod->module_init_rw;
5512+ else if (in_core_rx(mod, val))
5513+ val -= (uint64_t) mod->module_core_rx;
5514+ else if (in_core_rw(mod, val))
5515+ val -= (uint64_t) mod->module_core_rw;
5516 break;
5517
5518 case RV_LTV:
5519@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5520 * addresses have been selected...
5521 */
5522 uint64_t gp;
5523- if (mod->core_size > MAX_LTOFF)
5524+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5525 /*
5526 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5527 * at the end of the module.
5528 */
5529- gp = mod->core_size - MAX_LTOFF / 2;
5530+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5531 else
5532- gp = mod->core_size / 2;
5533- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5534+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5535+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5536 mod->arch.gp = gp;
5537 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5538 }
5539diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5540index c39c3cd..3c77738 100644
5541--- a/arch/ia64/kernel/palinfo.c
5542+++ b/arch/ia64/kernel/palinfo.c
5543@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5544 return NOTIFY_OK;
5545 }
5546
5547-static struct notifier_block __refdata palinfo_cpu_notifier =
5548+static struct notifier_block palinfo_cpu_notifier =
5549 {
5550 .notifier_call = palinfo_cpu_callback,
5551 .priority = 0,
5552diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5553index 41e33f8..65180b2a 100644
5554--- a/arch/ia64/kernel/sys_ia64.c
5555+++ b/arch/ia64/kernel/sys_ia64.c
5556@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5557 unsigned long align_mask = 0;
5558 struct mm_struct *mm = current->mm;
5559 struct vm_unmapped_area_info info;
5560+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5561
5562 if (len > RGN_MAP_LIMIT)
5563 return -ENOMEM;
5564@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5565 if (REGION_NUMBER(addr) == RGN_HPAGE)
5566 addr = 0;
5567 #endif
5568+
5569+#ifdef CONFIG_PAX_RANDMMAP
5570+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5571+ addr = mm->free_area_cache;
5572+ else
5573+#endif
5574+
5575 if (!addr)
5576 addr = TASK_UNMAPPED_BASE;
5577
5578@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5579 info.high_limit = TASK_SIZE;
5580 info.align_mask = align_mask;
5581 info.align_offset = 0;
5582+ info.threadstack_offset = offset;
5583 return vm_unmapped_area(&info);
5584 }
5585
5586diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5587index 84f8a52..7c76178 100644
5588--- a/arch/ia64/kernel/vmlinux.lds.S
5589+++ b/arch/ia64/kernel/vmlinux.lds.S
5590@@ -192,7 +192,7 @@ SECTIONS {
5591 /* Per-cpu data: */
5592 . = ALIGN(PERCPU_PAGE_SIZE);
5593 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5594- __phys_per_cpu_start = __per_cpu_load;
5595+ __phys_per_cpu_start = per_cpu_load;
5596 /*
5597 * ensure percpu data fits
5598 * into percpu page size
5599diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5600index 7225dad..2a7c8256 100644
5601--- a/arch/ia64/mm/fault.c
5602+++ b/arch/ia64/mm/fault.c
5603@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5604 return pte_present(pte);
5605 }
5606
5607+#ifdef CONFIG_PAX_PAGEEXEC
5608+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5609+{
5610+ unsigned long i;
5611+
5612+ printk(KERN_ERR "PAX: bytes at PC: ");
5613+ for (i = 0; i < 8; i++) {
5614+ unsigned int c;
5615+ if (get_user(c, (unsigned int *)pc+i))
5616+ printk(KERN_CONT "???????? ");
5617+ else
5618+ printk(KERN_CONT "%08x ", c);
5619+ }
5620+ printk("\n");
5621+}
5622+#endif
5623+
5624 # define VM_READ_BIT 0
5625 # define VM_WRITE_BIT 1
5626 # define VM_EXEC_BIT 2
5627@@ -151,8 +168,21 @@ retry:
5628 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5629 goto bad_area;
5630
5631- if ((vma->vm_flags & mask) != mask)
5632+ if ((vma->vm_flags & mask) != mask) {
5633+
5634+#ifdef CONFIG_PAX_PAGEEXEC
5635+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5636+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5637+ goto bad_area;
5638+
5639+ up_read(&mm->mmap_sem);
5640+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5641+ do_group_exit(SIGKILL);
5642+ }
5643+#endif
5644+
5645 goto bad_area;
5646+ }
5647
5648 /*
5649 * If for any reason at all we couldn't handle the fault, make
5650diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5651index 76069c1..c2aa816 100644
5652--- a/arch/ia64/mm/hugetlbpage.c
5653+++ b/arch/ia64/mm/hugetlbpage.c
5654@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5655 unsigned long pgoff, unsigned long flags)
5656 {
5657 struct vm_unmapped_area_info info;
5658+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5659
5660 if (len > RGN_MAP_LIMIT)
5661 return -ENOMEM;
5662@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5663 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5664 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5665 info.align_offset = 0;
5666+ info.threadstack_offset = offset;
5667 return vm_unmapped_area(&info);
5668 }
5669
5670diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5671index 6b33457..88b5124 100644
5672--- a/arch/ia64/mm/init.c
5673+++ b/arch/ia64/mm/init.c
5674@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5675 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5676 vma->vm_end = vma->vm_start + PAGE_SIZE;
5677 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5678+
5679+#ifdef CONFIG_PAX_PAGEEXEC
5680+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5681+ vma->vm_flags &= ~VM_EXEC;
5682+
5683+#ifdef CONFIG_PAX_MPROTECT
5684+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5685+ vma->vm_flags &= ~VM_MAYEXEC;
5686+#endif
5687+
5688+ }
5689+#endif
5690+
5691 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5692 down_write(&current->mm->mmap_sem);
5693 if (insert_vm_struct(current->mm, vma)) {
5694@@ -286,7 +299,7 @@ static int __init gate_vma_init(void)
5695 gate_vma.vm_start = FIXADDR_USER_START;
5696 gate_vma.vm_end = FIXADDR_USER_END;
5697 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
5698- gate_vma.vm_page_prot = __P101;
5699+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
5700
5701 return 0;
5702 }
5703diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5704index 40b3ee9..8c2c112 100644
5705--- a/arch/m32r/include/asm/cache.h
5706+++ b/arch/m32r/include/asm/cache.h
5707@@ -1,8 +1,10 @@
5708 #ifndef _ASM_M32R_CACHE_H
5709 #define _ASM_M32R_CACHE_H
5710
5711+#include <linux/const.h>
5712+
5713 /* L1 cache line size */
5714 #define L1_CACHE_SHIFT 4
5715-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5716+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5717
5718 #endif /* _ASM_M32R_CACHE_H */
5719diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5720index 82abd15..d95ae5d 100644
5721--- a/arch/m32r/lib/usercopy.c
5722+++ b/arch/m32r/lib/usercopy.c
5723@@ -14,6 +14,9 @@
5724 unsigned long
5725 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5726 {
5727+ if ((long)n < 0)
5728+ return n;
5729+
5730 prefetch(from);
5731 if (access_ok(VERIFY_WRITE, to, n))
5732 __copy_user(to,from,n);
5733@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5734 unsigned long
5735 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5736 {
5737+ if ((long)n < 0)
5738+ return n;
5739+
5740 prefetchw(to);
5741 if (access_ok(VERIFY_READ, from, n))
5742 __copy_user_zeroing(to,from,n);
5743diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5744index 0395c51..5f26031 100644
5745--- a/arch/m68k/include/asm/cache.h
5746+++ b/arch/m68k/include/asm/cache.h
5747@@ -4,9 +4,11 @@
5748 #ifndef __ARCH_M68K_CACHE_H
5749 #define __ARCH_M68K_CACHE_H
5750
5751+#include <linux/const.h>
5752+
5753 /* bytes per L1 cache line */
5754 #define L1_CACHE_SHIFT 4
5755-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5756+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5757
5758 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5759
5760diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5761index c7591e8..ecef036 100644
5762--- a/arch/metag/include/asm/barrier.h
5763+++ b/arch/metag/include/asm/barrier.h
5764@@ -89,7 +89,7 @@ static inline void fence(void)
5765 do { \
5766 compiletime_assert_atomic_type(*p); \
5767 smp_mb(); \
5768- ACCESS_ONCE(*p) = (v); \
5769+ ACCESS_ONCE_RW(*p) = (v); \
5770 } while (0)
5771
5772 #define smp_load_acquire(p) \
5773diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5774index 3c32075..ae0ae75 100644
5775--- a/arch/metag/mm/hugetlbpage.c
5776+++ b/arch/metag/mm/hugetlbpage.c
5777@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5778 info.high_limit = TASK_SIZE;
5779 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5780 info.align_offset = 0;
5781+ info.threadstack_offset = 0;
5782 return vm_unmapped_area(&info);
5783 }
5784
5785diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5786index 4efe96a..60e8699 100644
5787--- a/arch/microblaze/include/asm/cache.h
5788+++ b/arch/microblaze/include/asm/cache.h
5789@@ -13,11 +13,12 @@
5790 #ifndef _ASM_MICROBLAZE_CACHE_H
5791 #define _ASM_MICROBLAZE_CACHE_H
5792
5793+#include <linux/const.h>
5794 #include <asm/registers.h>
5795
5796 #define L1_CACHE_SHIFT 5
5797 /* word-granular cache in microblaze */
5798-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5799+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5800
5801 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5802
5803diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5804index 574c430..470200d 100644
5805--- a/arch/mips/Kconfig
5806+++ b/arch/mips/Kconfig
5807@@ -2399,6 +2399,7 @@ source "kernel/Kconfig.preempt"
5808
5809 config KEXEC
5810 bool "Kexec system call"
5811+ depends on !GRKERNSEC_KMEM
5812 help
5813 kexec is a system call that implements the ability to shutdown your
5814 current kernel, and to start another kernel. It is like a reboot
5815diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5816index 02f2444..506969c 100644
5817--- a/arch/mips/cavium-octeon/dma-octeon.c
5818+++ b/arch/mips/cavium-octeon/dma-octeon.c
5819@@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5820 if (dma_release_from_coherent(dev, order, vaddr))
5821 return;
5822
5823- swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5824+ swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5825 }
5826
5827 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5828diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5829index 37b2bef..02122b8 100644
5830--- a/arch/mips/include/asm/atomic.h
5831+++ b/arch/mips/include/asm/atomic.h
5832@@ -21,15 +21,39 @@
5833 #include <asm/cmpxchg.h>
5834 #include <asm/war.h>
5835
5836+#ifdef CONFIG_GENERIC_ATOMIC64
5837+#include <asm-generic/atomic64.h>
5838+#endif
5839+
5840 #define ATOMIC_INIT(i) { (i) }
5841
5842+#ifdef CONFIG_64BIT
5843+#define _ASM_EXTABLE(from, to) \
5844+" .section __ex_table,\"a\"\n" \
5845+" .dword " #from ", " #to"\n" \
5846+" .previous\n"
5847+#else
5848+#define _ASM_EXTABLE(from, to) \
5849+" .section __ex_table,\"a\"\n" \
5850+" .word " #from ", " #to"\n" \
5851+" .previous\n"
5852+#endif
5853+
5854 /*
5855 * atomic_read - read atomic variable
5856 * @v: pointer of type atomic_t
5857 *
5858 * Atomically reads the value of @v.
5859 */
5860-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5861+static inline int atomic_read(const atomic_t *v)
5862+{
5863+ return (*(volatile const int *) &v->counter);
5864+}
5865+
5866+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5867+{
5868+ return (*(volatile const int *) &v->counter);
5869+}
5870
5871 /*
5872 * atomic_set - set atomic variable
5873@@ -38,7 +62,15 @@
5874 *
5875 * Atomically sets the value of @v to @i.
5876 */
5877-#define atomic_set(v, i) ((v)->counter = (i))
5878+static inline void atomic_set(atomic_t *v, int i)
5879+{
5880+ v->counter = i;
5881+}
5882+
5883+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5884+{
5885+ v->counter = i;
5886+}
5887
5888 /*
5889 * atomic_add - add integer to atomic variable
5890@@ -47,7 +79,67 @@
5891 *
5892 * Atomically adds @i to @v.
5893 */
5894-static __inline__ void atomic_add(int i, atomic_t * v)
5895+static __inline__ void atomic_add(int i, atomic_t *v)
5896+{
5897+ int temp;
5898+
5899+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5900+ __asm__ __volatile__(
5901+ " .set mips3 \n"
5902+ "1: ll %0, %1 # atomic_add \n"
5903+#ifdef CONFIG_PAX_REFCOUNT
5904+ /* Exception on overflow. */
5905+ "2: add %0, %2 \n"
5906+#else
5907+ " addu %0, %2 \n"
5908+#endif
5909+ " sc %0, %1 \n"
5910+ " beqzl %0, 1b \n"
5911+#ifdef CONFIG_PAX_REFCOUNT
5912+ "3: \n"
5913+ _ASM_EXTABLE(2b, 3b)
5914+#endif
5915+ " .set mips0 \n"
5916+ : "=&r" (temp), "+m" (v->counter)
5917+ : "Ir" (i));
5918+ } else if (kernel_uses_llsc) {
5919+ __asm__ __volatile__(
5920+ " .set mips3 \n"
5921+ "1: ll %0, %1 # atomic_add \n"
5922+#ifdef CONFIG_PAX_REFCOUNT
5923+ /* Exception on overflow. */
5924+ "2: add %0, %2 \n"
5925+#else
5926+ " addu %0, %2 \n"
5927+#endif
5928+ " sc %0, %1 \n"
5929+ " beqz %0, 1b \n"
5930+#ifdef CONFIG_PAX_REFCOUNT
5931+ "3: \n"
5932+ _ASM_EXTABLE(2b, 3b)
5933+#endif
5934+ " .set mips0 \n"
5935+ : "=&r" (temp), "+m" (v->counter)
5936+ : "Ir" (i));
5937+ } else {
5938+ unsigned long flags;
5939+
5940+ raw_local_irq_save(flags);
5941+ __asm__ __volatile__(
5942+#ifdef CONFIG_PAX_REFCOUNT
5943+ /* Exception on overflow. */
5944+ "1: add %0, %1 \n"
5945+ "2: \n"
5946+ _ASM_EXTABLE(1b, 2b)
5947+#else
5948+ " addu %0, %1 \n"
5949+#endif
5950+ : "+r" (v->counter) : "Ir" (i));
5951+ raw_local_irq_restore(flags);
5952+ }
5953+}
5954+
5955+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5956 {
5957 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5958 int temp;
5959@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5960 *
5961 * Atomically subtracts @i from @v.
5962 */
5963-static __inline__ void atomic_sub(int i, atomic_t * v)
5964+static __inline__ void atomic_sub(int i, atomic_t *v)
5965+{
5966+ int temp;
5967+
5968+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5969+ __asm__ __volatile__(
5970+ " .set mips3 \n"
5971+ "1: ll %0, %1 # atomic64_sub \n"
5972+#ifdef CONFIG_PAX_REFCOUNT
5973+ /* Exception on overflow. */
5974+ "2: sub %0, %2 \n"
5975+#else
5976+ " subu %0, %2 \n"
5977+#endif
5978+ " sc %0, %1 \n"
5979+ " beqzl %0, 1b \n"
5980+#ifdef CONFIG_PAX_REFCOUNT
5981+ "3: \n"
5982+ _ASM_EXTABLE(2b, 3b)
5983+#endif
5984+ " .set mips0 \n"
5985+ : "=&r" (temp), "+m" (v->counter)
5986+ : "Ir" (i));
5987+ } else if (kernel_uses_llsc) {
5988+ __asm__ __volatile__(
5989+ " .set mips3 \n"
5990+ "1: ll %0, %1 # atomic64_sub \n"
5991+#ifdef CONFIG_PAX_REFCOUNT
5992+ /* Exception on overflow. */
5993+ "2: sub %0, %2 \n"
5994+#else
5995+ " subu %0, %2 \n"
5996+#endif
5997+ " sc %0, %1 \n"
5998+ " beqz %0, 1b \n"
5999+#ifdef CONFIG_PAX_REFCOUNT
6000+ "3: \n"
6001+ _ASM_EXTABLE(2b, 3b)
6002+#endif
6003+ " .set mips0 \n"
6004+ : "=&r" (temp), "+m" (v->counter)
6005+ : "Ir" (i));
6006+ } else {
6007+ unsigned long flags;
6008+
6009+ raw_local_irq_save(flags);
6010+ __asm__ __volatile__(
6011+#ifdef CONFIG_PAX_REFCOUNT
6012+ /* Exception on overflow. */
6013+ "1: sub %0, %1 \n"
6014+ "2: \n"
6015+ _ASM_EXTABLE(1b, 2b)
6016+#else
6017+ " subu %0, %1 \n"
6018+#endif
6019+ : "+r" (v->counter) : "Ir" (i));
6020+ raw_local_irq_restore(flags);
6021+ }
6022+}
6023+
6024+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
6025 {
6026 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6027 int temp;
6028@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
6029 /*
6030 * Same as above, but return the result value
6031 */
6032-static __inline__ int atomic_add_return(int i, atomic_t * v)
6033+static __inline__ int atomic_add_return(int i, atomic_t *v)
6034+{
6035+ int result;
6036+ int temp;
6037+
6038+ smp_mb__before_llsc();
6039+
6040+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6041+ __asm__ __volatile__(
6042+ " .set mips3 \n"
6043+ "1: ll %1, %2 # atomic_add_return \n"
6044+#ifdef CONFIG_PAX_REFCOUNT
6045+ "2: add %0, %1, %3 \n"
6046+#else
6047+ " addu %0, %1, %3 \n"
6048+#endif
6049+ " sc %0, %2 \n"
6050+ " beqzl %0, 1b \n"
6051+#ifdef CONFIG_PAX_REFCOUNT
6052+ " b 4f \n"
6053+ " .set noreorder \n"
6054+ "3: b 5f \n"
6055+ " move %0, %1 \n"
6056+ " .set reorder \n"
6057+ _ASM_EXTABLE(2b, 3b)
6058+#endif
6059+ "4: addu %0, %1, %3 \n"
6060+#ifdef CONFIG_PAX_REFCOUNT
6061+ "5: \n"
6062+#endif
6063+ " .set mips0 \n"
6064+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6065+ : "Ir" (i));
6066+ } else if (kernel_uses_llsc) {
6067+ __asm__ __volatile__(
6068+ " .set mips3 \n"
6069+ "1: ll %1, %2 # atomic_add_return \n"
6070+#ifdef CONFIG_PAX_REFCOUNT
6071+ "2: add %0, %1, %3 \n"
6072+#else
6073+ " addu %0, %1, %3 \n"
6074+#endif
6075+ " sc %0, %2 \n"
6076+ " bnez %0, 4f \n"
6077+ " b 1b \n"
6078+#ifdef CONFIG_PAX_REFCOUNT
6079+ " .set noreorder \n"
6080+ "3: b 5f \n"
6081+ " move %0, %1 \n"
6082+ " .set reorder \n"
6083+ _ASM_EXTABLE(2b, 3b)
6084+#endif
6085+ "4: addu %0, %1, %3 \n"
6086+#ifdef CONFIG_PAX_REFCOUNT
6087+ "5: \n"
6088+#endif
6089+ " .set mips0 \n"
6090+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6091+ : "Ir" (i));
6092+ } else {
6093+ unsigned long flags;
6094+
6095+ raw_local_irq_save(flags);
6096+ __asm__ __volatile__(
6097+ " lw %0, %1 \n"
6098+#ifdef CONFIG_PAX_REFCOUNT
6099+ /* Exception on overflow. */
6100+ "1: add %0, %2 \n"
6101+#else
6102+ " addu %0, %2 \n"
6103+#endif
6104+ " sw %0, %1 \n"
6105+#ifdef CONFIG_PAX_REFCOUNT
6106+ /* Note: Dest reg is not modified on overflow */
6107+ "2: \n"
6108+ _ASM_EXTABLE(1b, 2b)
6109+#endif
6110+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6111+ raw_local_irq_restore(flags);
6112+ }
6113+
6114+ smp_llsc_mb();
6115+
6116+ return result;
6117+}
6118+
6119+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
6120 {
6121 int result;
6122
6123@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
6124 return result;
6125 }
6126
6127-static __inline__ int atomic_sub_return(int i, atomic_t * v)
6128+static __inline__ int atomic_sub_return(int i, atomic_t *v)
6129+{
6130+ int result;
6131+ int temp;
6132+
6133+ smp_mb__before_llsc();
6134+
6135+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6136+ __asm__ __volatile__(
6137+ " .set mips3 \n"
6138+ "1: ll %1, %2 # atomic_sub_return \n"
6139+#ifdef CONFIG_PAX_REFCOUNT
6140+ "2: sub %0, %1, %3 \n"
6141+#else
6142+ " subu %0, %1, %3 \n"
6143+#endif
6144+ " sc %0, %2 \n"
6145+ " beqzl %0, 1b \n"
6146+#ifdef CONFIG_PAX_REFCOUNT
6147+ " b 4f \n"
6148+ " .set noreorder \n"
6149+ "3: b 5f \n"
6150+ " move %0, %1 \n"
6151+ " .set reorder \n"
6152+ _ASM_EXTABLE(2b, 3b)
6153+#endif
6154+ "4: subu %0, %1, %3 \n"
6155+#ifdef CONFIG_PAX_REFCOUNT
6156+ "5: \n"
6157+#endif
6158+ " .set mips0 \n"
6159+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6160+ : "Ir" (i), "m" (v->counter)
6161+ : "memory");
6162+ } else if (kernel_uses_llsc) {
6163+ __asm__ __volatile__(
6164+ " .set mips3 \n"
6165+ "1: ll %1, %2 # atomic_sub_return \n"
6166+#ifdef CONFIG_PAX_REFCOUNT
6167+ "2: sub %0, %1, %3 \n"
6168+#else
6169+ " subu %0, %1, %3 \n"
6170+#endif
6171+ " sc %0, %2 \n"
6172+ " bnez %0, 4f \n"
6173+ " b 1b \n"
6174+#ifdef CONFIG_PAX_REFCOUNT
6175+ " .set noreorder \n"
6176+ "3: b 5f \n"
6177+ " move %0, %1 \n"
6178+ " .set reorder \n"
6179+ _ASM_EXTABLE(2b, 3b)
6180+#endif
6181+ "4: subu %0, %1, %3 \n"
6182+#ifdef CONFIG_PAX_REFCOUNT
6183+ "5: \n"
6184+#endif
6185+ " .set mips0 \n"
6186+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6187+ : "Ir" (i));
6188+ } else {
6189+ unsigned long flags;
6190+
6191+ raw_local_irq_save(flags);
6192+ __asm__ __volatile__(
6193+ " lw %0, %1 \n"
6194+#ifdef CONFIG_PAX_REFCOUNT
6195+ /* Exception on overflow. */
6196+ "1: sub %0, %2 \n"
6197+#else
6198+ " subu %0, %2 \n"
6199+#endif
6200+ " sw %0, %1 \n"
6201+#ifdef CONFIG_PAX_REFCOUNT
6202+ /* Note: Dest reg is not modified on overflow */
6203+ "2: \n"
6204+ _ASM_EXTABLE(1b, 2b)
6205+#endif
6206+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6207+ raw_local_irq_restore(flags);
6208+ }
6209+
6210+ smp_llsc_mb();
6211+
6212+ return result;
6213+}
6214+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
6215 {
6216 int result;
6217
6218@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
6219 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6220 * The function returns the old value of @v minus @i.
6221 */
6222-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6223+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
6224 {
6225 int result;
6226
6227@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6228 return result;
6229 }
6230
6231-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6232-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
6233+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6234+{
6235+ return cmpxchg(&v->counter, old, new);
6236+}
6237+
6238+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
6239+ int new)
6240+{
6241+ return cmpxchg(&(v->counter), old, new);
6242+}
6243+
6244+static inline int atomic_xchg(atomic_t *v, int new)
6245+{
6246+ return xchg(&v->counter, new);
6247+}
6248+
6249+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6250+{
6251+ return xchg(&(v->counter), new);
6252+}
6253
6254 /**
6255 * __atomic_add_unless - add unless the number is a given value
6256@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6257
6258 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6259 #define atomic_inc_return(v) atomic_add_return(1, (v))
6260+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6261+{
6262+ return atomic_add_return_unchecked(1, v);
6263+}
6264
6265 /*
6266 * atomic_sub_and_test - subtract value from variable and test result
6267@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6268 * other cases.
6269 */
6270 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6271+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6272+{
6273+ return atomic_add_return_unchecked(1, v) == 0;
6274+}
6275
6276 /*
6277 * atomic_dec_and_test - decrement by 1 and test
6278@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6279 * Atomically increments @v by 1.
6280 */
6281 #define atomic_inc(v) atomic_add(1, (v))
6282+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6283+{
6284+ atomic_add_unchecked(1, v);
6285+}
6286
6287 /*
6288 * atomic_dec - decrement and test
6289@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6290 * Atomically decrements @v by 1.
6291 */
6292 #define atomic_dec(v) atomic_sub(1, (v))
6293+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6294+{
6295+ atomic_sub_unchecked(1, v);
6296+}
6297
6298 /*
6299 * atomic_add_negative - add and test if negative
6300@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6301 * @v: pointer of type atomic64_t
6302 *
6303 */
6304-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6305+static inline long atomic64_read(const atomic64_t *v)
6306+{
6307+ return (*(volatile const long *) &v->counter);
6308+}
6309+
6310+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6311+{
6312+ return (*(volatile const long *) &v->counter);
6313+}
6314
6315 /*
6316 * atomic64_set - set atomic variable
6317 * @v: pointer of type atomic64_t
6318 * @i: required value
6319 */
6320-#define atomic64_set(v, i) ((v)->counter = (i))
6321+static inline void atomic64_set(atomic64_t *v, long i)
6322+{
6323+ v->counter = i;
6324+}
6325+
6326+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6327+{
6328+ v->counter = i;
6329+}
6330
6331 /*
6332 * atomic64_add - add integer to atomic variable
6333@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6334 *
6335 * Atomically adds @i to @v.
6336 */
6337-static __inline__ void atomic64_add(long i, atomic64_t * v)
6338+static __inline__ void atomic64_add(long i, atomic64_t *v)
6339+{
6340+ long temp;
6341+
6342+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6343+ __asm__ __volatile__(
6344+ " .set mips3 \n"
6345+ "1: lld %0, %1 # atomic64_add \n"
6346+#ifdef CONFIG_PAX_REFCOUNT
6347+ /* Exception on overflow. */
6348+ "2: dadd %0, %2 \n"
6349+#else
6350+ " daddu %0, %2 \n"
6351+#endif
6352+ " scd %0, %1 \n"
6353+ " beqzl %0, 1b \n"
6354+#ifdef CONFIG_PAX_REFCOUNT
6355+ "3: \n"
6356+ _ASM_EXTABLE(2b, 3b)
6357+#endif
6358+ " .set mips0 \n"
6359+ : "=&r" (temp), "+m" (v->counter)
6360+ : "Ir" (i));
6361+ } else if (kernel_uses_llsc) {
6362+ __asm__ __volatile__(
6363+ " .set mips3 \n"
6364+ "1: lld %0, %1 # atomic64_add \n"
6365+#ifdef CONFIG_PAX_REFCOUNT
6366+ /* Exception on overflow. */
6367+ "2: dadd %0, %2 \n"
6368+#else
6369+ " daddu %0, %2 \n"
6370+#endif
6371+ " scd %0, %1 \n"
6372+ " beqz %0, 1b \n"
6373+#ifdef CONFIG_PAX_REFCOUNT
6374+ "3: \n"
6375+ _ASM_EXTABLE(2b, 3b)
6376+#endif
6377+ " .set mips0 \n"
6378+ : "=&r" (temp), "+m" (v->counter)
6379+ : "Ir" (i));
6380+ } else {
6381+ unsigned long flags;
6382+
6383+ raw_local_irq_save(flags);
6384+ __asm__ __volatile__(
6385+#ifdef CONFIG_PAX_REFCOUNT
6386+ /* Exception on overflow. */
6387+ "1: dadd %0, %1 \n"
6388+ "2: \n"
6389+ _ASM_EXTABLE(1b, 2b)
6390+#else
6391+ " daddu %0, %1 \n"
6392+#endif
6393+ : "+r" (v->counter) : "Ir" (i));
6394+ raw_local_irq_restore(flags);
6395+ }
6396+}
6397+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6398 {
6399 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6400 long temp;
6401@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6402 *
6403 * Atomically subtracts @i from @v.
6404 */
6405-static __inline__ void atomic64_sub(long i, atomic64_t * v)
6406+static __inline__ void atomic64_sub(long i, atomic64_t *v)
6407+{
6408+ long temp;
6409+
6410+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6411+ __asm__ __volatile__(
6412+ " .set mips3 \n"
6413+ "1: lld %0, %1 # atomic64_sub \n"
6414+#ifdef CONFIG_PAX_REFCOUNT
6415+ /* Exception on overflow. */
6416+ "2: dsub %0, %2 \n"
6417+#else
6418+ " dsubu %0, %2 \n"
6419+#endif
6420+ " scd %0, %1 \n"
6421+ " beqzl %0, 1b \n"
6422+#ifdef CONFIG_PAX_REFCOUNT
6423+ "3: \n"
6424+ _ASM_EXTABLE(2b, 3b)
6425+#endif
6426+ " .set mips0 \n"
6427+ : "=&r" (temp), "+m" (v->counter)
6428+ : "Ir" (i));
6429+ } else if (kernel_uses_llsc) {
6430+ __asm__ __volatile__(
6431+ " .set mips3 \n"
6432+ "1: lld %0, %1 # atomic64_sub \n"
6433+#ifdef CONFIG_PAX_REFCOUNT
6434+ /* Exception on overflow. */
6435+ "2: dsub %0, %2 \n"
6436+#else
6437+ " dsubu %0, %2 \n"
6438+#endif
6439+ " scd %0, %1 \n"
6440+ " beqz %0, 1b \n"
6441+#ifdef CONFIG_PAX_REFCOUNT
6442+ "3: \n"
6443+ _ASM_EXTABLE(2b, 3b)
6444+#endif
6445+ " .set mips0 \n"
6446+ : "=&r" (temp), "+m" (v->counter)
6447+ : "Ir" (i));
6448+ } else {
6449+ unsigned long flags;
6450+
6451+ raw_local_irq_save(flags);
6452+ __asm__ __volatile__(
6453+#ifdef CONFIG_PAX_REFCOUNT
6454+ /* Exception on overflow. */
6455+ "1: dsub %0, %1 \n"
6456+ "2: \n"
6457+ _ASM_EXTABLE(1b, 2b)
6458+#else
6459+ " dsubu %0, %1 \n"
6460+#endif
6461+ : "+r" (v->counter) : "Ir" (i));
6462+ raw_local_irq_restore(flags);
6463+ }
6464+}
6465+
6466+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6467 {
6468 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6469 long temp;
6470@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6471 /*
6472 * Same as above, but return the result value
6473 */
6474-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6475+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6476+{
6477+ long result;
6478+ long temp;
6479+
6480+ smp_mb__before_llsc();
6481+
6482+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6483+ __asm__ __volatile__(
6484+ " .set mips3 \n"
6485+ "1: lld %1, %2 # atomic64_add_return \n"
6486+#ifdef CONFIG_PAX_REFCOUNT
6487+ "2: dadd %0, %1, %3 \n"
6488+#else
6489+ " daddu %0, %1, %3 \n"
6490+#endif
6491+ " scd %0, %2 \n"
6492+ " beqzl %0, 1b \n"
6493+#ifdef CONFIG_PAX_REFCOUNT
6494+ " b 4f \n"
6495+ " .set noreorder \n"
6496+ "3: b 5f \n"
6497+ " move %0, %1 \n"
6498+ " .set reorder \n"
6499+ _ASM_EXTABLE(2b, 3b)
6500+#endif
6501+ "4: daddu %0, %1, %3 \n"
6502+#ifdef CONFIG_PAX_REFCOUNT
6503+ "5: \n"
6504+#endif
6505+ " .set mips0 \n"
6506+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6507+ : "Ir" (i));
6508+ } else if (kernel_uses_llsc) {
6509+ __asm__ __volatile__(
6510+ " .set mips3 \n"
6511+ "1: lld %1, %2 # atomic64_add_return \n"
6512+#ifdef CONFIG_PAX_REFCOUNT
6513+ "2: dadd %0, %1, %3 \n"
6514+#else
6515+ " daddu %0, %1, %3 \n"
6516+#endif
6517+ " scd %0, %2 \n"
6518+ " bnez %0, 4f \n"
6519+ " b 1b \n"
6520+#ifdef CONFIG_PAX_REFCOUNT
6521+ " .set noreorder \n"
6522+ "3: b 5f \n"
6523+ " move %0, %1 \n"
6524+ " .set reorder \n"
6525+ _ASM_EXTABLE(2b, 3b)
6526+#endif
6527+ "4: daddu %0, %1, %3 \n"
6528+#ifdef CONFIG_PAX_REFCOUNT
6529+ "5: \n"
6530+#endif
6531+ " .set mips0 \n"
6532+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6533+ : "Ir" (i), "m" (v->counter)
6534+ : "memory");
6535+ } else {
6536+ unsigned long flags;
6537+
6538+ raw_local_irq_save(flags);
6539+ __asm__ __volatile__(
6540+ " ld %0, %1 \n"
6541+#ifdef CONFIG_PAX_REFCOUNT
6542+ /* Exception on overflow. */
6543+ "1: dadd %0, %2 \n"
6544+#else
6545+ " daddu %0, %2 \n"
6546+#endif
6547+ " sd %0, %1 \n"
6548+#ifdef CONFIG_PAX_REFCOUNT
6549+ /* Note: Dest reg is not modified on overflow */
6550+ "2: \n"
6551+ _ASM_EXTABLE(1b, 2b)
6552+#endif
6553+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6554+ raw_local_irq_restore(flags);
6555+ }
6556+
6557+ smp_llsc_mb();
6558+
6559+ return result;
6560+}
6561+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6562 {
6563 long result;
6564
6565@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6566 return result;
6567 }
6568
6569-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6570+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6571+{
6572+ long result;
6573+ long temp;
6574+
6575+ smp_mb__before_llsc();
6576+
6577+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6578+ long temp;
6579+
6580+ __asm__ __volatile__(
6581+ " .set mips3 \n"
6582+ "1: lld %1, %2 # atomic64_sub_return \n"
6583+#ifdef CONFIG_PAX_REFCOUNT
6584+ "2: dsub %0, %1, %3 \n"
6585+#else
6586+ " dsubu %0, %1, %3 \n"
6587+#endif
6588+ " scd %0, %2 \n"
6589+ " beqzl %0, 1b \n"
6590+#ifdef CONFIG_PAX_REFCOUNT
6591+ " b 4f \n"
6592+ " .set noreorder \n"
6593+ "3: b 5f \n"
6594+ " move %0, %1 \n"
6595+ " .set reorder \n"
6596+ _ASM_EXTABLE(2b, 3b)
6597+#endif
6598+ "4: dsubu %0, %1, %3 \n"
6599+#ifdef CONFIG_PAX_REFCOUNT
6600+ "5: \n"
6601+#endif
6602+ " .set mips0 \n"
6603+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6604+ : "Ir" (i), "m" (v->counter)
6605+ : "memory");
6606+ } else if (kernel_uses_llsc) {
6607+ __asm__ __volatile__(
6608+ " .set mips3 \n"
6609+ "1: lld %1, %2 # atomic64_sub_return \n"
6610+#ifdef CONFIG_PAX_REFCOUNT
6611+ "2: dsub %0, %1, %3 \n"
6612+#else
6613+ " dsubu %0, %1, %3 \n"
6614+#endif
6615+ " scd %0, %2 \n"
6616+ " bnez %0, 4f \n"
6617+ " b 1b \n"
6618+#ifdef CONFIG_PAX_REFCOUNT
6619+ " .set noreorder \n"
6620+ "3: b 5f \n"
6621+ " move %0, %1 \n"
6622+ " .set reorder \n"
6623+ _ASM_EXTABLE(2b, 3b)
6624+#endif
6625+ "4: dsubu %0, %1, %3 \n"
6626+#ifdef CONFIG_PAX_REFCOUNT
6627+ "5: \n"
6628+#endif
6629+ " .set mips0 \n"
6630+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6631+ : "Ir" (i), "m" (v->counter)
6632+ : "memory");
6633+ } else {
6634+ unsigned long flags;
6635+
6636+ raw_local_irq_save(flags);
6637+ __asm__ __volatile__(
6638+ " ld %0, %1 \n"
6639+#ifdef CONFIG_PAX_REFCOUNT
6640+ /* Exception on overflow. */
6641+ "1: dsub %0, %2 \n"
6642+#else
6643+ " dsubu %0, %2 \n"
6644+#endif
6645+ " sd %0, %1 \n"
6646+#ifdef CONFIG_PAX_REFCOUNT
6647+ /* Note: Dest reg is not modified on overflow */
6648+ "2: \n"
6649+ _ASM_EXTABLE(1b, 2b)
6650+#endif
6651+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6652+ raw_local_irq_restore(flags);
6653+ }
6654+
6655+ smp_llsc_mb();
6656+
6657+ return result;
6658+}
6659+
6660+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6661 {
6662 long result;
6663
6664@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6665 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6666 * The function returns the old value of @v minus @i.
6667 */
6668-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6669+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6670 {
6671 long result;
6672
6673@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6674 return result;
6675 }
6676
6677-#define atomic64_cmpxchg(v, o, n) \
6678- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6679-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6680+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6681+{
6682+ return cmpxchg(&v->counter, old, new);
6683+}
6684+
6685+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6686+ long new)
6687+{
6688+ return cmpxchg(&(v->counter), old, new);
6689+}
6690+
6691+static inline long atomic64_xchg(atomic64_t *v, long new)
6692+{
6693+ return xchg(&v->counter, new);
6694+}
6695+
6696+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6697+{
6698+ return xchg(&(v->counter), new);
6699+}
6700
6701 /**
6702 * atomic64_add_unless - add unless the number is a given value
6703@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6704
6705 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6706 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6707+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6708
6709 /*
6710 * atomic64_sub_and_test - subtract value from variable and test result
6711@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6712 * other cases.
6713 */
6714 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6715+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6716
6717 /*
6718 * atomic64_dec_and_test - decrement by 1 and test
6719@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6720 * Atomically increments @v by 1.
6721 */
6722 #define atomic64_inc(v) atomic64_add(1, (v))
6723+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6724
6725 /*
6726 * atomic64_dec - decrement and test
6727@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6728 * Atomically decrements @v by 1.
6729 */
6730 #define atomic64_dec(v) atomic64_sub(1, (v))
6731+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6732
6733 /*
6734 * atomic64_add_negative - add and test if negative
6735diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6736index d0101dd..266982c 100644
6737--- a/arch/mips/include/asm/barrier.h
6738+++ b/arch/mips/include/asm/barrier.h
6739@@ -184,7 +184,7 @@
6740 do { \
6741 compiletime_assert_atomic_type(*p); \
6742 smp_mb(); \
6743- ACCESS_ONCE(*p) = (v); \
6744+ ACCESS_ONCE_RW(*p) = (v); \
6745 } while (0)
6746
6747 #define smp_load_acquire(p) \
6748diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6749index b4db69f..8f3b093 100644
6750--- a/arch/mips/include/asm/cache.h
6751+++ b/arch/mips/include/asm/cache.h
6752@@ -9,10 +9,11 @@
6753 #ifndef _ASM_CACHE_H
6754 #define _ASM_CACHE_H
6755
6756+#include <linux/const.h>
6757 #include <kmalloc.h>
6758
6759 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6760-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6761+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6762
6763 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6764 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6765diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6766index 1d38fe0..9beabc9 100644
6767--- a/arch/mips/include/asm/elf.h
6768+++ b/arch/mips/include/asm/elf.h
6769@@ -381,13 +381,16 @@ extern const char *__elf_platform;
6770 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6771 #endif
6772
6773+#ifdef CONFIG_PAX_ASLR
6774+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6775+
6776+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6777+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6778+#endif
6779+
6780 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6781 struct linux_binprm;
6782 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6783 int uses_interp);
6784
6785-struct mm_struct;
6786-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6787-#define arch_randomize_brk arch_randomize_brk
6788-
6789 #endif /* _ASM_ELF_H */
6790diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6791index c1f6afa..38cc6e9 100644
6792--- a/arch/mips/include/asm/exec.h
6793+++ b/arch/mips/include/asm/exec.h
6794@@ -12,6 +12,6 @@
6795 #ifndef _ASM_EXEC_H
6796 #define _ASM_EXEC_H
6797
6798-extern unsigned long arch_align_stack(unsigned long sp);
6799+#define arch_align_stack(x) ((x) & ~0xfUL)
6800
6801 #endif /* _ASM_EXEC_H */
6802diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6803index 9e8ef59..1139d6b 100644
6804--- a/arch/mips/include/asm/hw_irq.h
6805+++ b/arch/mips/include/asm/hw_irq.h
6806@@ -10,7 +10,7 @@
6807
6808 #include <linux/atomic.h>
6809
6810-extern atomic_t irq_err_count;
6811+extern atomic_unchecked_t irq_err_count;
6812
6813 /*
6814 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6815diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6816index 46dfc3c..a16b13a 100644
6817--- a/arch/mips/include/asm/local.h
6818+++ b/arch/mips/include/asm/local.h
6819@@ -12,15 +12,25 @@ typedef struct
6820 atomic_long_t a;
6821 } local_t;
6822
6823+typedef struct {
6824+ atomic_long_unchecked_t a;
6825+} local_unchecked_t;
6826+
6827 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6828
6829 #define local_read(l) atomic_long_read(&(l)->a)
6830+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6831 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6832+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6833
6834 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6835+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6836 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6837+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6838 #define local_inc(l) atomic_long_inc(&(l)->a)
6839+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6840 #define local_dec(l) atomic_long_dec(&(l)->a)
6841+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6842
6843 /*
6844 * Same as above, but return the result value
6845@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6846 return result;
6847 }
6848
6849+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6850+{
6851+ unsigned long result;
6852+
6853+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6854+ unsigned long temp;
6855+
6856+ __asm__ __volatile__(
6857+ " .set mips3 \n"
6858+ "1:" __LL "%1, %2 # local_add_return \n"
6859+ " addu %0, %1, %3 \n"
6860+ __SC "%0, %2 \n"
6861+ " beqzl %0, 1b \n"
6862+ " addu %0, %1, %3 \n"
6863+ " .set mips0 \n"
6864+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6865+ : "Ir" (i), "m" (l->a.counter)
6866+ : "memory");
6867+ } else if (kernel_uses_llsc) {
6868+ unsigned long temp;
6869+
6870+ __asm__ __volatile__(
6871+ " .set mips3 \n"
6872+ "1:" __LL "%1, %2 # local_add_return \n"
6873+ " addu %0, %1, %3 \n"
6874+ __SC "%0, %2 \n"
6875+ " beqz %0, 1b \n"
6876+ " addu %0, %1, %3 \n"
6877+ " .set mips0 \n"
6878+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6879+ : "Ir" (i), "m" (l->a.counter)
6880+ : "memory");
6881+ } else {
6882+ unsigned long flags;
6883+
6884+ local_irq_save(flags);
6885+ result = l->a.counter;
6886+ result += i;
6887+ l->a.counter = result;
6888+ local_irq_restore(flags);
6889+ }
6890+
6891+ return result;
6892+}
6893+
6894 static __inline__ long local_sub_return(long i, local_t * l)
6895 {
6896 unsigned long result;
6897@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6898
6899 #define local_cmpxchg(l, o, n) \
6900 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6901+#define local_cmpxchg_unchecked(l, o, n) \
6902+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6903 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6904
6905 /**
6906diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6907index 3be8180..c4798d5 100644
6908--- a/arch/mips/include/asm/page.h
6909+++ b/arch/mips/include/asm/page.h
6910@@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6911 #ifdef CONFIG_CPU_MIPS32
6912 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6913 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6914- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6915+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6916 #else
6917 typedef struct { unsigned long long pte; } pte_t;
6918 #define pte_val(x) ((x).pte)
6919diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6920index b336037..5b874cc 100644
6921--- a/arch/mips/include/asm/pgalloc.h
6922+++ b/arch/mips/include/asm/pgalloc.h
6923@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6924 {
6925 set_pud(pud, __pud((unsigned long)pmd));
6926 }
6927+
6928+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6929+{
6930+ pud_populate(mm, pud, pmd);
6931+}
6932 #endif
6933
6934 /*
6935diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6936index df49a30..c0d3dd6 100644
6937--- a/arch/mips/include/asm/pgtable.h
6938+++ b/arch/mips/include/asm/pgtable.h
6939@@ -20,6 +20,9 @@
6940 #include <asm/io.h>
6941 #include <asm/pgtable-bits.h>
6942
6943+#define ktla_ktva(addr) (addr)
6944+#define ktva_ktla(addr) (addr)
6945+
6946 struct mm_struct;
6947 struct vm_area_struct;
6948
6949diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6950index 7de8658..c109224 100644
6951--- a/arch/mips/include/asm/thread_info.h
6952+++ b/arch/mips/include/asm/thread_info.h
6953@@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6954 #define TIF_SECCOMP 4 /* secure computing */
6955 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6956 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6957+/* li takes a 32bit immediate */
6958+#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6959+
6960 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6961 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6962 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6963@@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6964 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6965 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6966 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6967+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6968
6969 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6970 _TIF_SYSCALL_AUDIT | \
6971- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6972+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6973+ _TIF_GRSEC_SETXID)
6974
6975 /* work to do in syscall_trace_leave() */
6976 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6977- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6978+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6979
6980 /* work to do on interrupt/exception return */
6981 #define _TIF_WORK_MASK \
6982@@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6983 /* work to do on any return to u-space */
6984 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6985 _TIF_WORK_SYSCALL_EXIT | \
6986- _TIF_SYSCALL_TRACEPOINT)
6987+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6988
6989 /*
6990 * We stash processor id into a COP0 register to retrieve it fast
6991diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6992index a109510..94ee3f6 100644
6993--- a/arch/mips/include/asm/uaccess.h
6994+++ b/arch/mips/include/asm/uaccess.h
6995@@ -130,6 +130,7 @@ extern u64 __ua_limit;
6996 __ok == 0; \
6997 })
6998
6999+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
7000 #define access_ok(type, addr, size) \
7001 likely(__access_ok((addr), (size), __access_mask))
7002
7003diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
7004index 1188e00..41cf144 100644
7005--- a/arch/mips/kernel/binfmt_elfn32.c
7006+++ b/arch/mips/kernel/binfmt_elfn32.c
7007@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
7008 #undef ELF_ET_DYN_BASE
7009 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
7010
7011+#ifdef CONFIG_PAX_ASLR
7012+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7013+
7014+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7015+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7016+#endif
7017+
7018 #include <asm/processor.h>
7019 #include <linux/module.h>
7020 #include <linux/elfcore.h>
7021diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
7022index 9287678..f870e47 100644
7023--- a/arch/mips/kernel/binfmt_elfo32.c
7024+++ b/arch/mips/kernel/binfmt_elfo32.c
7025@@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
7026 #undef ELF_ET_DYN_BASE
7027 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
7028
7029+#ifdef CONFIG_PAX_ASLR
7030+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
7031+
7032+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7033+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
7034+#endif
7035+
7036 #include <asm/processor.h>
7037
7038 #include <linux/module.h>
7039diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
7040index 50b3648..c2f3cec 100644
7041--- a/arch/mips/kernel/i8259.c
7042+++ b/arch/mips/kernel/i8259.c
7043@@ -201,7 +201,7 @@ spurious_8259A_irq:
7044 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
7045 spurious_irq_mask |= irqmask;
7046 }
7047- atomic_inc(&irq_err_count);
7048+ atomic_inc_unchecked(&irq_err_count);
7049 /*
7050 * Theoretically we do not have to handle this IRQ,
7051 * but in Linux this does not cause problems and is
7052diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
7053index 44a1f79..2bd6aa3 100644
7054--- a/arch/mips/kernel/irq-gt641xx.c
7055+++ b/arch/mips/kernel/irq-gt641xx.c
7056@@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
7057 }
7058 }
7059
7060- atomic_inc(&irq_err_count);
7061+ atomic_inc_unchecked(&irq_err_count);
7062 }
7063
7064 void __init gt641xx_irq_init(void)
7065diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
7066index d2bfbc2..a8eacd2 100644
7067--- a/arch/mips/kernel/irq.c
7068+++ b/arch/mips/kernel/irq.c
7069@@ -76,17 +76,17 @@ void ack_bad_irq(unsigned int irq)
7070 printk("unexpected IRQ # %d\n", irq);
7071 }
7072
7073-atomic_t irq_err_count;
7074+atomic_unchecked_t irq_err_count;
7075
7076 int arch_show_interrupts(struct seq_file *p, int prec)
7077 {
7078- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
7079+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
7080 return 0;
7081 }
7082
7083 asmlinkage void spurious_interrupt(void)
7084 {
7085- atomic_inc(&irq_err_count);
7086+ atomic_inc_unchecked(&irq_err_count);
7087 }
7088
7089 void __init init_IRQ(void)
7090@@ -109,7 +109,10 @@ void __init init_IRQ(void)
7091 #endif
7092 }
7093
7094+
7095 #ifdef DEBUG_STACKOVERFLOW
7096+extern void gr_handle_kernel_exploit(void);
7097+
7098 static inline void check_stack_overflow(void)
7099 {
7100 unsigned long sp;
7101@@ -125,6 +128,7 @@ static inline void check_stack_overflow(void)
7102 printk("do_IRQ: stack overflow: %ld\n",
7103 sp - sizeof(struct thread_info));
7104 dump_stack();
7105+ gr_handle_kernel_exploit();
7106 }
7107 }
7108 #else
7109diff --git a/arch/mips/kernel/pm-cps.c b/arch/mips/kernel/pm-cps.c
7110index 0614717..002fa43 100644
7111--- a/arch/mips/kernel/pm-cps.c
7112+++ b/arch/mips/kernel/pm-cps.c
7113@@ -172,7 +172,7 @@ int cps_pm_enter_state(enum cps_pm_state state)
7114 nc_core_ready_count = nc_addr;
7115
7116 /* Ensure ready_count is zero-initialised before the assembly runs */
7117- ACCESS_ONCE(*nc_core_ready_count) = 0;
7118+ ACCESS_ONCE_RW(*nc_core_ready_count) = 0;
7119 coupled_barrier(&per_cpu(pm_barrier, core), online);
7120
7121 /* Run the generated entry code */
7122diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
7123index 636b074..8fbb91f 100644
7124--- a/arch/mips/kernel/process.c
7125+++ b/arch/mips/kernel/process.c
7126@@ -520,15 +520,3 @@ unsigned long get_wchan(struct task_struct *task)
7127 out:
7128 return pc;
7129 }
7130-
7131-/*
7132- * Don't forget that the stack pointer must be aligned on a 8 bytes
7133- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
7134- */
7135-unsigned long arch_align_stack(unsigned long sp)
7136-{
7137- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7138- sp -= get_random_int() & ~PAGE_MASK;
7139-
7140- return sp & ALMASK;
7141-}
7142diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
7143index 645b3c4..909c75a 100644
7144--- a/arch/mips/kernel/ptrace.c
7145+++ b/arch/mips/kernel/ptrace.c
7146@@ -761,6 +761,10 @@ long arch_ptrace(struct task_struct *child, long request,
7147 return ret;
7148 }
7149
7150+#ifdef CONFIG_GRKERNSEC_SETXID
7151+extern void gr_delayed_cred_worker(void);
7152+#endif
7153+
7154 /*
7155 * Notification of system call entry/exit
7156 * - triggered by current->work.syscall_trace
7157@@ -777,6 +781,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
7158 tracehook_report_syscall_entry(regs))
7159 ret = -1;
7160
7161+#ifdef CONFIG_GRKERNSEC_SETXID
7162+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
7163+ gr_delayed_cred_worker();
7164+#endif
7165+
7166 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
7167 trace_sys_enter(regs, regs->regs[2]);
7168
7169diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
7170index 07fc524..b9d7f28 100644
7171--- a/arch/mips/kernel/reset.c
7172+++ b/arch/mips/kernel/reset.c
7173@@ -13,6 +13,7 @@
7174 #include <linux/reboot.h>
7175
7176 #include <asm/reboot.h>
7177+#include <asm/bug.h>
7178
7179 /*
7180 * Urgs ... Too many MIPS machines to handle this in a generic way.
7181@@ -29,16 +30,19 @@ void machine_restart(char *command)
7182 {
7183 if (_machine_restart)
7184 _machine_restart(command);
7185+ BUG();
7186 }
7187
7188 void machine_halt(void)
7189 {
7190 if (_machine_halt)
7191 _machine_halt();
7192+ BUG();
7193 }
7194
7195 void machine_power_off(void)
7196 {
7197 if (pm_power_off)
7198 pm_power_off();
7199+ BUG();
7200 }
7201diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
7202index 2242bdd..b284048 100644
7203--- a/arch/mips/kernel/sync-r4k.c
7204+++ b/arch/mips/kernel/sync-r4k.c
7205@@ -18,8 +18,8 @@
7206 #include <asm/mipsregs.h>
7207
7208 static atomic_t count_start_flag = ATOMIC_INIT(0);
7209-static atomic_t count_count_start = ATOMIC_INIT(0);
7210-static atomic_t count_count_stop = ATOMIC_INIT(0);
7211+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
7212+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
7213 static atomic_t count_reference = ATOMIC_INIT(0);
7214
7215 #define COUNTON 100
7216@@ -58,13 +58,13 @@ void synchronise_count_master(int cpu)
7217
7218 for (i = 0; i < NR_LOOPS; i++) {
7219 /* slaves loop on '!= 2' */
7220- while (atomic_read(&count_count_start) != 1)
7221+ while (atomic_read_unchecked(&count_count_start) != 1)
7222 mb();
7223- atomic_set(&count_count_stop, 0);
7224+ atomic_set_unchecked(&count_count_stop, 0);
7225 smp_wmb();
7226
7227 /* this lets the slaves write their count register */
7228- atomic_inc(&count_count_start);
7229+ atomic_inc_unchecked(&count_count_start);
7230
7231 /*
7232 * Everyone initialises count in the last loop:
7233@@ -75,11 +75,11 @@ void synchronise_count_master(int cpu)
7234 /*
7235 * Wait for all slaves to leave the synchronization point:
7236 */
7237- while (atomic_read(&count_count_stop) != 1)
7238+ while (atomic_read_unchecked(&count_count_stop) != 1)
7239 mb();
7240- atomic_set(&count_count_start, 0);
7241+ atomic_set_unchecked(&count_count_start, 0);
7242 smp_wmb();
7243- atomic_inc(&count_count_stop);
7244+ atomic_inc_unchecked(&count_count_stop);
7245 }
7246 /* Arrange for an interrupt in a short while */
7247 write_c0_compare(read_c0_count() + COUNTON);
7248@@ -112,8 +112,8 @@ void synchronise_count_slave(int cpu)
7249 initcount = atomic_read(&count_reference);
7250
7251 for (i = 0; i < NR_LOOPS; i++) {
7252- atomic_inc(&count_count_start);
7253- while (atomic_read(&count_count_start) != 2)
7254+ atomic_inc_unchecked(&count_count_start);
7255+ while (atomic_read_unchecked(&count_count_start) != 2)
7256 mb();
7257
7258 /*
7259@@ -122,8 +122,8 @@ void synchronise_count_slave(int cpu)
7260 if (i == NR_LOOPS-1)
7261 write_c0_count(initcount);
7262
7263- atomic_inc(&count_count_stop);
7264- while (atomic_read(&count_count_stop) != 2)
7265+ atomic_inc_unchecked(&count_count_stop);
7266+ while (atomic_read_unchecked(&count_count_stop) != 2)
7267 mb();
7268 }
7269 /* Arrange for an interrupt in a short while */
7270diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7271index 22b19c2..c5cc8c4 100644
7272--- a/arch/mips/kernel/traps.c
7273+++ b/arch/mips/kernel/traps.c
7274@@ -688,7 +688,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7275 siginfo_t info;
7276
7277 prev_state = exception_enter();
7278- die_if_kernel("Integer overflow", regs);
7279+ if (unlikely(!user_mode(regs))) {
7280+
7281+#ifdef CONFIG_PAX_REFCOUNT
7282+ if (fixup_exception(regs)) {
7283+ pax_report_refcount_overflow(regs);
7284+ exception_exit(prev_state);
7285+ return;
7286+ }
7287+#endif
7288+
7289+ die("Integer overflow", regs);
7290+ }
7291
7292 info.si_code = FPE_INTOVF;
7293 info.si_signo = SIGFPE;
7294diff --git a/arch/mips/kvm/mips.c b/arch/mips/kvm/mips.c
7295index cd71141..e02c4df 100644
7296--- a/arch/mips/kvm/mips.c
7297+++ b/arch/mips/kvm/mips.c
7298@@ -839,7 +839,7 @@ long kvm_arch_vm_ioctl(struct file *filp, unsigned int ioctl, unsigned long arg)
7299 return r;
7300 }
7301
7302-int kvm_arch_init(void *opaque)
7303+int kvm_arch_init(const void *opaque)
7304 {
7305 if (kvm_mips_callbacks) {
7306 kvm_err("kvm: module already exists\n");
7307diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7308index becc42b..9e43d4b 100644
7309--- a/arch/mips/mm/fault.c
7310+++ b/arch/mips/mm/fault.c
7311@@ -28,6 +28,23 @@
7312 #include <asm/highmem.h> /* For VMALLOC_END */
7313 #include <linux/kdebug.h>
7314
7315+#ifdef CONFIG_PAX_PAGEEXEC
7316+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7317+{
7318+ unsigned long i;
7319+
7320+ printk(KERN_ERR "PAX: bytes at PC: ");
7321+ for (i = 0; i < 5; i++) {
7322+ unsigned int c;
7323+ if (get_user(c, (unsigned int *)pc+i))
7324+ printk(KERN_CONT "???????? ");
7325+ else
7326+ printk(KERN_CONT "%08x ", c);
7327+ }
7328+ printk("\n");
7329+}
7330+#endif
7331+
7332 /*
7333 * This routine handles page faults. It determines the address,
7334 * and the problem, and then passes it off to one of the appropriate
7335@@ -199,6 +216,14 @@ bad_area:
7336 bad_area_nosemaphore:
7337 /* User mode accesses just cause a SIGSEGV */
7338 if (user_mode(regs)) {
7339+
7340+#ifdef CONFIG_PAX_PAGEEXEC
7341+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7342+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7343+ do_group_exit(SIGKILL);
7344+ }
7345+#endif
7346+
7347 tsk->thread.cp0_badvaddr = address;
7348 tsk->thread.error_code = write;
7349 #if 0
7350diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7351index f1baadd..5472dca 100644
7352--- a/arch/mips/mm/mmap.c
7353+++ b/arch/mips/mm/mmap.c
7354@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7355 struct vm_area_struct *vma;
7356 unsigned long addr = addr0;
7357 int do_color_align;
7358+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7359 struct vm_unmapped_area_info info;
7360
7361 if (unlikely(len > TASK_SIZE))
7362@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7363 do_color_align = 1;
7364
7365 /* requesting a specific address */
7366+
7367+#ifdef CONFIG_PAX_RANDMMAP
7368+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7369+#endif
7370+
7371 if (addr) {
7372 if (do_color_align)
7373 addr = COLOUR_ALIGN(addr, pgoff);
7374@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7375 addr = PAGE_ALIGN(addr);
7376
7377 vma = find_vma(mm, addr);
7378- if (TASK_SIZE - len >= addr &&
7379- (!vma || addr + len <= vma->vm_start))
7380+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7381 return addr;
7382 }
7383
7384 info.length = len;
7385 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7386 info.align_offset = pgoff << PAGE_SHIFT;
7387+ info.threadstack_offset = offset;
7388
7389 if (dir == DOWN) {
7390 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7391@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7392 {
7393 unsigned long random_factor = 0UL;
7394
7395+#ifdef CONFIG_PAX_RANDMMAP
7396+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7397+#endif
7398+
7399 if (current->flags & PF_RANDOMIZE) {
7400 random_factor = get_random_int();
7401 random_factor = random_factor << PAGE_SHIFT;
7402@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7403
7404 if (mmap_is_legacy()) {
7405 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7406+
7407+#ifdef CONFIG_PAX_RANDMMAP
7408+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7409+ mm->mmap_base += mm->delta_mmap;
7410+#endif
7411+
7412 mm->get_unmapped_area = arch_get_unmapped_area;
7413 } else {
7414 mm->mmap_base = mmap_base(random_factor);
7415+
7416+#ifdef CONFIG_PAX_RANDMMAP
7417+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7418+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7419+#endif
7420+
7421 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7422 }
7423 }
7424
7425-static inline unsigned long brk_rnd(void)
7426-{
7427- unsigned long rnd = get_random_int();
7428-
7429- rnd = rnd << PAGE_SHIFT;
7430- /* 8MB for 32bit, 256MB for 64bit */
7431- if (TASK_IS_32BIT_ADDR)
7432- rnd = rnd & 0x7ffffful;
7433- else
7434- rnd = rnd & 0xffffffful;
7435-
7436- return rnd;
7437-}
7438-
7439-unsigned long arch_randomize_brk(struct mm_struct *mm)
7440-{
7441- unsigned long base = mm->brk;
7442- unsigned long ret;
7443-
7444- ret = PAGE_ALIGN(base + brk_rnd());
7445-
7446- if (ret < mm->brk)
7447- return mm->brk;
7448-
7449- return ret;
7450-}
7451-
7452 int __virt_addr_valid(const volatile void *kaddr)
7453 {
7454 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7455diff --git a/arch/mips/net/bpf_jit.c b/arch/mips/net/bpf_jit.c
7456index 9f7ecbd..6e370fc 100644
7457--- a/arch/mips/net/bpf_jit.c
7458+++ b/arch/mips/net/bpf_jit.c
7459@@ -1428,5 +1428,6 @@ void bpf_jit_free(struct bpf_prog *fp)
7460 {
7461 if (fp->jited)
7462 module_free(NULL, fp->bpf_func);
7463- kfree(fp);
7464+
7465+ bpf_prog_unlock_free(fp);
7466 }
7467diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7468index 59cccd9..f39ac2f 100644
7469--- a/arch/mips/pci/pci-octeon.c
7470+++ b/arch/mips/pci/pci-octeon.c
7471@@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7472
7473
7474 static struct pci_ops octeon_pci_ops = {
7475- octeon_read_config,
7476- octeon_write_config,
7477+ .read = octeon_read_config,
7478+ .write = octeon_write_config,
7479 };
7480
7481 static struct resource octeon_pci_mem_resource = {
7482diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7483index 5e36c33..eb4a17b 100644
7484--- a/arch/mips/pci/pcie-octeon.c
7485+++ b/arch/mips/pci/pcie-octeon.c
7486@@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7487 }
7488
7489 static struct pci_ops octeon_pcie0_ops = {
7490- octeon_pcie0_read_config,
7491- octeon_pcie0_write_config,
7492+ .read = octeon_pcie0_read_config,
7493+ .write = octeon_pcie0_write_config,
7494 };
7495
7496 static struct resource octeon_pcie0_mem_resource = {
7497@@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7498 };
7499
7500 static struct pci_ops octeon_pcie1_ops = {
7501- octeon_pcie1_read_config,
7502- octeon_pcie1_write_config,
7503+ .read = octeon_pcie1_read_config,
7504+ .write = octeon_pcie1_write_config,
7505 };
7506
7507 static struct resource octeon_pcie1_mem_resource = {
7508@@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7509 };
7510
7511 static struct pci_ops octeon_dummy_ops = {
7512- octeon_dummy_read_config,
7513- octeon_dummy_write_config,
7514+ .read = octeon_dummy_read_config,
7515+ .write = octeon_dummy_write_config,
7516 };
7517
7518 static struct resource octeon_dummy_mem_resource = {
7519diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7520index a2358b4..7cead4f 100644
7521--- a/arch/mips/sgi-ip27/ip27-nmi.c
7522+++ b/arch/mips/sgi-ip27/ip27-nmi.c
7523@@ -187,9 +187,9 @@ void
7524 cont_nmi_dump(void)
7525 {
7526 #ifndef REAL_NMI_SIGNAL
7527- static atomic_t nmied_cpus = ATOMIC_INIT(0);
7528+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7529
7530- atomic_inc(&nmied_cpus);
7531+ atomic_inc_unchecked(&nmied_cpus);
7532 #endif
7533 /*
7534 * Only allow 1 cpu to proceed
7535@@ -233,7 +233,7 @@ cont_nmi_dump(void)
7536 udelay(10000);
7537 }
7538 #else
7539- while (atomic_read(&nmied_cpus) != num_online_cpus());
7540+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7541 #endif
7542
7543 /*
7544diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7545index a046b30..6799527 100644
7546--- a/arch/mips/sni/rm200.c
7547+++ b/arch/mips/sni/rm200.c
7548@@ -270,7 +270,7 @@ spurious_8259A_irq:
7549 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7550 spurious_irq_mask |= irqmask;
7551 }
7552- atomic_inc(&irq_err_count);
7553+ atomic_inc_unchecked(&irq_err_count);
7554 /*
7555 * Theoretically we do not have to handle this IRQ,
7556 * but in Linux this does not cause problems and is
7557diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7558index 41e873b..34d33a7 100644
7559--- a/arch/mips/vr41xx/common/icu.c
7560+++ b/arch/mips/vr41xx/common/icu.c
7561@@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7562
7563 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7564
7565- atomic_inc(&irq_err_count);
7566+ atomic_inc_unchecked(&irq_err_count);
7567
7568 return -1;
7569 }
7570diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7571index ae0e4ee..e8f0692 100644
7572--- a/arch/mips/vr41xx/common/irq.c
7573+++ b/arch/mips/vr41xx/common/irq.c
7574@@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7575 irq_cascade_t *cascade;
7576
7577 if (irq >= NR_IRQS) {
7578- atomic_inc(&irq_err_count);
7579+ atomic_inc_unchecked(&irq_err_count);
7580 return;
7581 }
7582
7583@@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7584 ret = cascade->get_irq(irq);
7585 irq = ret;
7586 if (ret < 0)
7587- atomic_inc(&irq_err_count);
7588+ atomic_inc_unchecked(&irq_err_count);
7589 else
7590 irq_dispatch(irq);
7591 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7592diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7593index 967d144..db12197 100644
7594--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7595+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7596@@ -11,12 +11,14 @@
7597 #ifndef _ASM_PROC_CACHE_H
7598 #define _ASM_PROC_CACHE_H
7599
7600+#include <linux/const.h>
7601+
7602 /* L1 cache */
7603
7604 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7605 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7606-#define L1_CACHE_BYTES 16 /* bytes per entry */
7607 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7608+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7609 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7610
7611 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7612diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7613index bcb5df2..84fabd2 100644
7614--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7615+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7616@@ -16,13 +16,15 @@
7617 #ifndef _ASM_PROC_CACHE_H
7618 #define _ASM_PROC_CACHE_H
7619
7620+#include <linux/const.h>
7621+
7622 /*
7623 * L1 cache
7624 */
7625 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7626 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7627-#define L1_CACHE_BYTES 32 /* bytes per entry */
7628 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7629+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7630 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7631
7632 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7633diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7634index 4ce7a01..449202a 100644
7635--- a/arch/openrisc/include/asm/cache.h
7636+++ b/arch/openrisc/include/asm/cache.h
7637@@ -19,11 +19,13 @@
7638 #ifndef __ASM_OPENRISC_CACHE_H
7639 #define __ASM_OPENRISC_CACHE_H
7640
7641+#include <linux/const.h>
7642+
7643 /* FIXME: How can we replace these with values from the CPU...
7644 * they shouldn't be hard-coded!
7645 */
7646
7647-#define L1_CACHE_BYTES 16
7648 #define L1_CACHE_SHIFT 4
7649+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7650
7651 #endif /* __ASM_OPENRISC_CACHE_H */
7652diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7653index 0be2db2..1b0f26d 100644
7654--- a/arch/parisc/include/asm/atomic.h
7655+++ b/arch/parisc/include/asm/atomic.h
7656@@ -248,6 +248,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7657 return dec;
7658 }
7659
7660+#define atomic64_read_unchecked(v) atomic64_read(v)
7661+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7662+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7663+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7664+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7665+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7666+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7667+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7668+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7669+
7670 #endif /* !CONFIG_64BIT */
7671
7672
7673diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7674index 47f11c7..3420df2 100644
7675--- a/arch/parisc/include/asm/cache.h
7676+++ b/arch/parisc/include/asm/cache.h
7677@@ -5,6 +5,7 @@
7678 #ifndef __ARCH_PARISC_CACHE_H
7679 #define __ARCH_PARISC_CACHE_H
7680
7681+#include <linux/const.h>
7682
7683 /*
7684 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7685@@ -15,13 +16,13 @@
7686 * just ruin performance.
7687 */
7688 #ifdef CONFIG_PA20
7689-#define L1_CACHE_BYTES 64
7690 #define L1_CACHE_SHIFT 6
7691 #else
7692-#define L1_CACHE_BYTES 32
7693 #define L1_CACHE_SHIFT 5
7694 #endif
7695
7696+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7697+
7698 #ifndef __ASSEMBLY__
7699
7700 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7701diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7702index 3391d06..c23a2cc 100644
7703--- a/arch/parisc/include/asm/elf.h
7704+++ b/arch/parisc/include/asm/elf.h
7705@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7706
7707 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7708
7709+#ifdef CONFIG_PAX_ASLR
7710+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7711+
7712+#define PAX_DELTA_MMAP_LEN 16
7713+#define PAX_DELTA_STACK_LEN 16
7714+#endif
7715+
7716 /* This yields a mask that user programs can use to figure out what
7717 instruction set this CPU supports. This could be done in user space,
7718 but it's not easy, and we've already done it here. */
7719diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7720index f213f5b..0af3e8e 100644
7721--- a/arch/parisc/include/asm/pgalloc.h
7722+++ b/arch/parisc/include/asm/pgalloc.h
7723@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7724 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7725 }
7726
7727+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7728+{
7729+ pgd_populate(mm, pgd, pmd);
7730+}
7731+
7732 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7733 {
7734 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7735@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7736 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7737 #define pmd_free(mm, x) do { } while (0)
7738 #define pgd_populate(mm, pmd, pte) BUG()
7739+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7740
7741 #endif
7742
7743diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7744index 22b89d1..ce34230 100644
7745--- a/arch/parisc/include/asm/pgtable.h
7746+++ b/arch/parisc/include/asm/pgtable.h
7747@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7748 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7749 #define PAGE_COPY PAGE_EXECREAD
7750 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7751+
7752+#ifdef CONFIG_PAX_PAGEEXEC
7753+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7754+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7755+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7756+#else
7757+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7758+# define PAGE_COPY_NOEXEC PAGE_COPY
7759+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7760+#endif
7761+
7762 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7763 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7764 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7765diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7766index 4006964..fcb3cc2 100644
7767--- a/arch/parisc/include/asm/uaccess.h
7768+++ b/arch/parisc/include/asm/uaccess.h
7769@@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7770 const void __user *from,
7771 unsigned long n)
7772 {
7773- int sz = __compiletime_object_size(to);
7774+ size_t sz = __compiletime_object_size(to);
7775 int ret = -EFAULT;
7776
7777- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7778+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7779 ret = __copy_from_user(to, from, n);
7780 else
7781 copy_from_user_overflow();
7782diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7783index 50dfafc..b9fc230 100644
7784--- a/arch/parisc/kernel/module.c
7785+++ b/arch/parisc/kernel/module.c
7786@@ -98,16 +98,38 @@
7787
7788 /* three functions to determine where in the module core
7789 * or init pieces the location is */
7790+static inline int in_init_rx(struct module *me, void *loc)
7791+{
7792+ return (loc >= me->module_init_rx &&
7793+ loc < (me->module_init_rx + me->init_size_rx));
7794+}
7795+
7796+static inline int in_init_rw(struct module *me, void *loc)
7797+{
7798+ return (loc >= me->module_init_rw &&
7799+ loc < (me->module_init_rw + me->init_size_rw));
7800+}
7801+
7802 static inline int in_init(struct module *me, void *loc)
7803 {
7804- return (loc >= me->module_init &&
7805- loc <= (me->module_init + me->init_size));
7806+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7807+}
7808+
7809+static inline int in_core_rx(struct module *me, void *loc)
7810+{
7811+ return (loc >= me->module_core_rx &&
7812+ loc < (me->module_core_rx + me->core_size_rx));
7813+}
7814+
7815+static inline int in_core_rw(struct module *me, void *loc)
7816+{
7817+ return (loc >= me->module_core_rw &&
7818+ loc < (me->module_core_rw + me->core_size_rw));
7819 }
7820
7821 static inline int in_core(struct module *me, void *loc)
7822 {
7823- return (loc >= me->module_core &&
7824- loc <= (me->module_core + me->core_size));
7825+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7826 }
7827
7828 static inline int in_local(struct module *me, void *loc)
7829@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7830 }
7831
7832 /* align things a bit */
7833- me->core_size = ALIGN(me->core_size, 16);
7834- me->arch.got_offset = me->core_size;
7835- me->core_size += gots * sizeof(struct got_entry);
7836+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7837+ me->arch.got_offset = me->core_size_rw;
7838+ me->core_size_rw += gots * sizeof(struct got_entry);
7839
7840- me->core_size = ALIGN(me->core_size, 16);
7841- me->arch.fdesc_offset = me->core_size;
7842- me->core_size += fdescs * sizeof(Elf_Fdesc);
7843+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7844+ me->arch.fdesc_offset = me->core_size_rw;
7845+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7846
7847 me->arch.got_max = gots;
7848 me->arch.fdesc_max = fdescs;
7849@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7850
7851 BUG_ON(value == 0);
7852
7853- got = me->module_core + me->arch.got_offset;
7854+ got = me->module_core_rw + me->arch.got_offset;
7855 for (i = 0; got[i].addr; i++)
7856 if (got[i].addr == value)
7857 goto out;
7858@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7859 #ifdef CONFIG_64BIT
7860 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7861 {
7862- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7863+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7864
7865 if (!value) {
7866 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7867@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7868
7869 /* Create new one */
7870 fdesc->addr = value;
7871- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7872+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7873 return (Elf_Addr)fdesc;
7874 }
7875 #endif /* CONFIG_64BIT */
7876@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7877
7878 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7879 end = table + sechdrs[me->arch.unwind_section].sh_size;
7880- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7881+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7882
7883 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7884 me->arch.unwind_section, table, end, gp);
7885diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7886index e1ffea2..46ed66e 100644
7887--- a/arch/parisc/kernel/sys_parisc.c
7888+++ b/arch/parisc/kernel/sys_parisc.c
7889@@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7890 unsigned long task_size = TASK_SIZE;
7891 int do_color_align, last_mmap;
7892 struct vm_unmapped_area_info info;
7893+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7894
7895 if (len > task_size)
7896 return -ENOMEM;
7897@@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7898 goto found_addr;
7899 }
7900
7901+#ifdef CONFIG_PAX_RANDMMAP
7902+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7903+#endif
7904+
7905 if (addr) {
7906 if (do_color_align && last_mmap)
7907 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7908@@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7909 info.high_limit = mmap_upper_limit();
7910 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7911 info.align_offset = shared_align_offset(last_mmap, pgoff);
7912+ info.threadstack_offset = offset;
7913 addr = vm_unmapped_area(&info);
7914
7915 found_addr:
7916@@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7917 unsigned long addr = addr0;
7918 int do_color_align, last_mmap;
7919 struct vm_unmapped_area_info info;
7920+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7921
7922 #ifdef CONFIG_64BIT
7923 /* This should only ever run for 32-bit processes. */
7924@@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7925 }
7926
7927 /* requesting a specific address */
7928+#ifdef CONFIG_PAX_RANDMMAP
7929+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7930+#endif
7931+
7932 if (addr) {
7933 if (do_color_align && last_mmap)
7934 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7935@@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7936 info.high_limit = mm->mmap_base;
7937 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7938 info.align_offset = shared_align_offset(last_mmap, pgoff);
7939+ info.threadstack_offset = offset;
7940 addr = vm_unmapped_area(&info);
7941 if (!(addr & ~PAGE_MASK))
7942 goto found_addr;
7943@@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7944 mm->mmap_legacy_base = mmap_legacy_base();
7945 mm->mmap_base = mmap_upper_limit();
7946
7947+#ifdef CONFIG_PAX_RANDMMAP
7948+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
7949+ mm->mmap_legacy_base += mm->delta_mmap;
7950+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7951+ }
7952+#endif
7953+
7954 if (mmap_is_legacy()) {
7955 mm->mmap_base = mm->mmap_legacy_base;
7956 mm->get_unmapped_area = arch_get_unmapped_area;
7957diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7958index 47ee620..1107387 100644
7959--- a/arch/parisc/kernel/traps.c
7960+++ b/arch/parisc/kernel/traps.c
7961@@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7962
7963 down_read(&current->mm->mmap_sem);
7964 vma = find_vma(current->mm,regs->iaoq[0]);
7965- if (vma && (regs->iaoq[0] >= vma->vm_start)
7966- && (vma->vm_flags & VM_EXEC)) {
7967-
7968+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7969 fault_address = regs->iaoq[0];
7970 fault_space = regs->iasq[0];
7971
7972diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7973index 3ca9c11..d163ef7 100644
7974--- a/arch/parisc/mm/fault.c
7975+++ b/arch/parisc/mm/fault.c
7976@@ -15,6 +15,7 @@
7977 #include <linux/sched.h>
7978 #include <linux/interrupt.h>
7979 #include <linux/module.h>
7980+#include <linux/unistd.h>
7981
7982 #include <asm/uaccess.h>
7983 #include <asm/traps.h>
7984@@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7985 static unsigned long
7986 parisc_acctyp(unsigned long code, unsigned int inst)
7987 {
7988- if (code == 6 || code == 16)
7989+ if (code == 6 || code == 7 || code == 16)
7990 return VM_EXEC;
7991
7992 switch (inst & 0xf0000000) {
7993@@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7994 }
7995 #endif
7996
7997+#ifdef CONFIG_PAX_PAGEEXEC
7998+/*
7999+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
8000+ *
8001+ * returns 1 when task should be killed
8002+ * 2 when rt_sigreturn trampoline was detected
8003+ * 3 when unpatched PLT trampoline was detected
8004+ */
8005+static int pax_handle_fetch_fault(struct pt_regs *regs)
8006+{
8007+
8008+#ifdef CONFIG_PAX_EMUPLT
8009+ int err;
8010+
8011+ do { /* PaX: unpatched PLT emulation */
8012+ unsigned int bl, depwi;
8013+
8014+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
8015+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
8016+
8017+ if (err)
8018+ break;
8019+
8020+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
8021+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
8022+
8023+ err = get_user(ldw, (unsigned int *)addr);
8024+ err |= get_user(bv, (unsigned int *)(addr+4));
8025+ err |= get_user(ldw2, (unsigned int *)(addr+8));
8026+
8027+ if (err)
8028+ break;
8029+
8030+ if (ldw == 0x0E801096U &&
8031+ bv == 0xEAC0C000U &&
8032+ ldw2 == 0x0E881095U)
8033+ {
8034+ unsigned int resolver, map;
8035+
8036+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
8037+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
8038+ if (err)
8039+ break;
8040+
8041+ regs->gr[20] = instruction_pointer(regs)+8;
8042+ regs->gr[21] = map;
8043+ regs->gr[22] = resolver;
8044+ regs->iaoq[0] = resolver | 3UL;
8045+ regs->iaoq[1] = regs->iaoq[0] + 4;
8046+ return 3;
8047+ }
8048+ }
8049+ } while (0);
8050+#endif
8051+
8052+#ifdef CONFIG_PAX_EMUTRAMP
8053+
8054+#ifndef CONFIG_PAX_EMUSIGRT
8055+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
8056+ return 1;
8057+#endif
8058+
8059+ do { /* PaX: rt_sigreturn emulation */
8060+ unsigned int ldi1, ldi2, bel, nop;
8061+
8062+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
8063+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
8064+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
8065+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
8066+
8067+ if (err)
8068+ break;
8069+
8070+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
8071+ ldi2 == 0x3414015AU &&
8072+ bel == 0xE4008200U &&
8073+ nop == 0x08000240U)
8074+ {
8075+ regs->gr[25] = (ldi1 & 2) >> 1;
8076+ regs->gr[20] = __NR_rt_sigreturn;
8077+ regs->gr[31] = regs->iaoq[1] + 16;
8078+ regs->sr[0] = regs->iasq[1];
8079+ regs->iaoq[0] = 0x100UL;
8080+ regs->iaoq[1] = regs->iaoq[0] + 4;
8081+ regs->iasq[0] = regs->sr[2];
8082+ regs->iasq[1] = regs->sr[2];
8083+ return 2;
8084+ }
8085+ } while (0);
8086+#endif
8087+
8088+ return 1;
8089+}
8090+
8091+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8092+{
8093+ unsigned long i;
8094+
8095+ printk(KERN_ERR "PAX: bytes at PC: ");
8096+ for (i = 0; i < 5; i++) {
8097+ unsigned int c;
8098+ if (get_user(c, (unsigned int *)pc+i))
8099+ printk(KERN_CONT "???????? ");
8100+ else
8101+ printk(KERN_CONT "%08x ", c);
8102+ }
8103+ printk("\n");
8104+}
8105+#endif
8106+
8107 int fixup_exception(struct pt_regs *regs)
8108 {
8109 const struct exception_table_entry *fix;
8110@@ -234,8 +345,33 @@ retry:
8111
8112 good_area:
8113
8114- if ((vma->vm_flags & acc_type) != acc_type)
8115+ if ((vma->vm_flags & acc_type) != acc_type) {
8116+
8117+#ifdef CONFIG_PAX_PAGEEXEC
8118+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
8119+ (address & ~3UL) == instruction_pointer(regs))
8120+ {
8121+ up_read(&mm->mmap_sem);
8122+ switch (pax_handle_fetch_fault(regs)) {
8123+
8124+#ifdef CONFIG_PAX_EMUPLT
8125+ case 3:
8126+ return;
8127+#endif
8128+
8129+#ifdef CONFIG_PAX_EMUTRAMP
8130+ case 2:
8131+ return;
8132+#endif
8133+
8134+ }
8135+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
8136+ do_group_exit(SIGKILL);
8137+ }
8138+#endif
8139+
8140 goto bad_area;
8141+ }
8142
8143 /*
8144 * If for any reason at all we couldn't handle the fault, make
8145diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
8146index 4bc7b62..107e0b2 100644
8147--- a/arch/powerpc/Kconfig
8148+++ b/arch/powerpc/Kconfig
8149@@ -399,6 +399,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
8150 config KEXEC
8151 bool "kexec system call"
8152 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
8153+ depends on !GRKERNSEC_KMEM
8154 help
8155 kexec is a system call that implements the ability to shutdown your
8156 current kernel, and to start another kernel. It is like a reboot
8157diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
8158index 28992d0..434c881 100644
8159--- a/arch/powerpc/include/asm/atomic.h
8160+++ b/arch/powerpc/include/asm/atomic.h
8161@@ -12,6 +12,11 @@
8162
8163 #define ATOMIC_INIT(i) { (i) }
8164
8165+#define _ASM_EXTABLE(from, to) \
8166+" .section __ex_table,\"a\"\n" \
8167+ PPC_LONG" " #from ", " #to"\n" \
8168+" .previous\n"
8169+
8170 static __inline__ int atomic_read(const atomic_t *v)
8171 {
8172 int t;
8173@@ -21,16 +26,61 @@ static __inline__ int atomic_read(const atomic_t *v)
8174 return t;
8175 }
8176
8177+static __inline__ int atomic_read_unchecked(const atomic_unchecked_t *v)
8178+{
8179+ int t;
8180+
8181+ __asm__ __volatile__("lwz%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
8182+
8183+ return t;
8184+}
8185+
8186 static __inline__ void atomic_set(atomic_t *v, int i)
8187 {
8188 __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8189 }
8190
8191+static __inline__ void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8192+{
8193+ __asm__ __volatile__("stw%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8194+}
8195+
8196 static __inline__ void atomic_add(int a, atomic_t *v)
8197 {
8198 int t;
8199
8200 __asm__ __volatile__(
8201+"1: lwarx %0,0,%3 # atomic_add\n"
8202+
8203+#ifdef CONFIG_PAX_REFCOUNT
8204+" mcrxr cr0\n"
8205+" addo. %0,%2,%0\n"
8206+" bf 4*cr0+so, 3f\n"
8207+"2:.long " "0x00c00b00""\n"
8208+#else
8209+" add %0,%2,%0\n"
8210+#endif
8211+
8212+"3:\n"
8213+ PPC405_ERR77(0,%3)
8214+" stwcx. %0,0,%3 \n\
8215+ bne- 1b"
8216+
8217+#ifdef CONFIG_PAX_REFCOUNT
8218+"\n4:\n"
8219+ _ASM_EXTABLE(2b, 4b)
8220+#endif
8221+
8222+ : "=&r" (t), "+m" (v->counter)
8223+ : "r" (a), "r" (&v->counter)
8224+ : "cc");
8225+}
8226+
8227+static __inline__ void atomic_add_unchecked(int a, atomic_unchecked_t *v)
8228+{
8229+ int t;
8230+
8231+ __asm__ __volatile__(
8232 "1: lwarx %0,0,%3 # atomic_add\n\
8233 add %0,%2,%0\n"
8234 PPC405_ERR77(0,%3)
8235@@ -41,12 +91,49 @@ static __inline__ void atomic_add(int a, atomic_t *v)
8236 : "cc");
8237 }
8238
8239+/* Same as atomic_add but return the value */
8240 static __inline__ int atomic_add_return(int a, atomic_t *v)
8241 {
8242 int t;
8243
8244 __asm__ __volatile__(
8245 PPC_ATOMIC_ENTRY_BARRIER
8246+"1: lwarx %0,0,%2 # atomic_add_return\n"
8247+
8248+#ifdef CONFIG_PAX_REFCOUNT
8249+" mcrxr cr0\n"
8250+" addo. %0,%1,%0\n"
8251+" bf 4*cr0+so, 3f\n"
8252+"2:.long " "0x00c00b00""\n"
8253+#else
8254+" add %0,%1,%0\n"
8255+#endif
8256+
8257+"3:\n"
8258+ PPC405_ERR77(0,%2)
8259+" stwcx. %0,0,%2 \n\
8260+ bne- 1b\n"
8261+"4:"
8262+
8263+#ifdef CONFIG_PAX_REFCOUNT
8264+ _ASM_EXTABLE(2b, 4b)
8265+#endif
8266+
8267+ PPC_ATOMIC_EXIT_BARRIER
8268+ : "=&r" (t)
8269+ : "r" (a), "r" (&v->counter)
8270+ : "cc", "memory");
8271+
8272+ return t;
8273+}
8274+
8275+/* Same as atomic_add_unchecked but return the value */
8276+static __inline__ int atomic_add_return_unchecked(int a, atomic_unchecked_t *v)
8277+{
8278+ int t;
8279+
8280+ __asm__ __volatile__(
8281+ PPC_ATOMIC_ENTRY_BARRIER
8282 "1: lwarx %0,0,%2 # atomic_add_return\n\
8283 add %0,%1,%0\n"
8284 PPC405_ERR77(0,%2)
8285@@ -67,6 +154,37 @@ static __inline__ void atomic_sub(int a, atomic_t *v)
8286 int t;
8287
8288 __asm__ __volatile__(
8289+"1: lwarx %0,0,%3 # atomic_sub\n"
8290+
8291+#ifdef CONFIG_PAX_REFCOUNT
8292+" mcrxr cr0\n"
8293+" subfo. %0,%2,%0\n"
8294+" bf 4*cr0+so, 3f\n"
8295+"2:.long " "0x00c00b00""\n"
8296+#else
8297+" subf %0,%2,%0\n"
8298+#endif
8299+
8300+"3:\n"
8301+ PPC405_ERR77(0,%3)
8302+" stwcx. %0,0,%3 \n\
8303+ bne- 1b\n"
8304+"4:"
8305+
8306+#ifdef CONFIG_PAX_REFCOUNT
8307+ _ASM_EXTABLE(2b, 4b)
8308+#endif
8309+
8310+ : "=&r" (t), "+m" (v->counter)
8311+ : "r" (a), "r" (&v->counter)
8312+ : "cc");
8313+}
8314+
8315+static __inline__ void atomic_sub_unchecked(int a, atomic_unchecked_t *v)
8316+{
8317+ int t;
8318+
8319+ __asm__ __volatile__(
8320 "1: lwarx %0,0,%3 # atomic_sub\n\
8321 subf %0,%2,%0\n"
8322 PPC405_ERR77(0,%3)
8323@@ -77,12 +195,49 @@ static __inline__ void atomic_sub(int a, atomic_t *v)
8324 : "cc");
8325 }
8326
8327+/* Same as atomic_sub but return the value */
8328 static __inline__ int atomic_sub_return(int a, atomic_t *v)
8329 {
8330 int t;
8331
8332 __asm__ __volatile__(
8333 PPC_ATOMIC_ENTRY_BARRIER
8334+"1: lwarx %0,0,%2 # atomic_sub_return\n"
8335+
8336+#ifdef CONFIG_PAX_REFCOUNT
8337+" mcrxr cr0\n"
8338+" subfo. %0,%1,%0\n"
8339+" bf 4*cr0+so, 3f\n"
8340+"2:.long " "0x00c00b00""\n"
8341+#else
8342+" subf %0,%1,%0\n"
8343+#endif
8344+
8345+"3:\n"
8346+ PPC405_ERR77(0,%2)
8347+" stwcx. %0,0,%2 \n\
8348+ bne- 1b\n"
8349+ PPC_ATOMIC_EXIT_BARRIER
8350+"4:"
8351+
8352+#ifdef CONFIG_PAX_REFCOUNT
8353+ _ASM_EXTABLE(2b, 4b)
8354+#endif
8355+
8356+ : "=&r" (t)
8357+ : "r" (a), "r" (&v->counter)
8358+ : "cc", "memory");
8359+
8360+ return t;
8361+}
8362+
8363+/* Same as atomic_sub_unchecked but return the value */
8364+static __inline__ int atomic_sub_return_unchecked(int a, atomic_unchecked_t *v)
8365+{
8366+ int t;
8367+
8368+ __asm__ __volatile__(
8369+ PPC_ATOMIC_ENTRY_BARRIER
8370 "1: lwarx %0,0,%2 # atomic_sub_return\n\
8371 subf %0,%1,%0\n"
8372 PPC405_ERR77(0,%2)
8373@@ -96,38 +251,23 @@ static __inline__ int atomic_sub_return(int a, atomic_t *v)
8374 return t;
8375 }
8376
8377-static __inline__ void atomic_inc(atomic_t *v)
8378-{
8379- int t;
8380+/*
8381+ * atomic_inc - increment atomic variable
8382+ * @v: pointer of type atomic_t
8383+ *
8384+ * Automatically increments @v by 1
8385+ */
8386+#define atomic_inc(v) atomic_add(1, (v))
8387+#define atomic_inc_return(v) atomic_add_return(1, (v))
8388
8389- __asm__ __volatile__(
8390-"1: lwarx %0,0,%2 # atomic_inc\n\
8391- addic %0,%0,1\n"
8392- PPC405_ERR77(0,%2)
8393-" stwcx. %0,0,%2 \n\
8394- bne- 1b"
8395- : "=&r" (t), "+m" (v->counter)
8396- : "r" (&v->counter)
8397- : "cc", "xer");
8398+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
8399+{
8400+ atomic_add_unchecked(1, v);
8401 }
8402
8403-static __inline__ int atomic_inc_return(atomic_t *v)
8404+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
8405 {
8406- int t;
8407-
8408- __asm__ __volatile__(
8409- PPC_ATOMIC_ENTRY_BARRIER
8410-"1: lwarx %0,0,%1 # atomic_inc_return\n\
8411- addic %0,%0,1\n"
8412- PPC405_ERR77(0,%1)
8413-" stwcx. %0,0,%1 \n\
8414- bne- 1b"
8415- PPC_ATOMIC_EXIT_BARRIER
8416- : "=&r" (t)
8417- : "r" (&v->counter)
8418- : "cc", "xer", "memory");
8419-
8420- return t;
8421+ return atomic_add_return_unchecked(1, v);
8422 }
8423
8424 /*
8425@@ -140,43 +280,38 @@ static __inline__ int atomic_inc_return(atomic_t *v)
8426 */
8427 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
8428
8429-static __inline__ void atomic_dec(atomic_t *v)
8430+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
8431 {
8432- int t;
8433-
8434- __asm__ __volatile__(
8435-"1: lwarx %0,0,%2 # atomic_dec\n\
8436- addic %0,%0,-1\n"
8437- PPC405_ERR77(0,%2)\
8438-" stwcx. %0,0,%2\n\
8439- bne- 1b"
8440- : "=&r" (t), "+m" (v->counter)
8441- : "r" (&v->counter)
8442- : "cc", "xer");
8443+ return atomic_add_return_unchecked(1, v) == 0;
8444 }
8445
8446-static __inline__ int atomic_dec_return(atomic_t *v)
8447+/*
8448+ * atomic_dec - decrement atomic variable
8449+ * @v: pointer of type atomic_t
8450+ *
8451+ * Atomically decrements @v by 1
8452+ */
8453+#define atomic_dec(v) atomic_sub(1, (v))
8454+#define atomic_dec_return(v) atomic_sub_return(1, (v))
8455+
8456+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
8457 {
8458- int t;
8459-
8460- __asm__ __volatile__(
8461- PPC_ATOMIC_ENTRY_BARRIER
8462-"1: lwarx %0,0,%1 # atomic_dec_return\n\
8463- addic %0,%0,-1\n"
8464- PPC405_ERR77(0,%1)
8465-" stwcx. %0,0,%1\n\
8466- bne- 1b"
8467- PPC_ATOMIC_EXIT_BARRIER
8468- : "=&r" (t)
8469- : "r" (&v->counter)
8470- : "cc", "xer", "memory");
8471-
8472- return t;
8473+ atomic_sub_unchecked(1, v);
8474 }
8475
8476 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8477 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
8478
8479+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
8480+{
8481+ return cmpxchg(&(v->counter), old, new);
8482+}
8483+
8484+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
8485+{
8486+ return xchg(&(v->counter), new);
8487+}
8488+
8489 /**
8490 * __atomic_add_unless - add unless the number is a given value
8491 * @v: pointer of type atomic_t
8492@@ -271,6 +406,11 @@ static __inline__ int atomic_dec_if_positive(atomic_t *v)
8493 }
8494 #define atomic_dec_if_positive atomic_dec_if_positive
8495
8496+#define smp_mb__before_atomic_dec() smp_mb()
8497+#define smp_mb__after_atomic_dec() smp_mb()
8498+#define smp_mb__before_atomic_inc() smp_mb()
8499+#define smp_mb__after_atomic_inc() smp_mb()
8500+
8501 #ifdef __powerpc64__
8502
8503 #define ATOMIC64_INIT(i) { (i) }
8504@@ -284,11 +424,25 @@ static __inline__ long atomic64_read(const atomic64_t *v)
8505 return t;
8506 }
8507
8508+static __inline__ long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8509+{
8510+ long t;
8511+
8512+ __asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : "m"(v->counter));
8513+
8514+ return t;
8515+}
8516+
8517 static __inline__ void atomic64_set(atomic64_t *v, long i)
8518 {
8519 __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8520 }
8521
8522+static __inline__ void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8523+{
8524+ __asm__ __volatile__("std%U0%X0 %1,%0" : "=m"(v->counter) : "r"(i));
8525+}
8526+
8527 static __inline__ void atomic64_add(long a, atomic64_t *v)
8528 {
8529 long t;
8530@@ -303,12 +457,76 @@ static __inline__ void atomic64_add(long a, atomic64_t *v)
8531 : "cc");
8532 }
8533
8534+static __inline__ void atomic64_add_unchecked(long a, atomic64_unchecked_t *v)
8535+{
8536+ long t;
8537+
8538+ __asm__ __volatile__(
8539+"1: ldarx %0,0,%3 # atomic64_add\n"
8540+
8541+#ifdef CONFIG_PAX_REFCOUNT
8542+" mcrxr cr0\n"
8543+" addo. %0,%2,%0\n"
8544+" bf 4*cr0+so, 3f\n"
8545+"2:.long " "0x00c00b00""\n"
8546+#else
8547+" add %0,%2,%0\n"
8548+#endif
8549+
8550+"3:\n"
8551+" stdcx. %0,0,%3 \n\
8552+ bne- 1b\n"
8553+"4:"
8554+
8555+#ifdef CONFIG_PAX_REFCOUNT
8556+ _ASM_EXTABLE(2b, 4b)
8557+#endif
8558+
8559+ : "=&r" (t), "+m" (v->counter)
8560+ : "r" (a), "r" (&v->counter)
8561+ : "cc");
8562+}
8563+
8564 static __inline__ long atomic64_add_return(long a, atomic64_t *v)
8565 {
8566 long t;
8567
8568 __asm__ __volatile__(
8569 PPC_ATOMIC_ENTRY_BARRIER
8570+"1: ldarx %0,0,%2 # atomic64_add_return\n"
8571+
8572+#ifdef CONFIG_PAX_REFCOUNT
8573+" mcrxr cr0\n"
8574+" addo. %0,%1,%0\n"
8575+" bf 4*cr0+so, 3f\n"
8576+"2:.long " "0x00c00b00""\n"
8577+#else
8578+" add %0,%1,%0\n"
8579+#endif
8580+
8581+"3:\n"
8582+" stdcx. %0,0,%2 \n\
8583+ bne- 1b\n"
8584+ PPC_ATOMIC_EXIT_BARRIER
8585+"4:"
8586+
8587+#ifdef CONFIG_PAX_REFCOUNT
8588+ _ASM_EXTABLE(2b, 4b)
8589+#endif
8590+
8591+ : "=&r" (t)
8592+ : "r" (a), "r" (&v->counter)
8593+ : "cc", "memory");
8594+
8595+ return t;
8596+}
8597+
8598+static __inline__ long atomic64_add_return_unchecked(long a, atomic64_unchecked_t *v)
8599+{
8600+ long t;
8601+
8602+ __asm__ __volatile__(
8603+ PPC_ATOMIC_ENTRY_BARRIER
8604 "1: ldarx %0,0,%2 # atomic64_add_return\n\
8605 add %0,%1,%0\n\
8606 stdcx. %0,0,%2 \n\
8607@@ -328,6 +546,36 @@ static __inline__ void atomic64_sub(long a, atomic64_t *v)
8608 long t;
8609
8610 __asm__ __volatile__(
8611+"1: ldarx %0,0,%3 # atomic64_sub\n"
8612+
8613+#ifdef CONFIG_PAX_REFCOUNT
8614+" mcrxr cr0\n"
8615+" subfo. %0,%2,%0\n"
8616+" bf 4*cr0+so, 3f\n"
8617+"2:.long " "0x00c00b00""\n"
8618+#else
8619+" subf %0,%2,%0\n"
8620+#endif
8621+
8622+"3:\n"
8623+" stdcx. %0,0,%3 \n\
8624+ bne- 1b"
8625+"4:"
8626+
8627+#ifdef CONFIG_PAX_REFCOUNT
8628+ _ASM_EXTABLE(2b, 4b)
8629+#endif
8630+
8631+ : "=&r" (t), "+m" (v->counter)
8632+ : "r" (a), "r" (&v->counter)
8633+ : "cc");
8634+}
8635+
8636+static __inline__ void atomic64_sub_unchecked(long a, atomic64_unchecked_t *v)
8637+{
8638+ long t;
8639+
8640+ __asm__ __volatile__(
8641 "1: ldarx %0,0,%3 # atomic64_sub\n\
8642 subf %0,%2,%0\n\
8643 stdcx. %0,0,%3 \n\
8644@@ -343,6 +591,40 @@ static __inline__ long atomic64_sub_return(long a, atomic64_t *v)
8645
8646 __asm__ __volatile__(
8647 PPC_ATOMIC_ENTRY_BARRIER
8648+"1: ldarx %0,0,%2 # atomic64_sub_return\n"
8649+
8650+#ifdef CONFIG_PAX_REFCOUNT
8651+" mcrxr cr0\n"
8652+" subfo. %0,%1,%0\n"
8653+" bf 4*cr0+so, 3f\n"
8654+"2:.long " "0x00c00b00""\n"
8655+#else
8656+" subf %0,%1,%0\n"
8657+#endif
8658+
8659+"3:\n"
8660+" stdcx. %0,0,%2 \n\
8661+ bne- 1b\n"
8662+ PPC_ATOMIC_EXIT_BARRIER
8663+"4:"
8664+
8665+#ifdef CONFIG_PAX_REFCOUNT
8666+ _ASM_EXTABLE(2b, 4b)
8667+#endif
8668+
8669+ : "=&r" (t)
8670+ : "r" (a), "r" (&v->counter)
8671+ : "cc", "memory");
8672+
8673+ return t;
8674+}
8675+
8676+static __inline__ long atomic64_sub_return_unchecked(long a, atomic64_unchecked_t *v)
8677+{
8678+ long t;
8679+
8680+ __asm__ __volatile__(
8681+ PPC_ATOMIC_ENTRY_BARRIER
8682 "1: ldarx %0,0,%2 # atomic64_sub_return\n\
8683 subf %0,%1,%0\n\
8684 stdcx. %0,0,%2 \n\
8685@@ -355,36 +637,23 @@ static __inline__ long atomic64_sub_return(long a, atomic64_t *v)
8686 return t;
8687 }
8688
8689-static __inline__ void atomic64_inc(atomic64_t *v)
8690-{
8691- long t;
8692+/*
8693+ * atomic64_inc - increment atomic variable
8694+ * @v: pointer of type atomic64_t
8695+ *
8696+ * Automatically increments @v by 1
8697+ */
8698+#define atomic64_inc(v) atomic64_add(1, (v))
8699+#define atomic64_inc_return(v) atomic64_add_return(1, (v))
8700
8701- __asm__ __volatile__(
8702-"1: ldarx %0,0,%2 # atomic64_inc\n\
8703- addic %0,%0,1\n\
8704- stdcx. %0,0,%2 \n\
8705- bne- 1b"
8706- : "=&r" (t), "+m" (v->counter)
8707- : "r" (&v->counter)
8708- : "cc", "xer");
8709+static __inline__ void atomic64_inc_unchecked(atomic64_unchecked_t *v)
8710+{
8711+ atomic64_add_unchecked(1, v);
8712 }
8713
8714-static __inline__ long atomic64_inc_return(atomic64_t *v)
8715+static __inline__ int atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
8716 {
8717- long t;
8718-
8719- __asm__ __volatile__(
8720- PPC_ATOMIC_ENTRY_BARRIER
8721-"1: ldarx %0,0,%1 # atomic64_inc_return\n\
8722- addic %0,%0,1\n\
8723- stdcx. %0,0,%1 \n\
8724- bne- 1b"
8725- PPC_ATOMIC_EXIT_BARRIER
8726- : "=&r" (t)
8727- : "r" (&v->counter)
8728- : "cc", "xer", "memory");
8729-
8730- return t;
8731+ return atomic64_add_return_unchecked(1, v);
8732 }
8733
8734 /*
8735@@ -397,36 +666,18 @@ static __inline__ long atomic64_inc_return(atomic64_t *v)
8736 */
8737 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
8738
8739-static __inline__ void atomic64_dec(atomic64_t *v)
8740+/*
8741+ * atomic64_dec - decrement atomic variable
8742+ * @v: pointer of type atomic64_t
8743+ *
8744+ * Atomically decrements @v by 1
8745+ */
8746+#define atomic64_dec(v) atomic64_sub(1, (v))
8747+#define atomic64_dec_return(v) atomic64_sub_return(1, (v))
8748+
8749+static __inline__ void atomic64_dec_unchecked(atomic64_unchecked_t *v)
8750 {
8751- long t;
8752-
8753- __asm__ __volatile__(
8754-"1: ldarx %0,0,%2 # atomic64_dec\n\
8755- addic %0,%0,-1\n\
8756- stdcx. %0,0,%2\n\
8757- bne- 1b"
8758- : "=&r" (t), "+m" (v->counter)
8759- : "r" (&v->counter)
8760- : "cc", "xer");
8761-}
8762-
8763-static __inline__ long atomic64_dec_return(atomic64_t *v)
8764-{
8765- long t;
8766-
8767- __asm__ __volatile__(
8768- PPC_ATOMIC_ENTRY_BARRIER
8769-"1: ldarx %0,0,%1 # atomic64_dec_return\n\
8770- addic %0,%0,-1\n\
8771- stdcx. %0,0,%1\n\
8772- bne- 1b"
8773- PPC_ATOMIC_EXIT_BARRIER
8774- : "=&r" (t)
8775- : "r" (&v->counter)
8776- : "cc", "xer", "memory");
8777-
8778- return t;
8779+ atomic64_sub_unchecked(1, v);
8780 }
8781
8782 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
8783@@ -459,6 +710,16 @@ static __inline__ long atomic64_dec_if_positive(atomic64_t *v)
8784 #define atomic64_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
8785 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
8786
8787+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
8788+{
8789+ return cmpxchg(&(v->counter), old, new);
8790+}
8791+
8792+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
8793+{
8794+ return xchg(&(v->counter), new);
8795+}
8796+
8797 /**
8798 * atomic64_add_unless - add unless the number is a given value
8799 * @v: pointer of type atomic64_t
8800diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8801index bab79a1..4a3eabc 100644
8802--- a/arch/powerpc/include/asm/barrier.h
8803+++ b/arch/powerpc/include/asm/barrier.h
8804@@ -73,7 +73,7 @@
8805 do { \
8806 compiletime_assert_atomic_type(*p); \
8807 __lwsync(); \
8808- ACCESS_ONCE(*p) = (v); \
8809+ ACCESS_ONCE_RW(*p) = (v); \
8810 } while (0)
8811
8812 #define smp_load_acquire(p) \
8813diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8814index 34a05a1..a1f2c67 100644
8815--- a/arch/powerpc/include/asm/cache.h
8816+++ b/arch/powerpc/include/asm/cache.h
8817@@ -4,6 +4,7 @@
8818 #ifdef __KERNEL__
8819
8820 #include <asm/reg.h>
8821+#include <linux/const.h>
8822
8823 /* bytes per L1 cache line */
8824 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8825@@ -23,7 +24,7 @@
8826 #define L1_CACHE_SHIFT 7
8827 #endif
8828
8829-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8830+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8831
8832 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8833
8834diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8835index 888d8f3..66f581c 100644
8836--- a/arch/powerpc/include/asm/elf.h
8837+++ b/arch/powerpc/include/asm/elf.h
8838@@ -28,8 +28,19 @@
8839 the loader. We need to make sure that it is out of the way of the program
8840 that it will "exec", and that there is sufficient room for the brk. */
8841
8842-extern unsigned long randomize_et_dyn(unsigned long base);
8843-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8844+#define ELF_ET_DYN_BASE (0x20000000)
8845+
8846+#ifdef CONFIG_PAX_ASLR
8847+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8848+
8849+#ifdef __powerpc64__
8850+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8851+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8852+#else
8853+#define PAX_DELTA_MMAP_LEN 15
8854+#define PAX_DELTA_STACK_LEN 15
8855+#endif
8856+#endif
8857
8858 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8859
8860@@ -129,10 +140,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8861 (0x7ff >> (PAGE_SHIFT - 12)) : \
8862 (0x3ffff >> (PAGE_SHIFT - 12)))
8863
8864-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8865-#define arch_randomize_brk arch_randomize_brk
8866-
8867-
8868 #ifdef CONFIG_SPU_BASE
8869 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8870 #define NT_SPU 1
8871diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8872index 8196e9c..d83a9f3 100644
8873--- a/arch/powerpc/include/asm/exec.h
8874+++ b/arch/powerpc/include/asm/exec.h
8875@@ -4,6 +4,6 @@
8876 #ifndef _ASM_POWERPC_EXEC_H
8877 #define _ASM_POWERPC_EXEC_H
8878
8879-extern unsigned long arch_align_stack(unsigned long sp);
8880+#define arch_align_stack(x) ((x) & ~0xfUL)
8881
8882 #endif /* _ASM_POWERPC_EXEC_H */
8883diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8884index 5acabbd..7ea14fa 100644
8885--- a/arch/powerpc/include/asm/kmap_types.h
8886+++ b/arch/powerpc/include/asm/kmap_types.h
8887@@ -10,7 +10,7 @@
8888 * 2 of the License, or (at your option) any later version.
8889 */
8890
8891-#define KM_TYPE_NR 16
8892+#define KM_TYPE_NR 17
8893
8894 #endif /* __KERNEL__ */
8895 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8896diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8897index b8da913..c02b593 100644
8898--- a/arch/powerpc/include/asm/local.h
8899+++ b/arch/powerpc/include/asm/local.h
8900@@ -9,21 +9,65 @@ typedef struct
8901 atomic_long_t a;
8902 } local_t;
8903
8904+typedef struct
8905+{
8906+ atomic_long_unchecked_t a;
8907+} local_unchecked_t;
8908+
8909 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8910
8911 #define local_read(l) atomic_long_read(&(l)->a)
8912+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8913 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8914+#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8915
8916 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8917+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8918 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8919+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8920 #define local_inc(l) atomic_long_inc(&(l)->a)
8921+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8922 #define local_dec(l) atomic_long_dec(&(l)->a)
8923+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8924
8925 static __inline__ long local_add_return(long a, local_t *l)
8926 {
8927 long t;
8928
8929 __asm__ __volatile__(
8930+"1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n"
8931+
8932+#ifdef CONFIG_PAX_REFCOUNT
8933+" mcrxr cr0\n"
8934+" addo. %0,%1,%0\n"
8935+" bf 4*cr0+so, 3f\n"
8936+"2:.long " "0x00c00b00""\n"
8937+#else
8938+" add %0,%1,%0\n"
8939+#endif
8940+
8941+"3:\n"
8942+ PPC405_ERR77(0,%2)
8943+ PPC_STLCX "%0,0,%2 \n\
8944+ bne- 1b"
8945+
8946+#ifdef CONFIG_PAX_REFCOUNT
8947+"\n4:\n"
8948+ _ASM_EXTABLE(2b, 4b)
8949+#endif
8950+
8951+ : "=&r" (t)
8952+ : "r" (a), "r" (&(l->a.counter))
8953+ : "cc", "memory");
8954+
8955+ return t;
8956+}
8957+
8958+static __inline__ long local_add_return_unchecked(long a, local_unchecked_t *l)
8959+{
8960+ long t;
8961+
8962+ __asm__ __volatile__(
8963 "1:" PPC_LLARX(%0,0,%2,0) " # local_add_return\n\
8964 add %0,%1,%0\n"
8965 PPC405_ERR77(0,%2)
8966@@ -101,6 +145,8 @@ static __inline__ long local_dec_return(local_t *l)
8967
8968 #define local_cmpxchg(l, o, n) \
8969 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8970+#define local_cmpxchg_unchecked(l, o, n) \
8971+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
8972 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8973
8974 /**
8975diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8976index 8565c25..2865190 100644
8977--- a/arch/powerpc/include/asm/mman.h
8978+++ b/arch/powerpc/include/asm/mman.h
8979@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8980 }
8981 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8982
8983-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8984+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8985 {
8986 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8987 }
8988diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8989index 26fe1ae..987ffc5 100644
8990--- a/arch/powerpc/include/asm/page.h
8991+++ b/arch/powerpc/include/asm/page.h
8992@@ -227,8 +227,9 @@ extern long long virt_phys_offset;
8993 * and needs to be executable. This means the whole heap ends
8994 * up being executable.
8995 */
8996-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8997- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8998+#define VM_DATA_DEFAULT_FLAGS32 \
8999+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
9000+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9001
9002 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
9003 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9004@@ -256,6 +257,9 @@ extern long long virt_phys_offset;
9005 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
9006 #endif
9007
9008+#define ktla_ktva(addr) (addr)
9009+#define ktva_ktla(addr) (addr)
9010+
9011 #ifndef CONFIG_PPC_BOOK3S_64
9012 /*
9013 * Use the top bit of the higher-level page table entries to indicate whether
9014diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
9015index 88693ce..ac6f9ab 100644
9016--- a/arch/powerpc/include/asm/page_64.h
9017+++ b/arch/powerpc/include/asm/page_64.h
9018@@ -153,15 +153,18 @@ do { \
9019 * stack by default, so in the absence of a PT_GNU_STACK program header
9020 * we turn execute permission off.
9021 */
9022-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
9023- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9024+#define VM_STACK_DEFAULT_FLAGS32 \
9025+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
9026+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9027
9028 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
9029 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
9030
9031+#ifndef CONFIG_PAX_PAGEEXEC
9032 #define VM_STACK_DEFAULT_FLAGS \
9033 (is_32bit_task() ? \
9034 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
9035+#endif
9036
9037 #include <asm-generic/getorder.h>
9038
9039diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
9040index 4b0be20..c15a27d 100644
9041--- a/arch/powerpc/include/asm/pgalloc-64.h
9042+++ b/arch/powerpc/include/asm/pgalloc-64.h
9043@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9044 #ifndef CONFIG_PPC_64K_PAGES
9045
9046 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
9047+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
9048
9049 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
9050 {
9051@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
9052 pud_set(pud, (unsigned long)pmd);
9053 }
9054
9055+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
9056+{
9057+ pud_populate(mm, pud, pmd);
9058+}
9059+
9060 #define pmd_populate(mm, pmd, pte_page) \
9061 pmd_populate_kernel(mm, pmd, page_address(pte_page))
9062 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
9063@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
9064 #endif
9065
9066 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
9067+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
9068
9069 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
9070 pte_t *pte)
9071diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
9072index d98c1ec..9f61569 100644
9073--- a/arch/powerpc/include/asm/pgtable.h
9074+++ b/arch/powerpc/include/asm/pgtable.h
9075@@ -2,6 +2,7 @@
9076 #define _ASM_POWERPC_PGTABLE_H
9077 #ifdef __KERNEL__
9078
9079+#include <linux/const.h>
9080 #ifndef __ASSEMBLY__
9081 #include <linux/mmdebug.h>
9082 #include <asm/processor.h> /* For TASK_SIZE */
9083diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
9084index 4aad413..85d86bf 100644
9085--- a/arch/powerpc/include/asm/pte-hash32.h
9086+++ b/arch/powerpc/include/asm/pte-hash32.h
9087@@ -21,6 +21,7 @@
9088 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
9089 #define _PAGE_USER 0x004 /* usermode access allowed */
9090 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
9091+#define _PAGE_EXEC _PAGE_GUARDED
9092 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
9093 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
9094 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
9095diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
9096index 0c05059..7e056e4 100644
9097--- a/arch/powerpc/include/asm/reg.h
9098+++ b/arch/powerpc/include/asm/reg.h
9099@@ -251,6 +251,7 @@
9100 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
9101 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
9102 #define DSISR_NOHPTE 0x40000000 /* no translation found */
9103+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
9104 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
9105 #define DSISR_ISSTORE 0x02000000 /* access was a store */
9106 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
9107diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
9108index 5a6614a..d89995d1 100644
9109--- a/arch/powerpc/include/asm/smp.h
9110+++ b/arch/powerpc/include/asm/smp.h
9111@@ -51,7 +51,7 @@ struct smp_ops_t {
9112 int (*cpu_disable)(void);
9113 void (*cpu_die)(unsigned int nr);
9114 int (*cpu_bootable)(unsigned int nr);
9115-};
9116+} __no_const;
9117
9118 extern void smp_send_debugger_break(void);
9119 extern void start_secondary_resume(void);
9120diff --git a/arch/powerpc/include/asm/spinlock.h b/arch/powerpc/include/asm/spinlock.h
9121index 4dbe072..b803275 100644
9122--- a/arch/powerpc/include/asm/spinlock.h
9123+++ b/arch/powerpc/include/asm/spinlock.h
9124@@ -204,13 +204,29 @@ static inline long __arch_read_trylock(arch_rwlock_t *rw)
9125 __asm__ __volatile__(
9126 "1: " PPC_LWARX(%0,0,%1,1) "\n"
9127 __DO_SIGN_EXTEND
9128-" addic. %0,%0,1\n\
9129- ble- 2f\n"
9130+
9131+#ifdef CONFIG_PAX_REFCOUNT
9132+" mcrxr cr0\n"
9133+" addico. %0,%0,1\n"
9134+" bf 4*cr0+so, 3f\n"
9135+"2:.long " "0x00c00b00""\n"
9136+#else
9137+" addic. %0,%0,1\n"
9138+#endif
9139+
9140+"3:\n"
9141+ "ble- 4f\n"
9142 PPC405_ERR77(0,%1)
9143 " stwcx. %0,0,%1\n\
9144 bne- 1b\n"
9145 PPC_ACQUIRE_BARRIER
9146-"2:" : "=&r" (tmp)
9147+"4:"
9148+
9149+#ifdef CONFIG_PAX_REFCOUNT
9150+ _ASM_EXTABLE(2b,4b)
9151+#endif
9152+
9153+ : "=&r" (tmp)
9154 : "r" (&rw->lock)
9155 : "cr0", "xer", "memory");
9156
9157@@ -286,11 +302,27 @@ static inline void arch_read_unlock(arch_rwlock_t *rw)
9158 __asm__ __volatile__(
9159 "# read_unlock\n\t"
9160 PPC_RELEASE_BARRIER
9161-"1: lwarx %0,0,%1\n\
9162- addic %0,%0,-1\n"
9163+"1: lwarx %0,0,%1\n"
9164+
9165+#ifdef CONFIG_PAX_REFCOUNT
9166+" mcrxr cr0\n"
9167+" addico. %0,%0,-1\n"
9168+" bf 4*cr0+so, 3f\n"
9169+"2:.long " "0x00c00b00""\n"
9170+#else
9171+" addic. %0,%0,-1\n"
9172+#endif
9173+
9174+"3:\n"
9175 PPC405_ERR77(0,%1)
9176 " stwcx. %0,0,%1\n\
9177 bne- 1b"
9178+
9179+#ifdef CONFIG_PAX_REFCOUNT
9180+"\n4:\n"
9181+ _ASM_EXTABLE(2b, 4b)
9182+#endif
9183+
9184 : "=&r"(tmp)
9185 : "r"(&rw->lock)
9186 : "cr0", "xer", "memory");
9187diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
9188index b034ecd..af7e31f 100644
9189--- a/arch/powerpc/include/asm/thread_info.h
9190+++ b/arch/powerpc/include/asm/thread_info.h
9191@@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
9192 #if defined(CONFIG_PPC64)
9193 #define TIF_ELF2ABI 18 /* function descriptors must die! */
9194 #endif
9195+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
9196+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9197
9198 /* as above, but as bit values */
9199 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
9200@@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
9201 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9202 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
9203 #define _TIF_NOHZ (1<<TIF_NOHZ)
9204+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9205 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
9206 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
9207- _TIF_NOHZ)
9208+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
9209
9210 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
9211 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
9212diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
9213index 9485b43..3bd3c16 100644
9214--- a/arch/powerpc/include/asm/uaccess.h
9215+++ b/arch/powerpc/include/asm/uaccess.h
9216@@ -58,6 +58,7 @@
9217
9218 #endif
9219
9220+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9221 #define access_ok(type, addr, size) \
9222 (__chk_user_ptr(addr), \
9223 __access_ok((__force unsigned long)(addr), (size), get_fs()))
9224@@ -318,52 +319,6 @@ do { \
9225 extern unsigned long __copy_tofrom_user(void __user *to,
9226 const void __user *from, unsigned long size);
9227
9228-#ifndef __powerpc64__
9229-
9230-static inline unsigned long copy_from_user(void *to,
9231- const void __user *from, unsigned long n)
9232-{
9233- unsigned long over;
9234-
9235- if (access_ok(VERIFY_READ, from, n))
9236- return __copy_tofrom_user((__force void __user *)to, from, n);
9237- if ((unsigned long)from < TASK_SIZE) {
9238- over = (unsigned long)from + n - TASK_SIZE;
9239- return __copy_tofrom_user((__force void __user *)to, from,
9240- n - over) + over;
9241- }
9242- return n;
9243-}
9244-
9245-static inline unsigned long copy_to_user(void __user *to,
9246- const void *from, unsigned long n)
9247-{
9248- unsigned long over;
9249-
9250- if (access_ok(VERIFY_WRITE, to, n))
9251- return __copy_tofrom_user(to, (__force void __user *)from, n);
9252- if ((unsigned long)to < TASK_SIZE) {
9253- over = (unsigned long)to + n - TASK_SIZE;
9254- return __copy_tofrom_user(to, (__force void __user *)from,
9255- n - over) + over;
9256- }
9257- return n;
9258-}
9259-
9260-#else /* __powerpc64__ */
9261-
9262-#define __copy_in_user(to, from, size) \
9263- __copy_tofrom_user((to), (from), (size))
9264-
9265-extern unsigned long copy_from_user(void *to, const void __user *from,
9266- unsigned long n);
9267-extern unsigned long copy_to_user(void __user *to, const void *from,
9268- unsigned long n);
9269-extern unsigned long copy_in_user(void __user *to, const void __user *from,
9270- unsigned long n);
9271-
9272-#endif /* __powerpc64__ */
9273-
9274 static inline unsigned long __copy_from_user_inatomic(void *to,
9275 const void __user *from, unsigned long n)
9276 {
9277@@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
9278 if (ret == 0)
9279 return 0;
9280 }
9281+
9282+ if (!__builtin_constant_p(n))
9283+ check_object_size(to, n, false);
9284+
9285 return __copy_tofrom_user((__force void __user *)to, from, n);
9286 }
9287
9288@@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
9289 if (ret == 0)
9290 return 0;
9291 }
9292+
9293+ if (!__builtin_constant_p(n))
9294+ check_object_size(from, n, true);
9295+
9296 return __copy_tofrom_user(to, (__force const void __user *)from, n);
9297 }
9298
9299@@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
9300 return __copy_to_user_inatomic(to, from, size);
9301 }
9302
9303+#ifndef __powerpc64__
9304+
9305+static inline unsigned long __must_check copy_from_user(void *to,
9306+ const void __user *from, unsigned long n)
9307+{
9308+ unsigned long over;
9309+
9310+ if ((long)n < 0)
9311+ return n;
9312+
9313+ if (access_ok(VERIFY_READ, from, n)) {
9314+ if (!__builtin_constant_p(n))
9315+ check_object_size(to, n, false);
9316+ return __copy_tofrom_user((__force void __user *)to, from, n);
9317+ }
9318+ if ((unsigned long)from < TASK_SIZE) {
9319+ over = (unsigned long)from + n - TASK_SIZE;
9320+ if (!__builtin_constant_p(n - over))
9321+ check_object_size(to, n - over, false);
9322+ return __copy_tofrom_user((__force void __user *)to, from,
9323+ n - over) + over;
9324+ }
9325+ return n;
9326+}
9327+
9328+static inline unsigned long __must_check copy_to_user(void __user *to,
9329+ const void *from, unsigned long n)
9330+{
9331+ unsigned long over;
9332+
9333+ if ((long)n < 0)
9334+ return n;
9335+
9336+ if (access_ok(VERIFY_WRITE, to, n)) {
9337+ if (!__builtin_constant_p(n))
9338+ check_object_size(from, n, true);
9339+ return __copy_tofrom_user(to, (__force void __user *)from, n);
9340+ }
9341+ if ((unsigned long)to < TASK_SIZE) {
9342+ over = (unsigned long)to + n - TASK_SIZE;
9343+ if (!__builtin_constant_p(n))
9344+ check_object_size(from, n - over, true);
9345+ return __copy_tofrom_user(to, (__force void __user *)from,
9346+ n - over) + over;
9347+ }
9348+ return n;
9349+}
9350+
9351+#else /* __powerpc64__ */
9352+
9353+#define __copy_in_user(to, from, size) \
9354+ __copy_tofrom_user((to), (from), (size))
9355+
9356+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
9357+{
9358+ if ((long)n < 0 || n > INT_MAX)
9359+ return n;
9360+
9361+ if (!__builtin_constant_p(n))
9362+ check_object_size(to, n, false);
9363+
9364+ if (likely(access_ok(VERIFY_READ, from, n)))
9365+ n = __copy_from_user(to, from, n);
9366+ else
9367+ memset(to, 0, n);
9368+ return n;
9369+}
9370+
9371+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
9372+{
9373+ if ((long)n < 0 || n > INT_MAX)
9374+ return n;
9375+
9376+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
9377+ if (!__builtin_constant_p(n))
9378+ check_object_size(from, n, true);
9379+ n = __copy_to_user(to, from, n);
9380+ }
9381+ return n;
9382+}
9383+
9384+extern unsigned long copy_in_user(void __user *to, const void __user *from,
9385+ unsigned long n);
9386+
9387+#endif /* __powerpc64__ */
9388+
9389 extern unsigned long __clear_user(void __user *addr, unsigned long size);
9390
9391 static inline unsigned long clear_user(void __user *addr, unsigned long size)
9392diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
9393index 670c312..60c2b52 100644
9394--- a/arch/powerpc/kernel/Makefile
9395+++ b/arch/powerpc/kernel/Makefile
9396@@ -27,6 +27,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
9397 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
9398 endif
9399
9400+CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
9401+
9402 obj-y := cputable.o ptrace.o syscalls.o \
9403 irq.o align.o signal_32.o pmc.o vdso.o \
9404 process.o systbl.o idle.o \
9405diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
9406index bb9cac6..5181202 100644
9407--- a/arch/powerpc/kernel/exceptions-64e.S
9408+++ b/arch/powerpc/kernel/exceptions-64e.S
9409@@ -1010,6 +1010,7 @@ storage_fault_common:
9410 std r14,_DAR(r1)
9411 std r15,_DSISR(r1)
9412 addi r3,r1,STACK_FRAME_OVERHEAD
9413+ bl save_nvgprs
9414 mr r4,r14
9415 mr r5,r15
9416 ld r14,PACA_EXGEN+EX_R14(r13)
9417@@ -1018,8 +1019,7 @@ storage_fault_common:
9418 cmpdi r3,0
9419 bne- 1f
9420 b ret_from_except_lite
9421-1: bl save_nvgprs
9422- mr r5,r3
9423+1: mr r5,r3
9424 addi r3,r1,STACK_FRAME_OVERHEAD
9425 ld r4,_DAR(r1)
9426 bl bad_page_fault
9427diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
9428index 050f79a..f385bfe 100644
9429--- a/arch/powerpc/kernel/exceptions-64s.S
9430+++ b/arch/powerpc/kernel/exceptions-64s.S
9431@@ -1593,10 +1593,10 @@ handle_page_fault:
9432 11: ld r4,_DAR(r1)
9433 ld r5,_DSISR(r1)
9434 addi r3,r1,STACK_FRAME_OVERHEAD
9435+ bl save_nvgprs
9436 bl do_page_fault
9437 cmpdi r3,0
9438 beq+ 12f
9439- bl save_nvgprs
9440 mr r5,r3
9441 addi r3,r1,STACK_FRAME_OVERHEAD
9442 lwz r4,_DAR(r1)
9443diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
9444index 4c5891d..a5d88bb 100644
9445--- a/arch/powerpc/kernel/irq.c
9446+++ b/arch/powerpc/kernel/irq.c
9447@@ -461,6 +461,8 @@ void migrate_irqs(void)
9448 }
9449 #endif
9450
9451+extern void gr_handle_kernel_exploit(void);
9452+
9453 static inline void check_stack_overflow(void)
9454 {
9455 #ifdef CONFIG_DEBUG_STACKOVERFLOW
9456@@ -473,6 +475,7 @@ static inline void check_stack_overflow(void)
9457 printk("do_IRQ: stack overflow: %ld\n",
9458 sp - sizeof(struct thread_info));
9459 dump_stack();
9460+ gr_handle_kernel_exploit();
9461 }
9462 #endif
9463 }
9464diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
9465index 6cff040..74ac5d1b 100644
9466--- a/arch/powerpc/kernel/module_32.c
9467+++ b/arch/powerpc/kernel/module_32.c
9468@@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
9469 me->arch.core_plt_section = i;
9470 }
9471 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
9472- printk("Module doesn't contain .plt or .init.plt sections.\n");
9473+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
9474 return -ENOEXEC;
9475 }
9476
9477@@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
9478
9479 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
9480 /* Init, or core PLT? */
9481- if (location >= mod->module_core
9482- && location < mod->module_core + mod->core_size)
9483+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
9484+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
9485 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
9486- else
9487+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
9488+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
9489 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
9490+ else {
9491+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
9492+ return ~0UL;
9493+ }
9494
9495 /* Find this entry, or if that fails, the next avail. entry */
9496 while (entry->jump[0]) {
9497@@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
9498 }
9499 #ifdef CONFIG_DYNAMIC_FTRACE
9500 module->arch.tramp =
9501- do_plt_call(module->module_core,
9502+ do_plt_call(module->module_core_rx,
9503 (unsigned long)ftrace_caller,
9504 sechdrs, module);
9505 #endif
9506diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
9507index bf44ae9..6d2ce71 100644
9508--- a/arch/powerpc/kernel/process.c
9509+++ b/arch/powerpc/kernel/process.c
9510@@ -1039,8 +1039,8 @@ void show_regs(struct pt_regs * regs)
9511 * Lookup NIP late so we have the best change of getting the
9512 * above info out without failing
9513 */
9514- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
9515- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
9516+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
9517+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
9518 #endif
9519 show_stack(current, (unsigned long *) regs->gpr[1]);
9520 if (!user_mode(regs))
9521@@ -1558,10 +1558,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9522 newsp = stack[0];
9523 ip = stack[STACK_FRAME_LR_SAVE];
9524 if (!firstframe || ip != lr) {
9525- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
9526+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
9527 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
9528 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
9529- printk(" (%pS)",
9530+ printk(" (%pA)",
9531 (void *)current->ret_stack[curr_frame].ret);
9532 curr_frame--;
9533 }
9534@@ -1581,7 +1581,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
9535 struct pt_regs *regs = (struct pt_regs *)
9536 (sp + STACK_FRAME_OVERHEAD);
9537 lr = regs->link;
9538- printk("--- interrupt: %lx at %pS\n LR = %pS\n",
9539+ printk("--- interrupt: %lx at %pA\n LR = %pA\n",
9540 regs->trap, (void *)regs->nip, (void *)lr);
9541 firstframe = 1;
9542 }
9543@@ -1617,58 +1617,3 @@ void notrace __ppc64_runlatch_off(void)
9544 mtspr(SPRN_CTRLT, ctrl);
9545 }
9546 #endif /* CONFIG_PPC64 */
9547-
9548-unsigned long arch_align_stack(unsigned long sp)
9549-{
9550- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9551- sp -= get_random_int() & ~PAGE_MASK;
9552- return sp & ~0xf;
9553-}
9554-
9555-static inline unsigned long brk_rnd(void)
9556-{
9557- unsigned long rnd = 0;
9558-
9559- /* 8MB for 32bit, 1GB for 64bit */
9560- if (is_32bit_task())
9561- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
9562- else
9563- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
9564-
9565- return rnd << PAGE_SHIFT;
9566-}
9567-
9568-unsigned long arch_randomize_brk(struct mm_struct *mm)
9569-{
9570- unsigned long base = mm->brk;
9571- unsigned long ret;
9572-
9573-#ifdef CONFIG_PPC_STD_MMU_64
9574- /*
9575- * If we are using 1TB segments and we are allowed to randomise
9576- * the heap, we can put it above 1TB so it is backed by a 1TB
9577- * segment. Otherwise the heap will be in the bottom 1TB
9578- * which always uses 256MB segments and this may result in a
9579- * performance penalty.
9580- */
9581- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
9582- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
9583-#endif
9584-
9585- ret = PAGE_ALIGN(base + brk_rnd());
9586-
9587- if (ret < mm->brk)
9588- return mm->brk;
9589-
9590- return ret;
9591-}
9592-
9593-unsigned long randomize_et_dyn(unsigned long base)
9594-{
9595- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9596-
9597- if (ret < base)
9598- return base;
9599-
9600- return ret;
9601-}
9602diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
9603index 2e3d2bf..35df241 100644
9604--- a/arch/powerpc/kernel/ptrace.c
9605+++ b/arch/powerpc/kernel/ptrace.c
9606@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
9607 return ret;
9608 }
9609
9610+#ifdef CONFIG_GRKERNSEC_SETXID
9611+extern void gr_delayed_cred_worker(void);
9612+#endif
9613+
9614 /*
9615 * We must return the syscall number to actually look up in the table.
9616 * This can be -1L to skip running any syscall at all.
9617@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
9618
9619 secure_computing_strict(regs->gpr[0]);
9620
9621+#ifdef CONFIG_GRKERNSEC_SETXID
9622+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9623+ gr_delayed_cred_worker();
9624+#endif
9625+
9626 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
9627 tracehook_report_syscall_entry(regs))
9628 /*
9629@@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
9630 {
9631 int step;
9632
9633+#ifdef CONFIG_GRKERNSEC_SETXID
9634+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9635+ gr_delayed_cred_worker();
9636+#endif
9637+
9638 audit_syscall_exit(regs);
9639
9640 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9641diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
9642index b171001..4ac7ac5 100644
9643--- a/arch/powerpc/kernel/signal_32.c
9644+++ b/arch/powerpc/kernel/signal_32.c
9645@@ -1011,7 +1011,7 @@ int handle_rt_signal32(struct ksignal *ksig, sigset_t *oldset,
9646 /* Save user registers on the stack */
9647 frame = &rt_sf->uc.uc_mcontext;
9648 addr = frame;
9649- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
9650+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9651 sigret = 0;
9652 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
9653 } else {
9654diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
9655index 2cb0c94..c0c0bc9 100644
9656--- a/arch/powerpc/kernel/signal_64.c
9657+++ b/arch/powerpc/kernel/signal_64.c
9658@@ -754,7 +754,7 @@ int handle_rt_signal64(struct ksignal *ksig, sigset_t *set, struct pt_regs *regs
9659 current->thread.fp_state.fpscr = 0;
9660
9661 /* Set up to return from userspace. */
9662- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
9663+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
9664 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
9665 } else {
9666 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
9667diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
9668index 0dc43f9..a885d33 100644
9669--- a/arch/powerpc/kernel/traps.c
9670+++ b/arch/powerpc/kernel/traps.c
9671@@ -36,6 +36,7 @@
9672 #include <linux/debugfs.h>
9673 #include <linux/ratelimit.h>
9674 #include <linux/context_tracking.h>
9675+#include <linux/uaccess.h>
9676
9677 #include <asm/emulated_ops.h>
9678 #include <asm/pgtable.h>
9679@@ -142,6 +143,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
9680 return flags;
9681 }
9682
9683+extern void gr_handle_kernel_exploit(void);
9684+
9685 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9686 int signr)
9687 {
9688@@ -191,6 +194,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
9689 panic("Fatal exception in interrupt");
9690 if (panic_on_oops)
9691 panic("Fatal exception");
9692+
9693+ gr_handle_kernel_exploit();
9694+
9695 do_exit(signr);
9696 }
9697
9698@@ -1137,6 +1143,26 @@ void __kprobes program_check_exception(struct pt_regs *regs)
9699 enum ctx_state prev_state = exception_enter();
9700 unsigned int reason = get_reason(regs);
9701
9702+#ifdef CONFIG_PAX_REFCOUNT
9703+ unsigned int bkpt;
9704+ const struct exception_table_entry *entry;
9705+
9706+ if (reason & REASON_ILLEGAL) {
9707+ /* Check if PaX bad instruction */
9708+ if (!probe_kernel_address(regs->nip, bkpt) && bkpt == 0xc00b00) {
9709+ current->thread.trap_nr = 0;
9710+ pax_report_refcount_overflow(regs);
9711+ /* fixup_exception() for PowerPC does not exist, simulate its job */
9712+ if ((entry = search_exception_tables(regs->nip)) != NULL) {
9713+ regs->nip = entry->fixup;
9714+ return;
9715+ }
9716+ /* fixup_exception() could not handle */
9717+ goto bail;
9718+ }
9719+ }
9720+#endif
9721+
9722 /* We can now get here via a FP Unavailable exception if the core
9723 * has no FPU, in that case the reason flags will be 0 */
9724
9725diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
9726index f174351..5722009 100644
9727--- a/arch/powerpc/kernel/vdso.c
9728+++ b/arch/powerpc/kernel/vdso.c
9729@@ -35,6 +35,7 @@
9730 #include <asm/vdso.h>
9731 #include <asm/vdso_datapage.h>
9732 #include <asm/setup.h>
9733+#include <asm/mman.h>
9734
9735 #undef DEBUG
9736
9737@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9738 vdso_base = VDSO32_MBASE;
9739 #endif
9740
9741- current->mm->context.vdso_base = 0;
9742+ current->mm->context.vdso_base = ~0UL;
9743
9744 /* vDSO has a problem and was disabled, just don't "enable" it for the
9745 * process
9746@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
9747 vdso_base = get_unmapped_area(NULL, vdso_base,
9748 (vdso_pages << PAGE_SHIFT) +
9749 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
9750- 0, 0);
9751+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
9752 if (IS_ERR_VALUE(vdso_base)) {
9753 rc = vdso_base;
9754 goto fail_mmapsem;
9755diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
9756index 4c79284..0e462c3 100644
9757--- a/arch/powerpc/kvm/powerpc.c
9758+++ b/arch/powerpc/kvm/powerpc.c
9759@@ -1338,7 +1338,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
9760 }
9761 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
9762
9763-int kvm_arch_init(void *opaque)
9764+int kvm_arch_init(const void *opaque)
9765 {
9766 return 0;
9767 }
9768diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
9769index 5eea6f3..5d10396 100644
9770--- a/arch/powerpc/lib/usercopy_64.c
9771+++ b/arch/powerpc/lib/usercopy_64.c
9772@@ -9,22 +9,6 @@
9773 #include <linux/module.h>
9774 #include <asm/uaccess.h>
9775
9776-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9777-{
9778- if (likely(access_ok(VERIFY_READ, from, n)))
9779- n = __copy_from_user(to, from, n);
9780- else
9781- memset(to, 0, n);
9782- return n;
9783-}
9784-
9785-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9786-{
9787- if (likely(access_ok(VERIFY_WRITE, to, n)))
9788- n = __copy_to_user(to, from, n);
9789- return n;
9790-}
9791-
9792 unsigned long copy_in_user(void __user *to, const void __user *from,
9793 unsigned long n)
9794 {
9795@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
9796 return n;
9797 }
9798
9799-EXPORT_SYMBOL(copy_from_user);
9800-EXPORT_SYMBOL(copy_to_user);
9801 EXPORT_SYMBOL(copy_in_user);
9802
9803diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
9804index 51ab9e7..7d3c78b 100644
9805--- a/arch/powerpc/mm/fault.c
9806+++ b/arch/powerpc/mm/fault.c
9807@@ -33,6 +33,10 @@
9808 #include <linux/magic.h>
9809 #include <linux/ratelimit.h>
9810 #include <linux/context_tracking.h>
9811+#include <linux/slab.h>
9812+#include <linux/pagemap.h>
9813+#include <linux/compiler.h>
9814+#include <linux/unistd.h>
9815
9816 #include <asm/firmware.h>
9817 #include <asm/page.h>
9818@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
9819 }
9820 #endif
9821
9822+#ifdef CONFIG_PAX_PAGEEXEC
9823+/*
9824+ * PaX: decide what to do with offenders (regs->nip = fault address)
9825+ *
9826+ * returns 1 when task should be killed
9827+ */
9828+static int pax_handle_fetch_fault(struct pt_regs *regs)
9829+{
9830+ return 1;
9831+}
9832+
9833+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9834+{
9835+ unsigned long i;
9836+
9837+ printk(KERN_ERR "PAX: bytes at PC: ");
9838+ for (i = 0; i < 5; i++) {
9839+ unsigned int c;
9840+ if (get_user(c, (unsigned int __user *)pc+i))
9841+ printk(KERN_CONT "???????? ");
9842+ else
9843+ printk(KERN_CONT "%08x ", c);
9844+ }
9845+ printk("\n");
9846+}
9847+#endif
9848+
9849 /*
9850 * Check whether the instruction at regs->nip is a store using
9851 * an update addressing form which will update r1.
9852@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
9853 * indicate errors in DSISR but can validly be set in SRR1.
9854 */
9855 if (trap == 0x400)
9856- error_code &= 0x48200000;
9857+ error_code &= 0x58200000;
9858 else
9859 is_write = error_code & DSISR_ISSTORE;
9860 #else
9861@@ -378,7 +409,7 @@ good_area:
9862 * "undefined". Of those that can be set, this is the only
9863 * one which seems bad.
9864 */
9865- if (error_code & 0x10000000)
9866+ if (error_code & DSISR_GUARDED)
9867 /* Guarded storage error. */
9868 goto bad_area;
9869 #endif /* CONFIG_8xx */
9870@@ -393,7 +424,7 @@ good_area:
9871 * processors use the same I/D cache coherency mechanism
9872 * as embedded.
9873 */
9874- if (error_code & DSISR_PROTFAULT)
9875+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
9876 goto bad_area;
9877 #endif /* CONFIG_PPC_STD_MMU */
9878
9879@@ -483,6 +514,23 @@ bad_area:
9880 bad_area_nosemaphore:
9881 /* User mode accesses cause a SIGSEGV */
9882 if (user_mode(regs)) {
9883+
9884+#ifdef CONFIG_PAX_PAGEEXEC
9885+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
9886+#ifdef CONFIG_PPC_STD_MMU
9887+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
9888+#else
9889+ if (is_exec && regs->nip == address) {
9890+#endif
9891+ switch (pax_handle_fetch_fault(regs)) {
9892+ }
9893+
9894+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
9895+ do_group_exit(SIGKILL);
9896+ }
9897+ }
9898+#endif
9899+
9900 _exception(SIGSEGV, regs, code, address);
9901 goto bail;
9902 }
9903diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9904index cb8bdbe..cde4bc7 100644
9905--- a/arch/powerpc/mm/mmap.c
9906+++ b/arch/powerpc/mm/mmap.c
9907@@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9908 return sysctl_legacy_va_layout;
9909 }
9910
9911-static unsigned long mmap_rnd(void)
9912+static unsigned long mmap_rnd(struct mm_struct *mm)
9913 {
9914 unsigned long rnd = 0;
9915
9916+#ifdef CONFIG_PAX_RANDMMAP
9917+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9918+#endif
9919+
9920 if (current->flags & PF_RANDOMIZE) {
9921 /* 8MB for 32bit, 1GB for 64bit */
9922 if (is_32bit_task())
9923@@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9924 return rnd << PAGE_SHIFT;
9925 }
9926
9927-static inline unsigned long mmap_base(void)
9928+static inline unsigned long mmap_base(struct mm_struct *mm)
9929 {
9930 unsigned long gap = rlimit(RLIMIT_STACK);
9931
9932@@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9933 else if (gap > MAX_GAP)
9934 gap = MAX_GAP;
9935
9936- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9937+ return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9938 }
9939
9940 /*
9941@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9942 */
9943 if (mmap_is_legacy()) {
9944 mm->mmap_base = TASK_UNMAPPED_BASE;
9945+
9946+#ifdef CONFIG_PAX_RANDMMAP
9947+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9948+ mm->mmap_base += mm->delta_mmap;
9949+#endif
9950+
9951 mm->get_unmapped_area = arch_get_unmapped_area;
9952 } else {
9953- mm->mmap_base = mmap_base();
9954+ mm->mmap_base = mmap_base(mm);
9955+
9956+#ifdef CONFIG_PAX_RANDMMAP
9957+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9958+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9959+#endif
9960+
9961 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9962 }
9963 }
9964diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9965index b0c75cc..ef7fb93 100644
9966--- a/arch/powerpc/mm/slice.c
9967+++ b/arch/powerpc/mm/slice.c
9968@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9969 if ((mm->task_size - len) < addr)
9970 return 0;
9971 vma = find_vma(mm, addr);
9972- return (!vma || (addr + len) <= vma->vm_start);
9973+ return check_heap_stack_gap(vma, addr, len, 0);
9974 }
9975
9976 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9977@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9978 info.align_offset = 0;
9979
9980 addr = TASK_UNMAPPED_BASE;
9981+
9982+#ifdef CONFIG_PAX_RANDMMAP
9983+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9984+ addr += mm->delta_mmap;
9985+#endif
9986+
9987 while (addr < TASK_SIZE) {
9988 info.low_limit = addr;
9989 if (!slice_scan_available(addr, available, 1, &addr))
9990@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9991 if (fixed && addr > (mm->task_size - len))
9992 return -ENOMEM;
9993
9994+#ifdef CONFIG_PAX_RANDMMAP
9995+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9996+ addr = 0;
9997+#endif
9998+
9999 /* If hint, make sure it matches our alignment restrictions */
10000 if (!fixed && addr) {
10001 addr = _ALIGN_UP(addr, 1ul << pshift);
10002diff --git a/arch/powerpc/net/bpf_jit_comp.c b/arch/powerpc/net/bpf_jit_comp.c
10003index 3afa6f4..40c53ff 100644
10004--- a/arch/powerpc/net/bpf_jit_comp.c
10005+++ b/arch/powerpc/net/bpf_jit_comp.c
10006@@ -697,5 +697,6 @@ void bpf_jit_free(struct bpf_prog *fp)
10007 {
10008 if (fp->jited)
10009 module_free(NULL, fp->bpf_func);
10010- kfree(fp);
10011+
10012+ bpf_prog_unlock_free(fp);
10013 }
10014diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
10015index 4278acf..67fd0e6 100644
10016--- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
10017+++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
10018@@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
10019 }
10020
10021 static struct pci_ops scc_pciex_pci_ops = {
10022- scc_pciex_read_config,
10023- scc_pciex_write_config,
10024+ .read = scc_pciex_read_config,
10025+ .write = scc_pciex_write_config,
10026 };
10027
10028 static void pciex_clear_intr_all(unsigned int __iomem *base)
10029diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
10030index d966bbe..372124a 100644
10031--- a/arch/powerpc/platforms/cell/spufs/file.c
10032+++ b/arch/powerpc/platforms/cell/spufs/file.c
10033@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10034 return VM_FAULT_NOPAGE;
10035 }
10036
10037-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
10038+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
10039 unsigned long address,
10040- void *buf, int len, int write)
10041+ void *buf, size_t len, int write)
10042 {
10043 struct spu_context *ctx = vma->vm_file->private_data;
10044 unsigned long offset = address - vma->vm_start;
10045diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
10046index fa934fe..c296056 100644
10047--- a/arch/s390/include/asm/atomic.h
10048+++ b/arch/s390/include/asm/atomic.h
10049@@ -412,4 +412,14 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
10050 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
10051 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10052
10053+#define atomic64_read_unchecked(v) atomic64_read(v)
10054+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
10055+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
10056+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
10057+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
10058+#define atomic64_inc_unchecked(v) atomic64_inc(v)
10059+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
10060+#define atomic64_dec_unchecked(v) atomic64_dec(v)
10061+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
10062+
10063 #endif /* __ARCH_S390_ATOMIC__ */
10064diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
10065index 19ff956..8d39cb1 100644
10066--- a/arch/s390/include/asm/barrier.h
10067+++ b/arch/s390/include/asm/barrier.h
10068@@ -37,7 +37,7 @@
10069 do { \
10070 compiletime_assert_atomic_type(*p); \
10071 barrier(); \
10072- ACCESS_ONCE(*p) = (v); \
10073+ ACCESS_ONCE_RW(*p) = (v); \
10074 } while (0)
10075
10076 #define smp_load_acquire(p) \
10077diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
10078index 4d7ccac..d03d0ad 100644
10079--- a/arch/s390/include/asm/cache.h
10080+++ b/arch/s390/include/asm/cache.h
10081@@ -9,8 +9,10 @@
10082 #ifndef __ARCH_S390_CACHE_H
10083 #define __ARCH_S390_CACHE_H
10084
10085-#define L1_CACHE_BYTES 256
10086+#include <linux/const.h>
10087+
10088 #define L1_CACHE_SHIFT 8
10089+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10090 #define NET_SKB_PAD 32
10091
10092 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10093diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
10094index 78f4f87..598ce39 100644
10095--- a/arch/s390/include/asm/elf.h
10096+++ b/arch/s390/include/asm/elf.h
10097@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
10098 the loader. We need to make sure that it is out of the way of the program
10099 that it will "exec", and that there is sufficient room for the brk. */
10100
10101-extern unsigned long randomize_et_dyn(unsigned long base);
10102-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
10103+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
10104+
10105+#ifdef CONFIG_PAX_ASLR
10106+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
10107+
10108+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
10109+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
10110+#endif
10111
10112 /* This yields a mask that user programs can use to figure out what
10113 instruction set this CPU supports. */
10114@@ -222,9 +228,6 @@ struct linux_binprm;
10115 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
10116 int arch_setup_additional_pages(struct linux_binprm *, int);
10117
10118-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10119-#define arch_randomize_brk arch_randomize_brk
10120-
10121 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
10122
10123 #endif
10124diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
10125index c4a93d6..4d2a9b4 100644
10126--- a/arch/s390/include/asm/exec.h
10127+++ b/arch/s390/include/asm/exec.h
10128@@ -7,6 +7,6 @@
10129 #ifndef __ASM_EXEC_H
10130 #define __ASM_EXEC_H
10131
10132-extern unsigned long arch_align_stack(unsigned long sp);
10133+#define arch_align_stack(x) ((x) & ~0xfUL)
10134
10135 #endif /* __ASM_EXEC_H */
10136diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
10137index cd4c68e..6764641 100644
10138--- a/arch/s390/include/asm/uaccess.h
10139+++ b/arch/s390/include/asm/uaccess.h
10140@@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
10141 __range_ok((unsigned long)(addr), (size)); \
10142 })
10143
10144+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
10145 #define access_ok(type, addr, size) __access_ok(addr, size)
10146
10147 /*
10148@@ -275,6 +276,10 @@ static inline unsigned long __must_check
10149 copy_to_user(void __user *to, const void *from, unsigned long n)
10150 {
10151 might_fault();
10152+
10153+ if ((long)n < 0)
10154+ return n;
10155+
10156 return __copy_to_user(to, from, n);
10157 }
10158
10159@@ -303,10 +308,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
10160 static inline unsigned long __must_check
10161 copy_from_user(void *to, const void __user *from, unsigned long n)
10162 {
10163- unsigned int sz = __compiletime_object_size(to);
10164+ size_t sz = __compiletime_object_size(to);
10165
10166 might_fault();
10167- if (unlikely(sz != -1 && sz < n)) {
10168+
10169+ if ((long)n < 0)
10170+ return n;
10171+
10172+ if (unlikely(sz != (size_t)-1 && sz < n)) {
10173 copy_from_user_overflow();
10174 return n;
10175 }
10176diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
10177index b89b591..fd9609d 100644
10178--- a/arch/s390/kernel/module.c
10179+++ b/arch/s390/kernel/module.c
10180@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
10181
10182 /* Increase core size by size of got & plt and set start
10183 offsets for got and plt. */
10184- me->core_size = ALIGN(me->core_size, 4);
10185- me->arch.got_offset = me->core_size;
10186- me->core_size += me->arch.got_size;
10187- me->arch.plt_offset = me->core_size;
10188- me->core_size += me->arch.plt_size;
10189+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
10190+ me->arch.got_offset = me->core_size_rw;
10191+ me->core_size_rw += me->arch.got_size;
10192+ me->arch.plt_offset = me->core_size_rx;
10193+ me->core_size_rx += me->arch.plt_size;
10194 return 0;
10195 }
10196
10197@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10198 if (info->got_initialized == 0) {
10199 Elf_Addr *gotent;
10200
10201- gotent = me->module_core + me->arch.got_offset +
10202+ gotent = me->module_core_rw + me->arch.got_offset +
10203 info->got_offset;
10204 *gotent = val;
10205 info->got_initialized = 1;
10206@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10207 rc = apply_rela_bits(loc, val, 0, 64, 0);
10208 else if (r_type == R_390_GOTENT ||
10209 r_type == R_390_GOTPLTENT) {
10210- val += (Elf_Addr) me->module_core - loc;
10211+ val += (Elf_Addr) me->module_core_rw - loc;
10212 rc = apply_rela_bits(loc, val, 1, 32, 1);
10213 }
10214 break;
10215@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10216 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
10217 if (info->plt_initialized == 0) {
10218 unsigned int *ip;
10219- ip = me->module_core + me->arch.plt_offset +
10220+ ip = me->module_core_rx + me->arch.plt_offset +
10221 info->plt_offset;
10222 #ifndef CONFIG_64BIT
10223 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
10224@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10225 val - loc + 0xffffUL < 0x1ffffeUL) ||
10226 (r_type == R_390_PLT32DBL &&
10227 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
10228- val = (Elf_Addr) me->module_core +
10229+ val = (Elf_Addr) me->module_core_rx +
10230 me->arch.plt_offset +
10231 info->plt_offset;
10232 val += rela->r_addend - loc;
10233@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10234 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
10235 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
10236 val = val + rela->r_addend -
10237- ((Elf_Addr) me->module_core + me->arch.got_offset);
10238+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
10239 if (r_type == R_390_GOTOFF16)
10240 rc = apply_rela_bits(loc, val, 0, 16, 0);
10241 else if (r_type == R_390_GOTOFF32)
10242@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
10243 break;
10244 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
10245 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
10246- val = (Elf_Addr) me->module_core + me->arch.got_offset +
10247+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
10248 rela->r_addend - loc;
10249 if (r_type == R_390_GOTPC)
10250 rc = apply_rela_bits(loc, val, 1, 32, 0);
10251diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
10252index 93b9ca4..4ea1454 100644
10253--- a/arch/s390/kernel/process.c
10254+++ b/arch/s390/kernel/process.c
10255@@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
10256 }
10257 return 0;
10258 }
10259-
10260-unsigned long arch_align_stack(unsigned long sp)
10261-{
10262- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10263- sp -= get_random_int() & ~PAGE_MASK;
10264- return sp & ~0xf;
10265-}
10266-
10267-static inline unsigned long brk_rnd(void)
10268-{
10269- /* 8MB for 32bit, 1GB for 64bit */
10270- if (is_32bit_task())
10271- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
10272- else
10273- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
10274-}
10275-
10276-unsigned long arch_randomize_brk(struct mm_struct *mm)
10277-{
10278- unsigned long ret;
10279-
10280- ret = PAGE_ALIGN(mm->brk + brk_rnd());
10281- return (ret > mm->brk) ? ret : mm->brk;
10282-}
10283-
10284-unsigned long randomize_et_dyn(unsigned long base)
10285-{
10286- unsigned long ret;
10287-
10288- if (!(current->flags & PF_RANDOMIZE))
10289- return base;
10290- ret = PAGE_ALIGN(base + brk_rnd());
10291- return (ret > base) ? ret : base;
10292-}
10293diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
10294index 9b436c2..54fbf0a 100644
10295--- a/arch/s390/mm/mmap.c
10296+++ b/arch/s390/mm/mmap.c
10297@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10298 */
10299 if (mmap_is_legacy()) {
10300 mm->mmap_base = mmap_base_legacy();
10301+
10302+#ifdef CONFIG_PAX_RANDMMAP
10303+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10304+ mm->mmap_base += mm->delta_mmap;
10305+#endif
10306+
10307 mm->get_unmapped_area = arch_get_unmapped_area;
10308 } else {
10309 mm->mmap_base = mmap_base();
10310+
10311+#ifdef CONFIG_PAX_RANDMMAP
10312+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10313+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10314+#endif
10315+
10316 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10317 }
10318 }
10319@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10320 */
10321 if (mmap_is_legacy()) {
10322 mm->mmap_base = mmap_base_legacy();
10323+
10324+#ifdef CONFIG_PAX_RANDMMAP
10325+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10326+ mm->mmap_base += mm->delta_mmap;
10327+#endif
10328+
10329 mm->get_unmapped_area = s390_get_unmapped_area;
10330 } else {
10331 mm->mmap_base = mmap_base();
10332+
10333+#ifdef CONFIG_PAX_RANDMMAP
10334+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10335+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10336+#endif
10337+
10338 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
10339 }
10340 }
10341diff --git a/arch/s390/net/bpf_jit_comp.c b/arch/s390/net/bpf_jit_comp.c
10342index 61e45b7..f2833c5 100644
10343--- a/arch/s390/net/bpf_jit_comp.c
10344+++ b/arch/s390/net/bpf_jit_comp.c
10345@@ -887,5 +887,5 @@ void bpf_jit_free(struct bpf_prog *fp)
10346 module_free(NULL, header);
10347
10348 free_filter:
10349- kfree(fp);
10350+ bpf_prog_unlock_free(fp);
10351 }
10352diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
10353index ae3d59f..f65f075 100644
10354--- a/arch/score/include/asm/cache.h
10355+++ b/arch/score/include/asm/cache.h
10356@@ -1,7 +1,9 @@
10357 #ifndef _ASM_SCORE_CACHE_H
10358 #define _ASM_SCORE_CACHE_H
10359
10360+#include <linux/const.h>
10361+
10362 #define L1_CACHE_SHIFT 4
10363-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10364+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10365
10366 #endif /* _ASM_SCORE_CACHE_H */
10367diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
10368index f9f3cd5..58ff438 100644
10369--- a/arch/score/include/asm/exec.h
10370+++ b/arch/score/include/asm/exec.h
10371@@ -1,6 +1,6 @@
10372 #ifndef _ASM_SCORE_EXEC_H
10373 #define _ASM_SCORE_EXEC_H
10374
10375-extern unsigned long arch_align_stack(unsigned long sp);
10376+#define arch_align_stack(x) (x)
10377
10378 #endif /* _ASM_SCORE_EXEC_H */
10379diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
10380index a1519ad3..e8ac1ff 100644
10381--- a/arch/score/kernel/process.c
10382+++ b/arch/score/kernel/process.c
10383@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
10384
10385 return task_pt_regs(task)->cp0_epc;
10386 }
10387-
10388-unsigned long arch_align_stack(unsigned long sp)
10389-{
10390- return sp;
10391-}
10392diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
10393index ef9e555..331bd29 100644
10394--- a/arch/sh/include/asm/cache.h
10395+++ b/arch/sh/include/asm/cache.h
10396@@ -9,10 +9,11 @@
10397 #define __ASM_SH_CACHE_H
10398 #ifdef __KERNEL__
10399
10400+#include <linux/const.h>
10401 #include <linux/init.h>
10402 #include <cpu/cache.h>
10403
10404-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10405+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10406
10407 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10408
10409diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
10410index 6777177..cb5e44f 100644
10411--- a/arch/sh/mm/mmap.c
10412+++ b/arch/sh/mm/mmap.c
10413@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
10414 struct mm_struct *mm = current->mm;
10415 struct vm_area_struct *vma;
10416 int do_colour_align;
10417+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10418 struct vm_unmapped_area_info info;
10419
10420 if (flags & MAP_FIXED) {
10421@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
10422 if (filp || (flags & MAP_SHARED))
10423 do_colour_align = 1;
10424
10425+#ifdef CONFIG_PAX_RANDMMAP
10426+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10427+#endif
10428+
10429 if (addr) {
10430 if (do_colour_align)
10431 addr = COLOUR_ALIGN(addr, pgoff);
10432@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
10433 addr = PAGE_ALIGN(addr);
10434
10435 vma = find_vma(mm, addr);
10436- if (TASK_SIZE - len >= addr &&
10437- (!vma || addr + len <= vma->vm_start))
10438+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10439 return addr;
10440 }
10441
10442 info.flags = 0;
10443 info.length = len;
10444- info.low_limit = TASK_UNMAPPED_BASE;
10445+ info.low_limit = mm->mmap_base;
10446 info.high_limit = TASK_SIZE;
10447 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
10448 info.align_offset = pgoff << PAGE_SHIFT;
10449@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10450 struct mm_struct *mm = current->mm;
10451 unsigned long addr = addr0;
10452 int do_colour_align;
10453+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10454 struct vm_unmapped_area_info info;
10455
10456 if (flags & MAP_FIXED) {
10457@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10458 if (filp || (flags & MAP_SHARED))
10459 do_colour_align = 1;
10460
10461+#ifdef CONFIG_PAX_RANDMMAP
10462+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10463+#endif
10464+
10465 /* requesting a specific address */
10466 if (addr) {
10467 if (do_colour_align)
10468@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10469 addr = PAGE_ALIGN(addr);
10470
10471 vma = find_vma(mm, addr);
10472- if (TASK_SIZE - len >= addr &&
10473- (!vma || addr + len <= vma->vm_start))
10474+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10475 return addr;
10476 }
10477
10478@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10479 VM_BUG_ON(addr != -ENOMEM);
10480 info.flags = 0;
10481 info.low_limit = TASK_UNMAPPED_BASE;
10482+
10483+#ifdef CONFIG_PAX_RANDMMAP
10484+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10485+ info.low_limit += mm->delta_mmap;
10486+#endif
10487+
10488 info.high_limit = TASK_SIZE;
10489 addr = vm_unmapped_area(&info);
10490 }
10491diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
10492index bb894c8..8141d5c 100644
10493--- a/arch/sparc/include/asm/atomic_64.h
10494+++ b/arch/sparc/include/asm/atomic_64.h
10495@@ -15,18 +15,40 @@
10496 #define ATOMIC64_INIT(i) { (i) }
10497
10498 #define atomic_read(v) (*(volatile int *)&(v)->counter)
10499+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
10500+{
10501+ return v->counter;
10502+}
10503 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
10504+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
10505+{
10506+ return v->counter;
10507+}
10508
10509 #define atomic_set(v, i) (((v)->counter) = i)
10510+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
10511+{
10512+ v->counter = i;
10513+}
10514 #define atomic64_set(v, i) (((v)->counter) = i)
10515+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
10516+{
10517+ v->counter = i;
10518+}
10519
10520 void atomic_add(int, atomic_t *);
10521+void atomic_add_unchecked(int, atomic_unchecked_t *);
10522 void atomic64_add(long, atomic64_t *);
10523+void atomic64_add_unchecked(long, atomic64_unchecked_t *);
10524 void atomic_sub(int, atomic_t *);
10525+void atomic_sub_unchecked(int, atomic_unchecked_t *);
10526 void atomic64_sub(long, atomic64_t *);
10527+void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
10528
10529 int atomic_add_ret(int, atomic_t *);
10530+int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
10531 long atomic64_add_ret(long, atomic64_t *);
10532+long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
10533 int atomic_sub_ret(int, atomic_t *);
10534 long atomic64_sub_ret(long, atomic64_t *);
10535
10536@@ -34,13 +56,29 @@ long atomic64_sub_ret(long, atomic64_t *);
10537 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
10538
10539 #define atomic_inc_return(v) atomic_add_ret(1, v)
10540+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
10541+{
10542+ return atomic_add_ret_unchecked(1, v);
10543+}
10544 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
10545+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10546+{
10547+ return atomic64_add_ret_unchecked(1, v);
10548+}
10549
10550 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
10551 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
10552
10553 #define atomic_add_return(i, v) atomic_add_ret(i, v)
10554+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
10555+{
10556+ return atomic_add_ret_unchecked(i, v);
10557+}
10558 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
10559+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10560+{
10561+ return atomic64_add_ret_unchecked(i, v);
10562+}
10563
10564 /*
10565 * atomic_inc_and_test - increment and test
10566@@ -51,6 +89,10 @@ long atomic64_sub_ret(long, atomic64_t *);
10567 * other cases.
10568 */
10569 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
10570+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
10571+{
10572+ return atomic_inc_return_unchecked(v) == 0;
10573+}
10574 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
10575
10576 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
10577@@ -60,25 +102,60 @@ long atomic64_sub_ret(long, atomic64_t *);
10578 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
10579
10580 #define atomic_inc(v) atomic_add(1, v)
10581+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
10582+{
10583+ atomic_add_unchecked(1, v);
10584+}
10585 #define atomic64_inc(v) atomic64_add(1, v)
10586+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
10587+{
10588+ atomic64_add_unchecked(1, v);
10589+}
10590
10591 #define atomic_dec(v) atomic_sub(1, v)
10592+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
10593+{
10594+ atomic_sub_unchecked(1, v);
10595+}
10596 #define atomic64_dec(v) atomic64_sub(1, v)
10597+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
10598+{
10599+ atomic64_sub_unchecked(1, v);
10600+}
10601
10602 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
10603 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
10604
10605 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
10606+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
10607+{
10608+ return cmpxchg(&v->counter, old, new);
10609+}
10610 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
10611+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
10612+{
10613+ return xchg(&v->counter, new);
10614+}
10615
10616 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10617 {
10618- int c, old;
10619+ int c, old, new;
10620 c = atomic_read(v);
10621 for (;;) {
10622- if (unlikely(c == (u)))
10623+ if (unlikely(c == u))
10624 break;
10625- old = atomic_cmpxchg((v), c, c + (a));
10626+
10627+ asm volatile("addcc %2, %0, %0\n"
10628+
10629+#ifdef CONFIG_PAX_REFCOUNT
10630+ "tvs %%icc, 6\n"
10631+#endif
10632+
10633+ : "=r" (new)
10634+ : "0" (c), "ir" (a)
10635+ : "cc");
10636+
10637+ old = atomic_cmpxchg(v, c, new);
10638 if (likely(old == c))
10639 break;
10640 c = old;
10641@@ -89,20 +166,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
10642 #define atomic64_cmpxchg(v, o, n) \
10643 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
10644 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
10645+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
10646+{
10647+ return xchg(&v->counter, new);
10648+}
10649
10650 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10651 {
10652- long c, old;
10653+ long c, old, new;
10654 c = atomic64_read(v);
10655 for (;;) {
10656- if (unlikely(c == (u)))
10657+ if (unlikely(c == u))
10658 break;
10659- old = atomic64_cmpxchg((v), c, c + (a));
10660+
10661+ asm volatile("addcc %2, %0, %0\n"
10662+
10663+#ifdef CONFIG_PAX_REFCOUNT
10664+ "tvs %%xcc, 6\n"
10665+#endif
10666+
10667+ : "=r" (new)
10668+ : "0" (c), "ir" (a)
10669+ : "cc");
10670+
10671+ old = atomic64_cmpxchg(v, c, new);
10672 if (likely(old == c))
10673 break;
10674 c = old;
10675 }
10676- return c != (u);
10677+ return c != u;
10678 }
10679
10680 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10681diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
10682index 305dcc3..7835030 100644
10683--- a/arch/sparc/include/asm/barrier_64.h
10684+++ b/arch/sparc/include/asm/barrier_64.h
10685@@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
10686 do { \
10687 compiletime_assert_atomic_type(*p); \
10688 barrier(); \
10689- ACCESS_ONCE(*p) = (v); \
10690+ ACCESS_ONCE_RW(*p) = (v); \
10691 } while (0)
10692
10693 #define smp_load_acquire(p) \
10694diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
10695index 5bb6991..5c2132e 100644
10696--- a/arch/sparc/include/asm/cache.h
10697+++ b/arch/sparc/include/asm/cache.h
10698@@ -7,10 +7,12 @@
10699 #ifndef _SPARC_CACHE_H
10700 #define _SPARC_CACHE_H
10701
10702+#include <linux/const.h>
10703+
10704 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
10705
10706 #define L1_CACHE_SHIFT 5
10707-#define L1_CACHE_BYTES 32
10708+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10709
10710 #ifdef CONFIG_SPARC32
10711 #define SMP_CACHE_BYTES_SHIFT 5
10712diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
10713index a24e41f..47677ff 100644
10714--- a/arch/sparc/include/asm/elf_32.h
10715+++ b/arch/sparc/include/asm/elf_32.h
10716@@ -114,6 +114,13 @@ typedef struct {
10717
10718 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
10719
10720+#ifdef CONFIG_PAX_ASLR
10721+#define PAX_ELF_ET_DYN_BASE 0x10000UL
10722+
10723+#define PAX_DELTA_MMAP_LEN 16
10724+#define PAX_DELTA_STACK_LEN 16
10725+#endif
10726+
10727 /* This yields a mask that user programs can use to figure out what
10728 instruction set this cpu supports. This can NOT be done in userspace
10729 on Sparc. */
10730diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
10731index 370ca1e..d4f4a98 100644
10732--- a/arch/sparc/include/asm/elf_64.h
10733+++ b/arch/sparc/include/asm/elf_64.h
10734@@ -189,6 +189,13 @@ typedef struct {
10735 #define ELF_ET_DYN_BASE 0x0000010000000000UL
10736 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
10737
10738+#ifdef CONFIG_PAX_ASLR
10739+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
10740+
10741+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
10742+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
10743+#endif
10744+
10745 extern unsigned long sparc64_elf_hwcap;
10746 #define ELF_HWCAP sparc64_elf_hwcap
10747
10748diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
10749index a3890da..f6a408e 100644
10750--- a/arch/sparc/include/asm/pgalloc_32.h
10751+++ b/arch/sparc/include/asm/pgalloc_32.h
10752@@ -35,6 +35,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
10753 }
10754
10755 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
10756+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
10757
10758 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
10759 unsigned long address)
10760diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
10761index 5e31871..b71c9d7 100644
10762--- a/arch/sparc/include/asm/pgalloc_64.h
10763+++ b/arch/sparc/include/asm/pgalloc_64.h
10764@@ -38,6 +38,7 @@ static inline void __pud_populate(pud_t *pud, pmd_t *pmd)
10765 }
10766
10767 #define pud_populate(MM, PUD, PMD) __pud_populate(PUD, PMD)
10768+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
10769
10770 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
10771 {
10772diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
10773index 59ba6f6..4518128 100644
10774--- a/arch/sparc/include/asm/pgtable.h
10775+++ b/arch/sparc/include/asm/pgtable.h
10776@@ -5,4 +5,8 @@
10777 #else
10778 #include <asm/pgtable_32.h>
10779 #endif
10780+
10781+#define ktla_ktva(addr) (addr)
10782+#define ktva_ktla(addr) (addr)
10783+
10784 #endif
10785diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
10786index b9b91ae..950b91e 100644
10787--- a/arch/sparc/include/asm/pgtable_32.h
10788+++ b/arch/sparc/include/asm/pgtable_32.h
10789@@ -51,6 +51,9 @@ unsigned long __init bootmem_init(unsigned long *pages_avail);
10790 #define PAGE_SHARED SRMMU_PAGE_SHARED
10791 #define PAGE_COPY SRMMU_PAGE_COPY
10792 #define PAGE_READONLY SRMMU_PAGE_RDONLY
10793+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
10794+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
10795+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
10796 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
10797
10798 /* Top-level page directory - dummy used by init-mm.
10799@@ -63,18 +66,18 @@ extern unsigned long ptr_in_current_pgd;
10800
10801 /* xwr */
10802 #define __P000 PAGE_NONE
10803-#define __P001 PAGE_READONLY
10804-#define __P010 PAGE_COPY
10805-#define __P011 PAGE_COPY
10806+#define __P001 PAGE_READONLY_NOEXEC
10807+#define __P010 PAGE_COPY_NOEXEC
10808+#define __P011 PAGE_COPY_NOEXEC
10809 #define __P100 PAGE_READONLY
10810 #define __P101 PAGE_READONLY
10811 #define __P110 PAGE_COPY
10812 #define __P111 PAGE_COPY
10813
10814 #define __S000 PAGE_NONE
10815-#define __S001 PAGE_READONLY
10816-#define __S010 PAGE_SHARED
10817-#define __S011 PAGE_SHARED
10818+#define __S001 PAGE_READONLY_NOEXEC
10819+#define __S010 PAGE_SHARED_NOEXEC
10820+#define __S011 PAGE_SHARED_NOEXEC
10821 #define __S100 PAGE_READONLY
10822 #define __S101 PAGE_READONLY
10823 #define __S110 PAGE_SHARED
10824diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
10825index 79da178..c2eede8 100644
10826--- a/arch/sparc/include/asm/pgtsrmmu.h
10827+++ b/arch/sparc/include/asm/pgtsrmmu.h
10828@@ -115,6 +115,11 @@
10829 SRMMU_EXEC | SRMMU_REF)
10830 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
10831 SRMMU_EXEC | SRMMU_REF)
10832+
10833+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
10834+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10835+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
10836+
10837 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
10838 SRMMU_DIRTY | SRMMU_REF)
10839
10840diff --git a/arch/sparc/include/asm/setup.h b/arch/sparc/include/asm/setup.h
10841index 29d64b1..4272fe8 100644
10842--- a/arch/sparc/include/asm/setup.h
10843+++ b/arch/sparc/include/asm/setup.h
10844@@ -55,8 +55,8 @@ int handle_ldf_stq(u32 insn, struct pt_regs *regs);
10845 void handle_ld_nf(u32 insn, struct pt_regs *regs);
10846
10847 /* init_64.c */
10848-extern atomic_t dcpage_flushes;
10849-extern atomic_t dcpage_flushes_xcall;
10850+extern atomic_unchecked_t dcpage_flushes;
10851+extern atomic_unchecked_t dcpage_flushes_xcall;
10852
10853 extern int sysctl_tsb_ratio;
10854 #endif
10855diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
10856index 9689176..63c18ea 100644
10857--- a/arch/sparc/include/asm/spinlock_64.h
10858+++ b/arch/sparc/include/asm/spinlock_64.h
10859@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
10860
10861 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
10862
10863-static void inline arch_read_lock(arch_rwlock_t *lock)
10864+static inline void arch_read_lock(arch_rwlock_t *lock)
10865 {
10866 unsigned long tmp1, tmp2;
10867
10868 __asm__ __volatile__ (
10869 "1: ldsw [%2], %0\n"
10870 " brlz,pn %0, 2f\n"
10871-"4: add %0, 1, %1\n"
10872+"4: addcc %0, 1, %1\n"
10873+
10874+#ifdef CONFIG_PAX_REFCOUNT
10875+" tvs %%icc, 6\n"
10876+#endif
10877+
10878 " cas [%2], %0, %1\n"
10879 " cmp %0, %1\n"
10880 " bne,pn %%icc, 1b\n"
10881@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
10882 " .previous"
10883 : "=&r" (tmp1), "=&r" (tmp2)
10884 : "r" (lock)
10885- : "memory");
10886+ : "memory", "cc");
10887 }
10888
10889-static int inline arch_read_trylock(arch_rwlock_t *lock)
10890+static inline int arch_read_trylock(arch_rwlock_t *lock)
10891 {
10892 int tmp1, tmp2;
10893
10894@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10895 "1: ldsw [%2], %0\n"
10896 " brlz,a,pn %0, 2f\n"
10897 " mov 0, %0\n"
10898-" add %0, 1, %1\n"
10899+" addcc %0, 1, %1\n"
10900+
10901+#ifdef CONFIG_PAX_REFCOUNT
10902+" tvs %%icc, 6\n"
10903+#endif
10904+
10905 " cas [%2], %0, %1\n"
10906 " cmp %0, %1\n"
10907 " bne,pn %%icc, 1b\n"
10908@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
10909 return tmp1;
10910 }
10911
10912-static void inline arch_read_unlock(arch_rwlock_t *lock)
10913+static inline void arch_read_unlock(arch_rwlock_t *lock)
10914 {
10915 unsigned long tmp1, tmp2;
10916
10917 __asm__ __volatile__(
10918 "1: lduw [%2], %0\n"
10919-" sub %0, 1, %1\n"
10920+" subcc %0, 1, %1\n"
10921+
10922+#ifdef CONFIG_PAX_REFCOUNT
10923+" tvs %%icc, 6\n"
10924+#endif
10925+
10926 " cas [%2], %0, %1\n"
10927 " cmp %0, %1\n"
10928 " bne,pn %%xcc, 1b\n"
10929@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
10930 : "memory");
10931 }
10932
10933-static void inline arch_write_lock(arch_rwlock_t *lock)
10934+static inline void arch_write_lock(arch_rwlock_t *lock)
10935 {
10936 unsigned long mask, tmp1, tmp2;
10937
10938@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10939 : "memory");
10940 }
10941
10942-static void inline arch_write_unlock(arch_rwlock_t *lock)
10943+static inline void arch_write_unlock(arch_rwlock_t *lock)
10944 {
10945 __asm__ __volatile__(
10946 " stw %%g0, [%0]"
10947@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10948 : "memory");
10949 }
10950
10951-static int inline arch_write_trylock(arch_rwlock_t *lock)
10952+static inline int arch_write_trylock(arch_rwlock_t *lock)
10953 {
10954 unsigned long mask, tmp1, tmp2, result;
10955
10956diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10957index 96efa7a..16858bf 100644
10958--- a/arch/sparc/include/asm/thread_info_32.h
10959+++ b/arch/sparc/include/asm/thread_info_32.h
10960@@ -49,6 +49,8 @@ struct thread_info {
10961 unsigned long w_saved;
10962
10963 struct restart_block restart_block;
10964+
10965+ unsigned long lowest_stack;
10966 };
10967
10968 /*
10969diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10970index cc6275c..7eb8e21 100644
10971--- a/arch/sparc/include/asm/thread_info_64.h
10972+++ b/arch/sparc/include/asm/thread_info_64.h
10973@@ -63,6 +63,8 @@ struct thread_info {
10974 struct pt_regs *kern_una_regs;
10975 unsigned int kern_una_insn;
10976
10977+ unsigned long lowest_stack;
10978+
10979 unsigned long fpregs[(7 * 256) / sizeof(unsigned long)]
10980 __attribute__ ((aligned(64)));
10981 };
10982@@ -190,12 +192,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10983 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10984 /* flag bit 4 is available */
10985 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10986-/* flag bit 6 is available */
10987+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10988 #define TIF_32BIT 7 /* 32-bit binary */
10989 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10990 #define TIF_SECCOMP 9 /* secure computing */
10991 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10992 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10993+
10994 /* NOTE: Thread flags >= 12 should be ones we have no interest
10995 * in using in assembly, else we can't use the mask as
10996 * an immediate value in instructions such as andcc.
10997@@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
10998 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10999 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
11000 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
11001+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
11002
11003 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
11004 _TIF_DO_NOTIFY_RESUME_MASK | \
11005 _TIF_NEED_RESCHED)
11006 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
11007
11008+#define _TIF_WORK_SYSCALL \
11009+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
11010+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
11011+
11012+
11013 /*
11014 * Thread-synchronous status.
11015 *
11016diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
11017index bd56c28..4b63d83 100644
11018--- a/arch/sparc/include/asm/uaccess.h
11019+++ b/arch/sparc/include/asm/uaccess.h
11020@@ -1,5 +1,6 @@
11021 #ifndef ___ASM_SPARC_UACCESS_H
11022 #define ___ASM_SPARC_UACCESS_H
11023+
11024 #if defined(__sparc__) && defined(__arch64__)
11025 #include <asm/uaccess_64.h>
11026 #else
11027diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
11028index 9634d08..f55fe4f 100644
11029--- a/arch/sparc/include/asm/uaccess_32.h
11030+++ b/arch/sparc/include/asm/uaccess_32.h
11031@@ -250,27 +250,46 @@ unsigned long __copy_user(void __user *to, const void __user *from, unsigned lon
11032
11033 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
11034 {
11035- if (n && __access_ok((unsigned long) to, n))
11036+ if ((long)n < 0)
11037+ return n;
11038+
11039+ if (n && __access_ok((unsigned long) to, n)) {
11040+ if (!__builtin_constant_p(n))
11041+ check_object_size(from, n, true);
11042 return __copy_user(to, (__force void __user *) from, n);
11043- else
11044+ } else
11045 return n;
11046 }
11047
11048 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
11049 {
11050+ if ((long)n < 0)
11051+ return n;
11052+
11053+ if (!__builtin_constant_p(n))
11054+ check_object_size(from, n, true);
11055+
11056 return __copy_user(to, (__force void __user *) from, n);
11057 }
11058
11059 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
11060 {
11061- if (n && __access_ok((unsigned long) from, n))
11062+ if ((long)n < 0)
11063+ return n;
11064+
11065+ if (n && __access_ok((unsigned long) from, n)) {
11066+ if (!__builtin_constant_p(n))
11067+ check_object_size(to, n, false);
11068 return __copy_user((__force void __user *) to, from, n);
11069- else
11070+ } else
11071 return n;
11072 }
11073
11074 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
11075 {
11076+ if ((long)n < 0)
11077+ return n;
11078+
11079 return __copy_user((__force void __user *) to, from, n);
11080 }
11081
11082diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
11083index c990a5e..f17b9c1 100644
11084--- a/arch/sparc/include/asm/uaccess_64.h
11085+++ b/arch/sparc/include/asm/uaccess_64.h
11086@@ -10,6 +10,7 @@
11087 #include <linux/compiler.h>
11088 #include <linux/string.h>
11089 #include <linux/thread_info.h>
11090+#include <linux/kernel.h>
11091 #include <asm/asi.h>
11092 #include <asm/spitfire.h>
11093 #include <asm-generic/uaccess-unaligned.h>
11094@@ -214,8 +215,15 @@ unsigned long copy_from_user_fixup(void *to, const void __user *from,
11095 static inline unsigned long __must_check
11096 copy_from_user(void *to, const void __user *from, unsigned long size)
11097 {
11098- unsigned long ret = ___copy_from_user(to, from, size);
11099+ unsigned long ret;
11100
11101+ if ((long)size < 0 || size > INT_MAX)
11102+ return size;
11103+
11104+ if (!__builtin_constant_p(size))
11105+ check_object_size(to, size, false);
11106+
11107+ ret = ___copy_from_user(to, from, size);
11108 if (unlikely(ret))
11109 ret = copy_from_user_fixup(to, from, size);
11110
11111@@ -231,8 +239,15 @@ unsigned long copy_to_user_fixup(void __user *to, const void *from,
11112 static inline unsigned long __must_check
11113 copy_to_user(void __user *to, const void *from, unsigned long size)
11114 {
11115- unsigned long ret = ___copy_to_user(to, from, size);
11116+ unsigned long ret;
11117
11118+ if ((long)size < 0 || size > INT_MAX)
11119+ return size;
11120+
11121+ if (!__builtin_constant_p(size))
11122+ check_object_size(from, size, true);
11123+
11124+ ret = ___copy_to_user(to, from, size);
11125 if (unlikely(ret))
11126 ret = copy_to_user_fixup(to, from, size);
11127 return ret;
11128diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
11129index 7cf9c6e..6206648 100644
11130--- a/arch/sparc/kernel/Makefile
11131+++ b/arch/sparc/kernel/Makefile
11132@@ -4,7 +4,7 @@
11133 #
11134
11135 asflags-y := -ansi
11136-ccflags-y := -Werror
11137+#ccflags-y := -Werror
11138
11139 extra-y := head_$(BITS).o
11140
11141diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
11142index 50e7b62..79fae35 100644
11143--- a/arch/sparc/kernel/process_32.c
11144+++ b/arch/sparc/kernel/process_32.c
11145@@ -123,14 +123,14 @@ void show_regs(struct pt_regs *r)
11146
11147 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
11148 r->psr, r->pc, r->npc, r->y, print_tainted());
11149- printk("PC: <%pS>\n", (void *) r->pc);
11150+ printk("PC: <%pA>\n", (void *) r->pc);
11151 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
11152 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
11153 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
11154 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
11155 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
11156 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
11157- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
11158+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
11159
11160 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
11161 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
11162@@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11163 rw = (struct reg_window32 *) fp;
11164 pc = rw->ins[7];
11165 printk("[%08lx : ", pc);
11166- printk("%pS ] ", (void *) pc);
11167+ printk("%pA ] ", (void *) pc);
11168 fp = rw->ins[6];
11169 } while (++count < 16);
11170 printk("\n");
11171diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
11172index 0be7bf9..2b1cba8 100644
11173--- a/arch/sparc/kernel/process_64.c
11174+++ b/arch/sparc/kernel/process_64.c
11175@@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
11176 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
11177 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
11178 if (regs->tstate & TSTATE_PRIV)
11179- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
11180+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
11181 }
11182
11183 void show_regs(struct pt_regs *regs)
11184@@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
11185
11186 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
11187 regs->tpc, regs->tnpc, regs->y, print_tainted());
11188- printk("TPC: <%pS>\n", (void *) regs->tpc);
11189+ printk("TPC: <%pA>\n", (void *) regs->tpc);
11190 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
11191 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
11192 regs->u_regs[3]);
11193@@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
11194 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
11195 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
11196 regs->u_regs[15]);
11197- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
11198+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
11199 show_regwindow(regs);
11200 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
11201 }
11202@@ -278,7 +278,7 @@ void arch_trigger_all_cpu_backtrace(bool include_self)
11203 ((tp && tp->task) ? tp->task->pid : -1));
11204
11205 if (gp->tstate & TSTATE_PRIV) {
11206- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
11207+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
11208 (void *) gp->tpc,
11209 (void *) gp->o7,
11210 (void *) gp->i7,
11211diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
11212index 79cc0d1..ec62734 100644
11213--- a/arch/sparc/kernel/prom_common.c
11214+++ b/arch/sparc/kernel/prom_common.c
11215@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
11216
11217 unsigned int prom_early_allocated __initdata;
11218
11219-static struct of_pdt_ops prom_sparc_ops __initdata = {
11220+static struct of_pdt_ops prom_sparc_ops __initconst = {
11221 .nextprop = prom_common_nextprop,
11222 .getproplen = prom_getproplen,
11223 .getproperty = prom_getproperty,
11224diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
11225index c13c9f2..d572c34 100644
11226--- a/arch/sparc/kernel/ptrace_64.c
11227+++ b/arch/sparc/kernel/ptrace_64.c
11228@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
11229 return ret;
11230 }
11231
11232+#ifdef CONFIG_GRKERNSEC_SETXID
11233+extern void gr_delayed_cred_worker(void);
11234+#endif
11235+
11236 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
11237 {
11238 int ret = 0;
11239@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
11240 if (test_thread_flag(TIF_NOHZ))
11241 user_exit();
11242
11243+#ifdef CONFIG_GRKERNSEC_SETXID
11244+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
11245+ gr_delayed_cred_worker();
11246+#endif
11247+
11248 if (test_thread_flag(TIF_SYSCALL_TRACE))
11249 ret = tracehook_report_syscall_entry(regs);
11250
11251@@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
11252 if (test_thread_flag(TIF_NOHZ))
11253 user_exit();
11254
11255+#ifdef CONFIG_GRKERNSEC_SETXID
11256+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
11257+ gr_delayed_cred_worker();
11258+#endif
11259+
11260 audit_syscall_exit(regs);
11261
11262 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
11263diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
11264index c9300bf..b2080cf 100644
11265--- a/arch/sparc/kernel/smp_64.c
11266+++ b/arch/sparc/kernel/smp_64.c
11267@@ -883,7 +883,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
11268 return;
11269
11270 #ifdef CONFIG_DEBUG_DCFLUSH
11271- atomic_inc(&dcpage_flushes);
11272+ atomic_inc_unchecked(&dcpage_flushes);
11273 #endif
11274
11275 this_cpu = get_cpu();
11276@@ -907,7 +907,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
11277 xcall_deliver(data0, __pa(pg_addr),
11278 (u64) pg_addr, cpumask_of(cpu));
11279 #ifdef CONFIG_DEBUG_DCFLUSH
11280- atomic_inc(&dcpage_flushes_xcall);
11281+ atomic_inc_unchecked(&dcpage_flushes_xcall);
11282 #endif
11283 }
11284 }
11285@@ -926,7 +926,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
11286 preempt_disable();
11287
11288 #ifdef CONFIG_DEBUG_DCFLUSH
11289- atomic_inc(&dcpage_flushes);
11290+ atomic_inc_unchecked(&dcpage_flushes);
11291 #endif
11292 data0 = 0;
11293 pg_addr = page_address(page);
11294@@ -943,7 +943,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
11295 xcall_deliver(data0, __pa(pg_addr),
11296 (u64) pg_addr, cpu_online_mask);
11297 #ifdef CONFIG_DEBUG_DCFLUSH
11298- atomic_inc(&dcpage_flushes_xcall);
11299+ atomic_inc_unchecked(&dcpage_flushes_xcall);
11300 #endif
11301 }
11302 __local_flush_dcache_page(page);
11303diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
11304index 646988d..b88905f 100644
11305--- a/arch/sparc/kernel/sys_sparc_32.c
11306+++ b/arch/sparc/kernel/sys_sparc_32.c
11307@@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11308 if (len > TASK_SIZE - PAGE_SIZE)
11309 return -ENOMEM;
11310 if (!addr)
11311- addr = TASK_UNMAPPED_BASE;
11312+ addr = current->mm->mmap_base;
11313
11314 info.flags = 0;
11315 info.length = len;
11316diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
11317index c85403d..6af95c9 100644
11318--- a/arch/sparc/kernel/sys_sparc_64.c
11319+++ b/arch/sparc/kernel/sys_sparc_64.c
11320@@ -89,13 +89,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11321 struct vm_area_struct * vma;
11322 unsigned long task_size = TASK_SIZE;
11323 int do_color_align;
11324+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
11325 struct vm_unmapped_area_info info;
11326
11327 if (flags & MAP_FIXED) {
11328 /* We do not accept a shared mapping if it would violate
11329 * cache aliasing constraints.
11330 */
11331- if ((flags & MAP_SHARED) &&
11332+ if ((filp || (flags & MAP_SHARED)) &&
11333 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
11334 return -EINVAL;
11335 return addr;
11336@@ -110,6 +111,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11337 if (filp || (flags & MAP_SHARED))
11338 do_color_align = 1;
11339
11340+#ifdef CONFIG_PAX_RANDMMAP
11341+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11342+#endif
11343+
11344 if (addr) {
11345 if (do_color_align)
11346 addr = COLOR_ALIGN(addr, pgoff);
11347@@ -117,22 +122,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
11348 addr = PAGE_ALIGN(addr);
11349
11350 vma = find_vma(mm, addr);
11351- if (task_size - len >= addr &&
11352- (!vma || addr + len <= vma->vm_start))
11353+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11354 return addr;
11355 }
11356
11357 info.flags = 0;
11358 info.length = len;
11359- info.low_limit = TASK_UNMAPPED_BASE;
11360+ info.low_limit = mm->mmap_base;
11361 info.high_limit = min(task_size, VA_EXCLUDE_START);
11362 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
11363 info.align_offset = pgoff << PAGE_SHIFT;
11364+ info.threadstack_offset = offset;
11365 addr = vm_unmapped_area(&info);
11366
11367 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11368 VM_BUG_ON(addr != -ENOMEM);
11369 info.low_limit = VA_EXCLUDE_END;
11370+
11371+#ifdef CONFIG_PAX_RANDMMAP
11372+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11373+ info.low_limit += mm->delta_mmap;
11374+#endif
11375+
11376 info.high_limit = task_size;
11377 addr = vm_unmapped_area(&info);
11378 }
11379@@ -150,6 +161,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11380 unsigned long task_size = STACK_TOP32;
11381 unsigned long addr = addr0;
11382 int do_color_align;
11383+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
11384 struct vm_unmapped_area_info info;
11385
11386 /* This should only ever run for 32-bit processes. */
11387@@ -159,7 +171,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11388 /* We do not accept a shared mapping if it would violate
11389 * cache aliasing constraints.
11390 */
11391- if ((flags & MAP_SHARED) &&
11392+ if ((filp || (flags & MAP_SHARED)) &&
11393 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
11394 return -EINVAL;
11395 return addr;
11396@@ -172,6 +184,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11397 if (filp || (flags & MAP_SHARED))
11398 do_color_align = 1;
11399
11400+#ifdef CONFIG_PAX_RANDMMAP
11401+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11402+#endif
11403+
11404 /* requesting a specific address */
11405 if (addr) {
11406 if (do_color_align)
11407@@ -180,8 +196,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11408 addr = PAGE_ALIGN(addr);
11409
11410 vma = find_vma(mm, addr);
11411- if (task_size - len >= addr &&
11412- (!vma || addr + len <= vma->vm_start))
11413+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11414 return addr;
11415 }
11416
11417@@ -191,6 +206,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11418 info.high_limit = mm->mmap_base;
11419 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
11420 info.align_offset = pgoff << PAGE_SHIFT;
11421+ info.threadstack_offset = offset;
11422 addr = vm_unmapped_area(&info);
11423
11424 /*
11425@@ -203,6 +219,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11426 VM_BUG_ON(addr != -ENOMEM);
11427 info.flags = 0;
11428 info.low_limit = TASK_UNMAPPED_BASE;
11429+
11430+#ifdef CONFIG_PAX_RANDMMAP
11431+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11432+ info.low_limit += mm->delta_mmap;
11433+#endif
11434+
11435 info.high_limit = STACK_TOP32;
11436 addr = vm_unmapped_area(&info);
11437 }
11438@@ -259,10 +281,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
11439 EXPORT_SYMBOL(get_fb_unmapped_area);
11440
11441 /* Essentially the same as PowerPC. */
11442-static unsigned long mmap_rnd(void)
11443+static unsigned long mmap_rnd(struct mm_struct *mm)
11444 {
11445 unsigned long rnd = 0UL;
11446
11447+#ifdef CONFIG_PAX_RANDMMAP
11448+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11449+#endif
11450+
11451 if (current->flags & PF_RANDOMIZE) {
11452 unsigned long val = get_random_int();
11453 if (test_thread_flag(TIF_32BIT))
11454@@ -275,7 +301,7 @@ static unsigned long mmap_rnd(void)
11455
11456 void arch_pick_mmap_layout(struct mm_struct *mm)
11457 {
11458- unsigned long random_factor = mmap_rnd();
11459+ unsigned long random_factor = mmap_rnd(mm);
11460 unsigned long gap;
11461
11462 /*
11463@@ -288,6 +314,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
11464 gap == RLIM_INFINITY ||
11465 sysctl_legacy_va_layout) {
11466 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
11467+
11468+#ifdef CONFIG_PAX_RANDMMAP
11469+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11470+ mm->mmap_base += mm->delta_mmap;
11471+#endif
11472+
11473 mm->get_unmapped_area = arch_get_unmapped_area;
11474 } else {
11475 /* We know it's 32-bit */
11476@@ -299,6 +331,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
11477 gap = (task_size / 6 * 5);
11478
11479 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
11480+
11481+#ifdef CONFIG_PAX_RANDMMAP
11482+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11483+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
11484+#endif
11485+
11486 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
11487 }
11488 }
11489diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
11490index 33a17e7..d87fb1f 100644
11491--- a/arch/sparc/kernel/syscalls.S
11492+++ b/arch/sparc/kernel/syscalls.S
11493@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
11494 #endif
11495 .align 32
11496 1: ldx [%g6 + TI_FLAGS], %l5
11497- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11498+ andcc %l5, _TIF_WORK_SYSCALL, %g0
11499 be,pt %icc, rtrap
11500 nop
11501 call syscall_trace_leave
11502@@ -184,7 +184,7 @@ linux_sparc_syscall32:
11503
11504 srl %i3, 0, %o3 ! IEU0
11505 srl %i2, 0, %o2 ! IEU0 Group
11506- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11507+ andcc %l0, _TIF_WORK_SYSCALL, %g0
11508 bne,pn %icc, linux_syscall_trace32 ! CTI
11509 mov %i0, %l5 ! IEU1
11510 5: call %l7 ! CTI Group brk forced
11511@@ -208,7 +208,7 @@ linux_sparc_syscall:
11512
11513 mov %i3, %o3 ! IEU1
11514 mov %i4, %o4 ! IEU0 Group
11515- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11516+ andcc %l0, _TIF_WORK_SYSCALL, %g0
11517 bne,pn %icc, linux_syscall_trace ! CTI Group
11518 mov %i0, %l5 ! IEU0
11519 2: call %l7 ! CTI Group brk forced
11520@@ -223,7 +223,7 @@ ret_sys_call:
11521
11522 cmp %o0, -ERESTART_RESTARTBLOCK
11523 bgeu,pn %xcc, 1f
11524- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
11525+ andcc %l0, _TIF_WORK_SYSCALL, %g0
11526 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
11527
11528 2:
11529diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
11530index 6fd386c5..6907d81 100644
11531--- a/arch/sparc/kernel/traps_32.c
11532+++ b/arch/sparc/kernel/traps_32.c
11533@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
11534 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
11535 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
11536
11537+extern void gr_handle_kernel_exploit(void);
11538+
11539 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11540 {
11541 static int die_counter;
11542@@ -76,15 +78,17 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11543 count++ < 30 &&
11544 (((unsigned long) rw) >= PAGE_OFFSET) &&
11545 !(((unsigned long) rw) & 0x7)) {
11546- printk("Caller[%08lx]: %pS\n", rw->ins[7],
11547+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
11548 (void *) rw->ins[7]);
11549 rw = (struct reg_window32 *)rw->ins[6];
11550 }
11551 }
11552 printk("Instruction DUMP:");
11553 instruction_dump ((unsigned long *) regs->pc);
11554- if(regs->psr & PSR_PS)
11555+ if(regs->psr & PSR_PS) {
11556+ gr_handle_kernel_exploit();
11557 do_exit(SIGKILL);
11558+ }
11559 do_exit(SIGSEGV);
11560 }
11561
11562diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
11563index 981a769..d906eda 100644
11564--- a/arch/sparc/kernel/traps_64.c
11565+++ b/arch/sparc/kernel/traps_64.c
11566@@ -79,7 +79,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
11567 i + 1,
11568 p->trapstack[i].tstate, p->trapstack[i].tpc,
11569 p->trapstack[i].tnpc, p->trapstack[i].tt);
11570- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
11571+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
11572 }
11573 }
11574
11575@@ -99,6 +99,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
11576
11577 lvl -= 0x100;
11578 if (regs->tstate & TSTATE_PRIV) {
11579+
11580+#ifdef CONFIG_PAX_REFCOUNT
11581+ if (lvl == 6)
11582+ pax_report_refcount_overflow(regs);
11583+#endif
11584+
11585 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
11586 die_if_kernel(buffer, regs);
11587 }
11588@@ -117,11 +123,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
11589 void bad_trap_tl1(struct pt_regs *regs, long lvl)
11590 {
11591 char buffer[32];
11592-
11593+
11594 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
11595 0, lvl, SIGTRAP) == NOTIFY_STOP)
11596 return;
11597
11598+#ifdef CONFIG_PAX_REFCOUNT
11599+ if (lvl == 6)
11600+ pax_report_refcount_overflow(regs);
11601+#endif
11602+
11603 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
11604
11605 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
11606@@ -1151,7 +1162,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
11607 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
11608 printk("%s" "ERROR(%d): ",
11609 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
11610- printk("TPC<%pS>\n", (void *) regs->tpc);
11611+ printk("TPC<%pA>\n", (void *) regs->tpc);
11612 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
11613 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
11614 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
11615@@ -1758,7 +1769,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11616 smp_processor_id(),
11617 (type & 0x1) ? 'I' : 'D',
11618 regs->tpc);
11619- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
11620+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
11621 panic("Irrecoverable Cheetah+ parity error.");
11622 }
11623
11624@@ -1766,7 +1777,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
11625 smp_processor_id(),
11626 (type & 0x1) ? 'I' : 'D',
11627 regs->tpc);
11628- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
11629+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
11630 }
11631
11632 struct sun4v_error_entry {
11633@@ -1839,8 +1850,8 @@ struct sun4v_error_entry {
11634 /*0x38*/u64 reserved_5;
11635 };
11636
11637-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11638-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11639+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
11640+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
11641
11642 static const char *sun4v_err_type_to_str(u8 type)
11643 {
11644@@ -1932,7 +1943,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
11645 }
11646
11647 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11648- int cpu, const char *pfx, atomic_t *ocnt)
11649+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
11650 {
11651 u64 *raw_ptr = (u64 *) ent;
11652 u32 attrs;
11653@@ -1990,8 +2001,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
11654
11655 show_regs(regs);
11656
11657- if ((cnt = atomic_read(ocnt)) != 0) {
11658- atomic_set(ocnt, 0);
11659+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
11660+ atomic_set_unchecked(ocnt, 0);
11661 wmb();
11662 printk("%s: Queue overflowed %d times.\n",
11663 pfx, cnt);
11664@@ -2048,7 +2059,7 @@ out:
11665 */
11666 void sun4v_resum_overflow(struct pt_regs *regs)
11667 {
11668- atomic_inc(&sun4v_resum_oflow_cnt);
11669+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
11670 }
11671
11672 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
11673@@ -2101,7 +2112,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
11674 /* XXX Actually even this can make not that much sense. Perhaps
11675 * XXX we should just pull the plug and panic directly from here?
11676 */
11677- atomic_inc(&sun4v_nonresum_oflow_cnt);
11678+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
11679 }
11680
11681 static void sun4v_tlb_error(struct pt_regs *regs)
11682@@ -2120,9 +2131,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
11683
11684 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
11685 regs->tpc, tl);
11686- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
11687+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
11688 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11689- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
11690+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
11691 (void *) regs->u_regs[UREG_I7]);
11692 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
11693 "pte[%lx] error[%lx]\n",
11694@@ -2143,9 +2154,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
11695
11696 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
11697 regs->tpc, tl);
11698- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
11699+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
11700 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
11701- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
11702+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
11703 (void *) regs->u_regs[UREG_I7]);
11704 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
11705 "pte[%lx] error[%lx]\n",
11706@@ -2362,13 +2373,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
11707 fp = (unsigned long)sf->fp + STACK_BIAS;
11708 }
11709
11710- printk(" [%016lx] %pS\n", pc, (void *) pc);
11711+ printk(" [%016lx] %pA\n", pc, (void *) pc);
11712 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
11713 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
11714 int index = tsk->curr_ret_stack;
11715 if (tsk->ret_stack && index >= graph) {
11716 pc = tsk->ret_stack[index - graph].ret;
11717- printk(" [%016lx] %pS\n", pc, (void *) pc);
11718+ printk(" [%016lx] %pA\n", pc, (void *) pc);
11719 graph++;
11720 }
11721 }
11722@@ -2386,6 +2397,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
11723 return (struct reg_window *) (fp + STACK_BIAS);
11724 }
11725
11726+extern void gr_handle_kernel_exploit(void);
11727+
11728 void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11729 {
11730 static int die_counter;
11731@@ -2414,7 +2427,7 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11732 while (rw &&
11733 count++ < 30 &&
11734 kstack_valid(tp, (unsigned long) rw)) {
11735- printk("Caller[%016lx]: %pS\n", rw->ins[7],
11736+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
11737 (void *) rw->ins[7]);
11738
11739 rw = kernel_stack_up(rw);
11740@@ -2427,8 +2440,10 @@ void __noreturn die_if_kernel(char *str, struct pt_regs *regs)
11741 }
11742 user_instruction_dump ((unsigned int __user *) regs->tpc);
11743 }
11744- if (regs->tstate & TSTATE_PRIV)
11745+ if (regs->tstate & TSTATE_PRIV) {
11746+ gr_handle_kernel_exploit();
11747 do_exit(SIGKILL);
11748+ }
11749 do_exit(SIGSEGV);
11750 }
11751 EXPORT_SYMBOL(die_if_kernel);
11752diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
11753index 62098a8..547ab2c 100644
11754--- a/arch/sparc/kernel/unaligned_64.c
11755+++ b/arch/sparc/kernel/unaligned_64.c
11756@@ -297,7 +297,7 @@ static void log_unaligned(struct pt_regs *regs)
11757 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
11758
11759 if (__ratelimit(&ratelimit)) {
11760- printk("Kernel unaligned access at TPC[%lx] %pS\n",
11761+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
11762 regs->tpc, (void *) regs->tpc);
11763 }
11764 }
11765diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
11766index 3269b02..64f5231 100644
11767--- a/arch/sparc/lib/Makefile
11768+++ b/arch/sparc/lib/Makefile
11769@@ -2,7 +2,7 @@
11770 #
11771
11772 asflags-y := -ansi -DST_DIV0=0x02
11773-ccflags-y := -Werror
11774+#ccflags-y := -Werror
11775
11776 lib-$(CONFIG_SPARC32) += ashrdi3.o
11777 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
11778diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
11779index 85c233d..68500e0 100644
11780--- a/arch/sparc/lib/atomic_64.S
11781+++ b/arch/sparc/lib/atomic_64.S
11782@@ -17,7 +17,12 @@
11783 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11784 BACKOFF_SETUP(%o2)
11785 1: lduw [%o1], %g1
11786- add %g1, %o0, %g7
11787+ addcc %g1, %o0, %g7
11788+
11789+#ifdef CONFIG_PAX_REFCOUNT
11790+ tvs %icc, 6
11791+#endif
11792+
11793 cas [%o1], %g1, %g7
11794 cmp %g1, %g7
11795 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11796@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
11797 2: BACKOFF_SPIN(%o2, %o3, 1b)
11798 ENDPROC(atomic_add)
11799
11800+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11801+ BACKOFF_SETUP(%o2)
11802+1: lduw [%o1], %g1
11803+ add %g1, %o0, %g7
11804+ cas [%o1], %g1, %g7
11805+ cmp %g1, %g7
11806+ bne,pn %icc, 2f
11807+ nop
11808+ retl
11809+ nop
11810+2: BACKOFF_SPIN(%o2, %o3, 1b)
11811+ENDPROC(atomic_add_unchecked)
11812+
11813 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11814 BACKOFF_SETUP(%o2)
11815 1: lduw [%o1], %g1
11816- sub %g1, %o0, %g7
11817+ subcc %g1, %o0, %g7
11818+
11819+#ifdef CONFIG_PAX_REFCOUNT
11820+ tvs %icc, 6
11821+#endif
11822+
11823 cas [%o1], %g1, %g7
11824 cmp %g1, %g7
11825 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11826@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11827 2: BACKOFF_SPIN(%o2, %o3, 1b)
11828 ENDPROC(atomic_sub)
11829
11830+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11831+ BACKOFF_SETUP(%o2)
11832+1: lduw [%o1], %g1
11833+ sub %g1, %o0, %g7
11834+ cas [%o1], %g1, %g7
11835+ cmp %g1, %g7
11836+ bne,pn %icc, 2f
11837+ nop
11838+ retl
11839+ nop
11840+2: BACKOFF_SPIN(%o2, %o3, 1b)
11841+ENDPROC(atomic_sub_unchecked)
11842+
11843 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11844 BACKOFF_SETUP(%o2)
11845 1: lduw [%o1], %g1
11846- add %g1, %o0, %g7
11847+ addcc %g1, %o0, %g7
11848+
11849+#ifdef CONFIG_PAX_REFCOUNT
11850+ tvs %icc, 6
11851+#endif
11852+
11853 cas [%o1], %g1, %g7
11854 cmp %g1, %g7
11855 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11856@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11857 2: BACKOFF_SPIN(%o2, %o3, 1b)
11858 ENDPROC(atomic_add_ret)
11859
11860+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11861+ BACKOFF_SETUP(%o2)
11862+1: lduw [%o1], %g1
11863+ addcc %g1, %o0, %g7
11864+ cas [%o1], %g1, %g7
11865+ cmp %g1, %g7
11866+ bne,pn %icc, 2f
11867+ add %g7, %o0, %g7
11868+ sra %g7, 0, %o0
11869+ retl
11870+ nop
11871+2: BACKOFF_SPIN(%o2, %o3, 1b)
11872+ENDPROC(atomic_add_ret_unchecked)
11873+
11874 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11875 BACKOFF_SETUP(%o2)
11876 1: lduw [%o1], %g1
11877- sub %g1, %o0, %g7
11878+ subcc %g1, %o0, %g7
11879+
11880+#ifdef CONFIG_PAX_REFCOUNT
11881+ tvs %icc, 6
11882+#endif
11883+
11884 cas [%o1], %g1, %g7
11885 cmp %g1, %g7
11886 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
11887@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
11888 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11889 BACKOFF_SETUP(%o2)
11890 1: ldx [%o1], %g1
11891- add %g1, %o0, %g7
11892+ addcc %g1, %o0, %g7
11893+
11894+#ifdef CONFIG_PAX_REFCOUNT
11895+ tvs %xcc, 6
11896+#endif
11897+
11898 casx [%o1], %g1, %g7
11899 cmp %g1, %g7
11900 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11901@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
11902 2: BACKOFF_SPIN(%o2, %o3, 1b)
11903 ENDPROC(atomic64_add)
11904
11905+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11906+ BACKOFF_SETUP(%o2)
11907+1: ldx [%o1], %g1
11908+ addcc %g1, %o0, %g7
11909+ casx [%o1], %g1, %g7
11910+ cmp %g1, %g7
11911+ bne,pn %xcc, 2f
11912+ nop
11913+ retl
11914+ nop
11915+2: BACKOFF_SPIN(%o2, %o3, 1b)
11916+ENDPROC(atomic64_add_unchecked)
11917+
11918 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11919 BACKOFF_SETUP(%o2)
11920 1: ldx [%o1], %g1
11921- sub %g1, %o0, %g7
11922+ subcc %g1, %o0, %g7
11923+
11924+#ifdef CONFIG_PAX_REFCOUNT
11925+ tvs %xcc, 6
11926+#endif
11927+
11928 casx [%o1], %g1, %g7
11929 cmp %g1, %g7
11930 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11931@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11932 2: BACKOFF_SPIN(%o2, %o3, 1b)
11933 ENDPROC(atomic64_sub)
11934
11935+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11936+ BACKOFF_SETUP(%o2)
11937+1: ldx [%o1], %g1
11938+ subcc %g1, %o0, %g7
11939+ casx [%o1], %g1, %g7
11940+ cmp %g1, %g7
11941+ bne,pn %xcc, 2f
11942+ nop
11943+ retl
11944+ nop
11945+2: BACKOFF_SPIN(%o2, %o3, 1b)
11946+ENDPROC(atomic64_sub_unchecked)
11947+
11948 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11949 BACKOFF_SETUP(%o2)
11950 1: ldx [%o1], %g1
11951- add %g1, %o0, %g7
11952+ addcc %g1, %o0, %g7
11953+
11954+#ifdef CONFIG_PAX_REFCOUNT
11955+ tvs %xcc, 6
11956+#endif
11957+
11958 casx [%o1], %g1, %g7
11959 cmp %g1, %g7
11960 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11961@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11962 2: BACKOFF_SPIN(%o2, %o3, 1b)
11963 ENDPROC(atomic64_add_ret)
11964
11965+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11966+ BACKOFF_SETUP(%o2)
11967+1: ldx [%o1], %g1
11968+ addcc %g1, %o0, %g7
11969+ casx [%o1], %g1, %g7
11970+ cmp %g1, %g7
11971+ bne,pn %xcc, 2f
11972+ add %g7, %o0, %g7
11973+ mov %g7, %o0
11974+ retl
11975+ nop
11976+2: BACKOFF_SPIN(%o2, %o3, 1b)
11977+ENDPROC(atomic64_add_ret_unchecked)
11978+
11979 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11980 BACKOFF_SETUP(%o2)
11981 1: ldx [%o1], %g1
11982- sub %g1, %o0, %g7
11983+ subcc %g1, %o0, %g7
11984+
11985+#ifdef CONFIG_PAX_REFCOUNT
11986+ tvs %xcc, 6
11987+#endif
11988+
11989 casx [%o1], %g1, %g7
11990 cmp %g1, %g7
11991 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11992diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11993index 323335b..ed85ea2 100644
11994--- a/arch/sparc/lib/ksyms.c
11995+++ b/arch/sparc/lib/ksyms.c
11996@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
11997
11998 /* Atomic counter implementation. */
11999 EXPORT_SYMBOL(atomic_add);
12000+EXPORT_SYMBOL(atomic_add_unchecked);
12001 EXPORT_SYMBOL(atomic_add_ret);
12002+EXPORT_SYMBOL(atomic_add_ret_unchecked);
12003 EXPORT_SYMBOL(atomic_sub);
12004+EXPORT_SYMBOL(atomic_sub_unchecked);
12005 EXPORT_SYMBOL(atomic_sub_ret);
12006 EXPORT_SYMBOL(atomic64_add);
12007+EXPORT_SYMBOL(atomic64_add_unchecked);
12008 EXPORT_SYMBOL(atomic64_add_ret);
12009+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
12010 EXPORT_SYMBOL(atomic64_sub);
12011+EXPORT_SYMBOL(atomic64_sub_unchecked);
12012 EXPORT_SYMBOL(atomic64_sub_ret);
12013 EXPORT_SYMBOL(atomic64_dec_if_positive);
12014
12015diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
12016index 30c3ecc..736f015 100644
12017--- a/arch/sparc/mm/Makefile
12018+++ b/arch/sparc/mm/Makefile
12019@@ -2,7 +2,7 @@
12020 #
12021
12022 asflags-y := -ansi
12023-ccflags-y := -Werror
12024+#ccflags-y := -Werror
12025
12026 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
12027 obj-y += fault_$(BITS).o
12028diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
12029index 908e8c1..1524793 100644
12030--- a/arch/sparc/mm/fault_32.c
12031+++ b/arch/sparc/mm/fault_32.c
12032@@ -21,6 +21,9 @@
12033 #include <linux/perf_event.h>
12034 #include <linux/interrupt.h>
12035 #include <linux/kdebug.h>
12036+#include <linux/slab.h>
12037+#include <linux/pagemap.h>
12038+#include <linux/compiler.h>
12039
12040 #include <asm/page.h>
12041 #include <asm/pgtable.h>
12042@@ -156,6 +159,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
12043 return safe_compute_effective_address(regs, insn);
12044 }
12045
12046+#ifdef CONFIG_PAX_PAGEEXEC
12047+#ifdef CONFIG_PAX_DLRESOLVE
12048+static void pax_emuplt_close(struct vm_area_struct *vma)
12049+{
12050+ vma->vm_mm->call_dl_resolve = 0UL;
12051+}
12052+
12053+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
12054+{
12055+ unsigned int *kaddr;
12056+
12057+ vmf->page = alloc_page(GFP_HIGHUSER);
12058+ if (!vmf->page)
12059+ return VM_FAULT_OOM;
12060+
12061+ kaddr = kmap(vmf->page);
12062+ memset(kaddr, 0, PAGE_SIZE);
12063+ kaddr[0] = 0x9DE3BFA8U; /* save */
12064+ flush_dcache_page(vmf->page);
12065+ kunmap(vmf->page);
12066+ return VM_FAULT_MAJOR;
12067+}
12068+
12069+static const struct vm_operations_struct pax_vm_ops = {
12070+ .close = pax_emuplt_close,
12071+ .fault = pax_emuplt_fault
12072+};
12073+
12074+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
12075+{
12076+ int ret;
12077+
12078+ INIT_LIST_HEAD(&vma->anon_vma_chain);
12079+ vma->vm_mm = current->mm;
12080+ vma->vm_start = addr;
12081+ vma->vm_end = addr + PAGE_SIZE;
12082+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
12083+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
12084+ vma->vm_ops = &pax_vm_ops;
12085+
12086+ ret = insert_vm_struct(current->mm, vma);
12087+ if (ret)
12088+ return ret;
12089+
12090+ ++current->mm->total_vm;
12091+ return 0;
12092+}
12093+#endif
12094+
12095+/*
12096+ * PaX: decide what to do with offenders (regs->pc = fault address)
12097+ *
12098+ * returns 1 when task should be killed
12099+ * 2 when patched PLT trampoline was detected
12100+ * 3 when unpatched PLT trampoline was detected
12101+ */
12102+static int pax_handle_fetch_fault(struct pt_regs *regs)
12103+{
12104+
12105+#ifdef CONFIG_PAX_EMUPLT
12106+ int err;
12107+
12108+ do { /* PaX: patched PLT emulation #1 */
12109+ unsigned int sethi1, sethi2, jmpl;
12110+
12111+ err = get_user(sethi1, (unsigned int *)regs->pc);
12112+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
12113+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
12114+
12115+ if (err)
12116+ break;
12117+
12118+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
12119+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
12120+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
12121+ {
12122+ unsigned int addr;
12123+
12124+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
12125+ addr = regs->u_regs[UREG_G1];
12126+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
12127+ regs->pc = addr;
12128+ regs->npc = addr+4;
12129+ return 2;
12130+ }
12131+ } while (0);
12132+
12133+ do { /* PaX: patched PLT emulation #2 */
12134+ unsigned int ba;
12135+
12136+ err = get_user(ba, (unsigned int *)regs->pc);
12137+
12138+ if (err)
12139+ break;
12140+
12141+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
12142+ unsigned int addr;
12143+
12144+ if ((ba & 0xFFC00000U) == 0x30800000U)
12145+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
12146+ else
12147+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
12148+ regs->pc = addr;
12149+ regs->npc = addr+4;
12150+ return 2;
12151+ }
12152+ } while (0);
12153+
12154+ do { /* PaX: patched PLT emulation #3 */
12155+ unsigned int sethi, bajmpl, nop;
12156+
12157+ err = get_user(sethi, (unsigned int *)regs->pc);
12158+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
12159+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
12160+
12161+ if (err)
12162+ break;
12163+
12164+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12165+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
12166+ nop == 0x01000000U)
12167+ {
12168+ unsigned int addr;
12169+
12170+ addr = (sethi & 0x003FFFFFU) << 10;
12171+ regs->u_regs[UREG_G1] = addr;
12172+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
12173+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
12174+ else
12175+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
12176+ regs->pc = addr;
12177+ regs->npc = addr+4;
12178+ return 2;
12179+ }
12180+ } while (0);
12181+
12182+ do { /* PaX: unpatched PLT emulation step 1 */
12183+ unsigned int sethi, ba, nop;
12184+
12185+ err = get_user(sethi, (unsigned int *)regs->pc);
12186+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
12187+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
12188+
12189+ if (err)
12190+ break;
12191+
12192+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12193+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
12194+ nop == 0x01000000U)
12195+ {
12196+ unsigned int addr, save, call;
12197+
12198+ if ((ba & 0xFFC00000U) == 0x30800000U)
12199+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
12200+ else
12201+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
12202+
12203+ err = get_user(save, (unsigned int *)addr);
12204+ err |= get_user(call, (unsigned int *)(addr+4));
12205+ err |= get_user(nop, (unsigned int *)(addr+8));
12206+ if (err)
12207+ break;
12208+
12209+#ifdef CONFIG_PAX_DLRESOLVE
12210+ if (save == 0x9DE3BFA8U &&
12211+ (call & 0xC0000000U) == 0x40000000U &&
12212+ nop == 0x01000000U)
12213+ {
12214+ struct vm_area_struct *vma;
12215+ unsigned long call_dl_resolve;
12216+
12217+ down_read(&current->mm->mmap_sem);
12218+ call_dl_resolve = current->mm->call_dl_resolve;
12219+ up_read(&current->mm->mmap_sem);
12220+ if (likely(call_dl_resolve))
12221+ goto emulate;
12222+
12223+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
12224+
12225+ down_write(&current->mm->mmap_sem);
12226+ if (current->mm->call_dl_resolve) {
12227+ call_dl_resolve = current->mm->call_dl_resolve;
12228+ up_write(&current->mm->mmap_sem);
12229+ if (vma)
12230+ kmem_cache_free(vm_area_cachep, vma);
12231+ goto emulate;
12232+ }
12233+
12234+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12235+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12236+ up_write(&current->mm->mmap_sem);
12237+ if (vma)
12238+ kmem_cache_free(vm_area_cachep, vma);
12239+ return 1;
12240+ }
12241+
12242+ if (pax_insert_vma(vma, call_dl_resolve)) {
12243+ up_write(&current->mm->mmap_sem);
12244+ kmem_cache_free(vm_area_cachep, vma);
12245+ return 1;
12246+ }
12247+
12248+ current->mm->call_dl_resolve = call_dl_resolve;
12249+ up_write(&current->mm->mmap_sem);
12250+
12251+emulate:
12252+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12253+ regs->pc = call_dl_resolve;
12254+ regs->npc = addr+4;
12255+ return 3;
12256+ }
12257+#endif
12258+
12259+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12260+ if ((save & 0xFFC00000U) == 0x05000000U &&
12261+ (call & 0xFFFFE000U) == 0x85C0A000U &&
12262+ nop == 0x01000000U)
12263+ {
12264+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12265+ regs->u_regs[UREG_G2] = addr + 4;
12266+ addr = (save & 0x003FFFFFU) << 10;
12267+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
12268+ regs->pc = addr;
12269+ regs->npc = addr+4;
12270+ return 3;
12271+ }
12272+ }
12273+ } while (0);
12274+
12275+ do { /* PaX: unpatched PLT emulation step 2 */
12276+ unsigned int save, call, nop;
12277+
12278+ err = get_user(save, (unsigned int *)(regs->pc-4));
12279+ err |= get_user(call, (unsigned int *)regs->pc);
12280+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
12281+ if (err)
12282+ break;
12283+
12284+ if (save == 0x9DE3BFA8U &&
12285+ (call & 0xC0000000U) == 0x40000000U &&
12286+ nop == 0x01000000U)
12287+ {
12288+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
12289+
12290+ regs->u_regs[UREG_RETPC] = regs->pc;
12291+ regs->pc = dl_resolve;
12292+ regs->npc = dl_resolve+4;
12293+ return 3;
12294+ }
12295+ } while (0);
12296+#endif
12297+
12298+ return 1;
12299+}
12300+
12301+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12302+{
12303+ unsigned long i;
12304+
12305+ printk(KERN_ERR "PAX: bytes at PC: ");
12306+ for (i = 0; i < 8; i++) {
12307+ unsigned int c;
12308+ if (get_user(c, (unsigned int *)pc+i))
12309+ printk(KERN_CONT "???????? ");
12310+ else
12311+ printk(KERN_CONT "%08x ", c);
12312+ }
12313+ printk("\n");
12314+}
12315+#endif
12316+
12317 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
12318 int text_fault)
12319 {
12320@@ -226,6 +500,24 @@ good_area:
12321 if (!(vma->vm_flags & VM_WRITE))
12322 goto bad_area;
12323 } else {
12324+
12325+#ifdef CONFIG_PAX_PAGEEXEC
12326+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
12327+ up_read(&mm->mmap_sem);
12328+ switch (pax_handle_fetch_fault(regs)) {
12329+
12330+#ifdef CONFIG_PAX_EMUPLT
12331+ case 2:
12332+ case 3:
12333+ return;
12334+#endif
12335+
12336+ }
12337+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
12338+ do_group_exit(SIGKILL);
12339+ }
12340+#endif
12341+
12342 /* Allow reads even for write-only mappings */
12343 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
12344 goto bad_area;
12345diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
12346index 18fcd71..e4fe821 100644
12347--- a/arch/sparc/mm/fault_64.c
12348+++ b/arch/sparc/mm/fault_64.c
12349@@ -22,6 +22,9 @@
12350 #include <linux/kdebug.h>
12351 #include <linux/percpu.h>
12352 #include <linux/context_tracking.h>
12353+#include <linux/slab.h>
12354+#include <linux/pagemap.h>
12355+#include <linux/compiler.h>
12356
12357 #include <asm/page.h>
12358 #include <asm/pgtable.h>
12359@@ -76,7 +79,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
12360 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
12361 regs->tpc);
12362 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
12363- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
12364+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
12365 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
12366 dump_stack();
12367 unhandled_fault(regs->tpc, current, regs);
12368@@ -279,6 +282,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
12369 show_regs(regs);
12370 }
12371
12372+#ifdef CONFIG_PAX_PAGEEXEC
12373+#ifdef CONFIG_PAX_DLRESOLVE
12374+static void pax_emuplt_close(struct vm_area_struct *vma)
12375+{
12376+ vma->vm_mm->call_dl_resolve = 0UL;
12377+}
12378+
12379+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
12380+{
12381+ unsigned int *kaddr;
12382+
12383+ vmf->page = alloc_page(GFP_HIGHUSER);
12384+ if (!vmf->page)
12385+ return VM_FAULT_OOM;
12386+
12387+ kaddr = kmap(vmf->page);
12388+ memset(kaddr, 0, PAGE_SIZE);
12389+ kaddr[0] = 0x9DE3BFA8U; /* save */
12390+ flush_dcache_page(vmf->page);
12391+ kunmap(vmf->page);
12392+ return VM_FAULT_MAJOR;
12393+}
12394+
12395+static const struct vm_operations_struct pax_vm_ops = {
12396+ .close = pax_emuplt_close,
12397+ .fault = pax_emuplt_fault
12398+};
12399+
12400+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
12401+{
12402+ int ret;
12403+
12404+ INIT_LIST_HEAD(&vma->anon_vma_chain);
12405+ vma->vm_mm = current->mm;
12406+ vma->vm_start = addr;
12407+ vma->vm_end = addr + PAGE_SIZE;
12408+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
12409+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
12410+ vma->vm_ops = &pax_vm_ops;
12411+
12412+ ret = insert_vm_struct(current->mm, vma);
12413+ if (ret)
12414+ return ret;
12415+
12416+ ++current->mm->total_vm;
12417+ return 0;
12418+}
12419+#endif
12420+
12421+/*
12422+ * PaX: decide what to do with offenders (regs->tpc = fault address)
12423+ *
12424+ * returns 1 when task should be killed
12425+ * 2 when patched PLT trampoline was detected
12426+ * 3 when unpatched PLT trampoline was detected
12427+ */
12428+static int pax_handle_fetch_fault(struct pt_regs *regs)
12429+{
12430+
12431+#ifdef CONFIG_PAX_EMUPLT
12432+ int err;
12433+
12434+ do { /* PaX: patched PLT emulation #1 */
12435+ unsigned int sethi1, sethi2, jmpl;
12436+
12437+ err = get_user(sethi1, (unsigned int *)regs->tpc);
12438+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
12439+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
12440+
12441+ if (err)
12442+ break;
12443+
12444+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
12445+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
12446+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
12447+ {
12448+ unsigned long addr;
12449+
12450+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
12451+ addr = regs->u_regs[UREG_G1];
12452+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12453+
12454+ if (test_thread_flag(TIF_32BIT))
12455+ addr &= 0xFFFFFFFFUL;
12456+
12457+ regs->tpc = addr;
12458+ regs->tnpc = addr+4;
12459+ return 2;
12460+ }
12461+ } while (0);
12462+
12463+ do { /* PaX: patched PLT emulation #2 */
12464+ unsigned int ba;
12465+
12466+ err = get_user(ba, (unsigned int *)regs->tpc);
12467+
12468+ if (err)
12469+ break;
12470+
12471+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
12472+ unsigned long addr;
12473+
12474+ if ((ba & 0xFFC00000U) == 0x30800000U)
12475+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12476+ else
12477+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12478+
12479+ if (test_thread_flag(TIF_32BIT))
12480+ addr &= 0xFFFFFFFFUL;
12481+
12482+ regs->tpc = addr;
12483+ regs->tnpc = addr+4;
12484+ return 2;
12485+ }
12486+ } while (0);
12487+
12488+ do { /* PaX: patched PLT emulation #3 */
12489+ unsigned int sethi, bajmpl, nop;
12490+
12491+ err = get_user(sethi, (unsigned int *)regs->tpc);
12492+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
12493+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12494+
12495+ if (err)
12496+ break;
12497+
12498+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12499+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
12500+ nop == 0x01000000U)
12501+ {
12502+ unsigned long addr;
12503+
12504+ addr = (sethi & 0x003FFFFFU) << 10;
12505+ regs->u_regs[UREG_G1] = addr;
12506+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
12507+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12508+ else
12509+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12510+
12511+ if (test_thread_flag(TIF_32BIT))
12512+ addr &= 0xFFFFFFFFUL;
12513+
12514+ regs->tpc = addr;
12515+ regs->tnpc = addr+4;
12516+ return 2;
12517+ }
12518+ } while (0);
12519+
12520+ do { /* PaX: patched PLT emulation #4 */
12521+ unsigned int sethi, mov1, call, mov2;
12522+
12523+ err = get_user(sethi, (unsigned int *)regs->tpc);
12524+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
12525+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
12526+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
12527+
12528+ if (err)
12529+ break;
12530+
12531+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12532+ mov1 == 0x8210000FU &&
12533+ (call & 0xC0000000U) == 0x40000000U &&
12534+ mov2 == 0x9E100001U)
12535+ {
12536+ unsigned long addr;
12537+
12538+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
12539+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12540+
12541+ if (test_thread_flag(TIF_32BIT))
12542+ addr &= 0xFFFFFFFFUL;
12543+
12544+ regs->tpc = addr;
12545+ regs->tnpc = addr+4;
12546+ return 2;
12547+ }
12548+ } while (0);
12549+
12550+ do { /* PaX: patched PLT emulation #5 */
12551+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
12552+
12553+ err = get_user(sethi, (unsigned int *)regs->tpc);
12554+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12555+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12556+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
12557+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
12558+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
12559+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
12560+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
12561+
12562+ if (err)
12563+ break;
12564+
12565+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12566+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
12567+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12568+ (or1 & 0xFFFFE000U) == 0x82106000U &&
12569+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
12570+ sllx == 0x83287020U &&
12571+ jmpl == 0x81C04005U &&
12572+ nop == 0x01000000U)
12573+ {
12574+ unsigned long addr;
12575+
12576+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12577+ regs->u_regs[UREG_G1] <<= 32;
12578+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12579+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12580+ regs->tpc = addr;
12581+ regs->tnpc = addr+4;
12582+ return 2;
12583+ }
12584+ } while (0);
12585+
12586+ do { /* PaX: patched PLT emulation #6 */
12587+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
12588+
12589+ err = get_user(sethi, (unsigned int *)regs->tpc);
12590+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
12591+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
12592+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
12593+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
12594+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
12595+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
12596+
12597+ if (err)
12598+ break;
12599+
12600+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12601+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
12602+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12603+ sllx == 0x83287020U &&
12604+ (or & 0xFFFFE000U) == 0x8A116000U &&
12605+ jmpl == 0x81C04005U &&
12606+ nop == 0x01000000U)
12607+ {
12608+ unsigned long addr;
12609+
12610+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
12611+ regs->u_regs[UREG_G1] <<= 32;
12612+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
12613+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
12614+ regs->tpc = addr;
12615+ regs->tnpc = addr+4;
12616+ return 2;
12617+ }
12618+ } while (0);
12619+
12620+ do { /* PaX: unpatched PLT emulation step 1 */
12621+ unsigned int sethi, ba, nop;
12622+
12623+ err = get_user(sethi, (unsigned int *)regs->tpc);
12624+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12625+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12626+
12627+ if (err)
12628+ break;
12629+
12630+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12631+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
12632+ nop == 0x01000000U)
12633+ {
12634+ unsigned long addr;
12635+ unsigned int save, call;
12636+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
12637+
12638+ if ((ba & 0xFFC00000U) == 0x30800000U)
12639+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
12640+ else
12641+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12642+
12643+ if (test_thread_flag(TIF_32BIT))
12644+ addr &= 0xFFFFFFFFUL;
12645+
12646+ err = get_user(save, (unsigned int *)addr);
12647+ err |= get_user(call, (unsigned int *)(addr+4));
12648+ err |= get_user(nop, (unsigned int *)(addr+8));
12649+ if (err)
12650+ break;
12651+
12652+#ifdef CONFIG_PAX_DLRESOLVE
12653+ if (save == 0x9DE3BFA8U &&
12654+ (call & 0xC0000000U) == 0x40000000U &&
12655+ nop == 0x01000000U)
12656+ {
12657+ struct vm_area_struct *vma;
12658+ unsigned long call_dl_resolve;
12659+
12660+ down_read(&current->mm->mmap_sem);
12661+ call_dl_resolve = current->mm->call_dl_resolve;
12662+ up_read(&current->mm->mmap_sem);
12663+ if (likely(call_dl_resolve))
12664+ goto emulate;
12665+
12666+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
12667+
12668+ down_write(&current->mm->mmap_sem);
12669+ if (current->mm->call_dl_resolve) {
12670+ call_dl_resolve = current->mm->call_dl_resolve;
12671+ up_write(&current->mm->mmap_sem);
12672+ if (vma)
12673+ kmem_cache_free(vm_area_cachep, vma);
12674+ goto emulate;
12675+ }
12676+
12677+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
12678+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
12679+ up_write(&current->mm->mmap_sem);
12680+ if (vma)
12681+ kmem_cache_free(vm_area_cachep, vma);
12682+ return 1;
12683+ }
12684+
12685+ if (pax_insert_vma(vma, call_dl_resolve)) {
12686+ up_write(&current->mm->mmap_sem);
12687+ kmem_cache_free(vm_area_cachep, vma);
12688+ return 1;
12689+ }
12690+
12691+ current->mm->call_dl_resolve = call_dl_resolve;
12692+ up_write(&current->mm->mmap_sem);
12693+
12694+emulate:
12695+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12696+ regs->tpc = call_dl_resolve;
12697+ regs->tnpc = addr+4;
12698+ return 3;
12699+ }
12700+#endif
12701+
12702+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
12703+ if ((save & 0xFFC00000U) == 0x05000000U &&
12704+ (call & 0xFFFFE000U) == 0x85C0A000U &&
12705+ nop == 0x01000000U)
12706+ {
12707+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12708+ regs->u_regs[UREG_G2] = addr + 4;
12709+ addr = (save & 0x003FFFFFU) << 10;
12710+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
12711+
12712+ if (test_thread_flag(TIF_32BIT))
12713+ addr &= 0xFFFFFFFFUL;
12714+
12715+ regs->tpc = addr;
12716+ regs->tnpc = addr+4;
12717+ return 3;
12718+ }
12719+
12720+ /* PaX: 64-bit PLT stub */
12721+ err = get_user(sethi1, (unsigned int *)addr);
12722+ err |= get_user(sethi2, (unsigned int *)(addr+4));
12723+ err |= get_user(or1, (unsigned int *)(addr+8));
12724+ err |= get_user(or2, (unsigned int *)(addr+12));
12725+ err |= get_user(sllx, (unsigned int *)(addr+16));
12726+ err |= get_user(add, (unsigned int *)(addr+20));
12727+ err |= get_user(jmpl, (unsigned int *)(addr+24));
12728+ err |= get_user(nop, (unsigned int *)(addr+28));
12729+ if (err)
12730+ break;
12731+
12732+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
12733+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
12734+ (or1 & 0xFFFFE000U) == 0x88112000U &&
12735+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
12736+ sllx == 0x89293020U &&
12737+ add == 0x8A010005U &&
12738+ jmpl == 0x89C14000U &&
12739+ nop == 0x01000000U)
12740+ {
12741+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
12742+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
12743+ regs->u_regs[UREG_G4] <<= 32;
12744+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
12745+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
12746+ regs->u_regs[UREG_G4] = addr + 24;
12747+ addr = regs->u_regs[UREG_G5];
12748+ regs->tpc = addr;
12749+ regs->tnpc = addr+4;
12750+ return 3;
12751+ }
12752+ }
12753+ } while (0);
12754+
12755+#ifdef CONFIG_PAX_DLRESOLVE
12756+ do { /* PaX: unpatched PLT emulation step 2 */
12757+ unsigned int save, call, nop;
12758+
12759+ err = get_user(save, (unsigned int *)(regs->tpc-4));
12760+ err |= get_user(call, (unsigned int *)regs->tpc);
12761+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
12762+ if (err)
12763+ break;
12764+
12765+ if (save == 0x9DE3BFA8U &&
12766+ (call & 0xC0000000U) == 0x40000000U &&
12767+ nop == 0x01000000U)
12768+ {
12769+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
12770+
12771+ if (test_thread_flag(TIF_32BIT))
12772+ dl_resolve &= 0xFFFFFFFFUL;
12773+
12774+ regs->u_regs[UREG_RETPC] = regs->tpc;
12775+ regs->tpc = dl_resolve;
12776+ regs->tnpc = dl_resolve+4;
12777+ return 3;
12778+ }
12779+ } while (0);
12780+#endif
12781+
12782+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
12783+ unsigned int sethi, ba, nop;
12784+
12785+ err = get_user(sethi, (unsigned int *)regs->tpc);
12786+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
12787+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
12788+
12789+ if (err)
12790+ break;
12791+
12792+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
12793+ (ba & 0xFFF00000U) == 0x30600000U &&
12794+ nop == 0x01000000U)
12795+ {
12796+ unsigned long addr;
12797+
12798+ addr = (sethi & 0x003FFFFFU) << 10;
12799+ regs->u_regs[UREG_G1] = addr;
12800+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
12801+
12802+ if (test_thread_flag(TIF_32BIT))
12803+ addr &= 0xFFFFFFFFUL;
12804+
12805+ regs->tpc = addr;
12806+ regs->tnpc = addr+4;
12807+ return 2;
12808+ }
12809+ } while (0);
12810+
12811+#endif
12812+
12813+ return 1;
12814+}
12815+
12816+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
12817+{
12818+ unsigned long i;
12819+
12820+ printk(KERN_ERR "PAX: bytes at PC: ");
12821+ for (i = 0; i < 8; i++) {
12822+ unsigned int c;
12823+ if (get_user(c, (unsigned int *)pc+i))
12824+ printk(KERN_CONT "???????? ");
12825+ else
12826+ printk(KERN_CONT "%08x ", c);
12827+ }
12828+ printk("\n");
12829+}
12830+#endif
12831+
12832 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
12833 {
12834 enum ctx_state prev_state = exception_enter();
12835@@ -353,6 +816,29 @@ retry:
12836 if (!vma)
12837 goto bad_area;
12838
12839+#ifdef CONFIG_PAX_PAGEEXEC
12840+ /* PaX: detect ITLB misses on non-exec pages */
12841+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
12842+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
12843+ {
12844+ if (address != regs->tpc)
12845+ goto good_area;
12846+
12847+ up_read(&mm->mmap_sem);
12848+ switch (pax_handle_fetch_fault(regs)) {
12849+
12850+#ifdef CONFIG_PAX_EMUPLT
12851+ case 2:
12852+ case 3:
12853+ return;
12854+#endif
12855+
12856+ }
12857+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
12858+ do_group_exit(SIGKILL);
12859+ }
12860+#endif
12861+
12862 /* Pure DTLB misses do not tell us whether the fault causing
12863 * load/store/atomic was a write or not, it only says that there
12864 * was no match. So in such a case we (carefully) read the
12865diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
12866index d329537..2c3746a 100644
12867--- a/arch/sparc/mm/hugetlbpage.c
12868+++ b/arch/sparc/mm/hugetlbpage.c
12869@@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12870 unsigned long addr,
12871 unsigned long len,
12872 unsigned long pgoff,
12873- unsigned long flags)
12874+ unsigned long flags,
12875+ unsigned long offset)
12876 {
12877+ struct mm_struct *mm = current->mm;
12878 unsigned long task_size = TASK_SIZE;
12879 struct vm_unmapped_area_info info;
12880
12881@@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
12882
12883 info.flags = 0;
12884 info.length = len;
12885- info.low_limit = TASK_UNMAPPED_BASE;
12886+ info.low_limit = mm->mmap_base;
12887 info.high_limit = min(task_size, VA_EXCLUDE_START);
12888 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12889 info.align_offset = 0;
12890+ info.threadstack_offset = offset;
12891 addr = vm_unmapped_area(&info);
12892
12893 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
12894 VM_BUG_ON(addr != -ENOMEM);
12895 info.low_limit = VA_EXCLUDE_END;
12896+
12897+#ifdef CONFIG_PAX_RANDMMAP
12898+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12899+ info.low_limit += mm->delta_mmap;
12900+#endif
12901+
12902 info.high_limit = task_size;
12903 addr = vm_unmapped_area(&info);
12904 }
12905@@ -55,7 +64,8 @@ static unsigned long
12906 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12907 const unsigned long len,
12908 const unsigned long pgoff,
12909- const unsigned long flags)
12910+ const unsigned long flags,
12911+ const unsigned long offset)
12912 {
12913 struct mm_struct *mm = current->mm;
12914 unsigned long addr = addr0;
12915@@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12916 info.high_limit = mm->mmap_base;
12917 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
12918 info.align_offset = 0;
12919+ info.threadstack_offset = offset;
12920 addr = vm_unmapped_area(&info);
12921
12922 /*
12923@@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
12924 VM_BUG_ON(addr != -ENOMEM);
12925 info.flags = 0;
12926 info.low_limit = TASK_UNMAPPED_BASE;
12927+
12928+#ifdef CONFIG_PAX_RANDMMAP
12929+ if (mm->pax_flags & MF_PAX_RANDMMAP)
12930+ info.low_limit += mm->delta_mmap;
12931+#endif
12932+
12933 info.high_limit = STACK_TOP32;
12934 addr = vm_unmapped_area(&info);
12935 }
12936@@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12937 struct mm_struct *mm = current->mm;
12938 struct vm_area_struct *vma;
12939 unsigned long task_size = TASK_SIZE;
12940+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12941
12942 if (test_thread_flag(TIF_32BIT))
12943 task_size = STACK_TOP32;
12944@@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12945 return addr;
12946 }
12947
12948+#ifdef CONFIG_PAX_RANDMMAP
12949+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12950+#endif
12951+
12952 if (addr) {
12953 addr = ALIGN(addr, HPAGE_SIZE);
12954 vma = find_vma(mm, addr);
12955- if (task_size - len >= addr &&
12956- (!vma || addr + len <= vma->vm_start))
12957+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12958 return addr;
12959 }
12960 if (mm->get_unmapped_area == arch_get_unmapped_area)
12961 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12962- pgoff, flags);
12963+ pgoff, flags, offset);
12964 else
12965 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12966- pgoff, flags);
12967+ pgoff, flags, offset);
12968 }
12969
12970 pte_t *huge_pte_alloc(struct mm_struct *mm,
12971diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12972index 04bc826..0fefab9 100644
12973--- a/arch/sparc/mm/init_64.c
12974+++ b/arch/sparc/mm/init_64.c
12975@@ -186,9 +186,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12976 int num_kernel_image_mappings;
12977
12978 #ifdef CONFIG_DEBUG_DCFLUSH
12979-atomic_t dcpage_flushes = ATOMIC_INIT(0);
12980+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12981 #ifdef CONFIG_SMP
12982-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12983+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12984 #endif
12985 #endif
12986
12987@@ -196,7 +196,7 @@ inline void flush_dcache_page_impl(struct page *page)
12988 {
12989 BUG_ON(tlb_type == hypervisor);
12990 #ifdef CONFIG_DEBUG_DCFLUSH
12991- atomic_inc(&dcpage_flushes);
12992+ atomic_inc_unchecked(&dcpage_flushes);
12993 #endif
12994
12995 #ifdef DCACHE_ALIASING_POSSIBLE
12996@@ -468,10 +468,10 @@ void mmu_info(struct seq_file *m)
12997
12998 #ifdef CONFIG_DEBUG_DCFLUSH
12999 seq_printf(m, "DCPageFlushes\t: %d\n",
13000- atomic_read(&dcpage_flushes));
13001+ atomic_read_unchecked(&dcpage_flushes));
13002 #ifdef CONFIG_SMP
13003 seq_printf(m, "DCPageFlushesXC\t: %d\n",
13004- atomic_read(&dcpage_flushes_xcall));
13005+ atomic_read_unchecked(&dcpage_flushes_xcall));
13006 #endif /* CONFIG_SMP */
13007 #endif /* CONFIG_DEBUG_DCFLUSH */
13008 }
13009diff --git a/arch/sparc/net/bpf_jit_comp.c b/arch/sparc/net/bpf_jit_comp.c
13010index ece4af0..f04b862 100644
13011--- a/arch/sparc/net/bpf_jit_comp.c
13012+++ b/arch/sparc/net/bpf_jit_comp.c
13013@@ -823,5 +823,6 @@ void bpf_jit_free(struct bpf_prog *fp)
13014 {
13015 if (fp->jited)
13016 module_free(NULL, fp->bpf_func);
13017- kfree(fp);
13018+
13019+ bpf_prog_unlock_free(fp);
13020 }
13021diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
13022index 7fcd492..1311074 100644
13023--- a/arch/tile/Kconfig
13024+++ b/arch/tile/Kconfig
13025@@ -191,6 +191,7 @@ source "kernel/Kconfig.hz"
13026
13027 config KEXEC
13028 bool "kexec system call"
13029+ depends on !GRKERNSEC_KMEM
13030 ---help---
13031 kexec is a system call that implements the ability to shutdown your
13032 current kernel, and to start another kernel. It is like a reboot
13033diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
13034index 7b11c5f..755a026 100644
13035--- a/arch/tile/include/asm/atomic_64.h
13036+++ b/arch/tile/include/asm/atomic_64.h
13037@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
13038
13039 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
13040
13041+#define atomic64_read_unchecked(v) atomic64_read(v)
13042+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
13043+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
13044+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
13045+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
13046+#define atomic64_inc_unchecked(v) atomic64_inc(v)
13047+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
13048+#define atomic64_dec_unchecked(v) atomic64_dec(v)
13049+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
13050+
13051 /* Define this to indicate that cmpxchg is an efficient operation. */
13052 #define __HAVE_ARCH_CMPXCHG
13053
13054diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
13055index 6160761..00cac88 100644
13056--- a/arch/tile/include/asm/cache.h
13057+++ b/arch/tile/include/asm/cache.h
13058@@ -15,11 +15,12 @@
13059 #ifndef _ASM_TILE_CACHE_H
13060 #define _ASM_TILE_CACHE_H
13061
13062+#include <linux/const.h>
13063 #include <arch/chip.h>
13064
13065 /* bytes per L1 data cache line */
13066 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
13067-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13068+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13069
13070 /* bytes per L2 cache line */
13071 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
13072diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
13073index b6cde32..c0cb736 100644
13074--- a/arch/tile/include/asm/uaccess.h
13075+++ b/arch/tile/include/asm/uaccess.h
13076@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
13077 const void __user *from,
13078 unsigned long n)
13079 {
13080- int sz = __compiletime_object_size(to);
13081+ size_t sz = __compiletime_object_size(to);
13082
13083- if (likely(sz == -1 || sz >= n))
13084+ if (likely(sz == (size_t)-1 || sz >= n))
13085 n = _copy_from_user(to, from, n);
13086 else
13087 copy_from_user_overflow();
13088diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
13089index e514899..f8743c4 100644
13090--- a/arch/tile/mm/hugetlbpage.c
13091+++ b/arch/tile/mm/hugetlbpage.c
13092@@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
13093 info.high_limit = TASK_SIZE;
13094 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
13095 info.align_offset = 0;
13096+ info.threadstack_offset = 0;
13097 return vm_unmapped_area(&info);
13098 }
13099
13100@@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
13101 info.high_limit = current->mm->mmap_base;
13102 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
13103 info.align_offset = 0;
13104+ info.threadstack_offset = 0;
13105 addr = vm_unmapped_area(&info);
13106
13107 /*
13108diff --git a/arch/um/Makefile b/arch/um/Makefile
13109index e4b1a96..16162f8 100644
13110--- a/arch/um/Makefile
13111+++ b/arch/um/Makefile
13112@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
13113 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
13114 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
13115
13116+ifdef CONSTIFY_PLUGIN
13117+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
13118+endif
13119+
13120 #This will adjust *FLAGS accordingly to the platform.
13121 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
13122
13123diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
13124index 19e1bdd..3665b77 100644
13125--- a/arch/um/include/asm/cache.h
13126+++ b/arch/um/include/asm/cache.h
13127@@ -1,6 +1,7 @@
13128 #ifndef __UM_CACHE_H
13129 #define __UM_CACHE_H
13130
13131+#include <linux/const.h>
13132
13133 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
13134 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
13135@@ -12,6 +13,6 @@
13136 # define L1_CACHE_SHIFT 5
13137 #endif
13138
13139-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13140+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13141
13142 #endif
13143diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
13144index 2e0a6b1..a64d0f5 100644
13145--- a/arch/um/include/asm/kmap_types.h
13146+++ b/arch/um/include/asm/kmap_types.h
13147@@ -8,6 +8,6 @@
13148
13149 /* No more #include "asm/arch/kmap_types.h" ! */
13150
13151-#define KM_TYPE_NR 14
13152+#define KM_TYPE_NR 15
13153
13154 #endif
13155diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
13156index 71c5d13..4c7b9f1 100644
13157--- a/arch/um/include/asm/page.h
13158+++ b/arch/um/include/asm/page.h
13159@@ -14,6 +14,9 @@
13160 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
13161 #define PAGE_MASK (~(PAGE_SIZE-1))
13162
13163+#define ktla_ktva(addr) (addr)
13164+#define ktva_ktla(addr) (addr)
13165+
13166 #ifndef __ASSEMBLY__
13167
13168 struct page;
13169diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
13170index 0032f92..cd151e0 100644
13171--- a/arch/um/include/asm/pgtable-3level.h
13172+++ b/arch/um/include/asm/pgtable-3level.h
13173@@ -58,6 +58,7 @@
13174 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
13175 #define pud_populate(mm, pud, pmd) \
13176 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
13177+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
13178
13179 #ifdef CONFIG_64BIT
13180 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
13181diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
13182index f17bca8..48adb87 100644
13183--- a/arch/um/kernel/process.c
13184+++ b/arch/um/kernel/process.c
13185@@ -356,22 +356,6 @@ int singlestepping(void * t)
13186 return 2;
13187 }
13188
13189-/*
13190- * Only x86 and x86_64 have an arch_align_stack().
13191- * All other arches have "#define arch_align_stack(x) (x)"
13192- * in their asm/exec.h
13193- * As this is included in UML from asm-um/system-generic.h,
13194- * we can use it to behave as the subarch does.
13195- */
13196-#ifndef arch_align_stack
13197-unsigned long arch_align_stack(unsigned long sp)
13198-{
13199- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
13200- sp -= get_random_int() % 8192;
13201- return sp & ~0xf;
13202-}
13203-#endif
13204-
13205 unsigned long get_wchan(struct task_struct *p)
13206 {
13207 unsigned long stack_page, sp, ip;
13208diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
13209index ad8f795..2c7eec6 100644
13210--- a/arch/unicore32/include/asm/cache.h
13211+++ b/arch/unicore32/include/asm/cache.h
13212@@ -12,8 +12,10 @@
13213 #ifndef __UNICORE_CACHE_H__
13214 #define __UNICORE_CACHE_H__
13215
13216-#define L1_CACHE_SHIFT (5)
13217-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
13218+#include <linux/const.h>
13219+
13220+#define L1_CACHE_SHIFT 5
13221+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
13222
13223 /*
13224 * Memory returned by kmalloc() may be used for DMA, so we must make
13225diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
13226index 3632743..630a8bb 100644
13227--- a/arch/x86/Kconfig
13228+++ b/arch/x86/Kconfig
13229@@ -130,7 +130,7 @@ config X86
13230 select RTC_LIB
13231 select HAVE_DEBUG_STACKOVERFLOW
13232 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
13233- select HAVE_CC_STACKPROTECTOR
13234+ select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
13235 select GENERIC_CPU_AUTOPROBE
13236 select HAVE_ARCH_AUDITSYSCALL
13237 select ARCH_SUPPORTS_ATOMIC_RMW
13238@@ -258,7 +258,7 @@ config X86_HT
13239
13240 config X86_32_LAZY_GS
13241 def_bool y
13242- depends on X86_32 && !CC_STACKPROTECTOR
13243+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
13244
13245 config ARCH_HWEIGHT_CFLAGS
13246 string
13247@@ -555,6 +555,7 @@ config SCHED_OMIT_FRAME_POINTER
13248
13249 menuconfig HYPERVISOR_GUEST
13250 bool "Linux guest support"
13251+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
13252 ---help---
13253 Say Y here to enable options for running Linux under various hyper-
13254 visors. This option enables basic hypervisor detection and platform
13255@@ -1083,6 +1084,7 @@ choice
13256
13257 config NOHIGHMEM
13258 bool "off"
13259+ depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
13260 ---help---
13261 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
13262 However, the address space of 32-bit x86 processors is only 4
13263@@ -1119,6 +1121,7 @@ config NOHIGHMEM
13264
13265 config HIGHMEM4G
13266 bool "4GB"
13267+ depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
13268 ---help---
13269 Select this if you have a 32-bit processor and between 1 and 4
13270 gigabytes of physical RAM.
13271@@ -1171,7 +1174,7 @@ config PAGE_OFFSET
13272 hex
13273 default 0xB0000000 if VMSPLIT_3G_OPT
13274 default 0x80000000 if VMSPLIT_2G
13275- default 0x78000000 if VMSPLIT_2G_OPT
13276+ default 0x70000000 if VMSPLIT_2G_OPT
13277 default 0x40000000 if VMSPLIT_1G
13278 default 0xC0000000
13279 depends on X86_32
13280@@ -1586,6 +1589,7 @@ source kernel/Kconfig.hz
13281
13282 config KEXEC
13283 bool "kexec system call"
13284+ depends on !GRKERNSEC_KMEM
13285 ---help---
13286 kexec is a system call that implements the ability to shutdown your
13287 current kernel, and to start another kernel. It is like a reboot
13288@@ -1771,7 +1775,9 @@ config X86_NEED_RELOCS
13289
13290 config PHYSICAL_ALIGN
13291 hex "Alignment value to which kernel should be aligned"
13292- default "0x200000"
13293+ default "0x1000000"
13294+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
13295+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
13296 range 0x2000 0x1000000 if X86_32
13297 range 0x200000 0x1000000 if X86_64
13298 ---help---
13299@@ -1854,6 +1860,7 @@ config COMPAT_VDSO
13300 def_bool n
13301 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
13302 depends on X86_32 || IA32_EMULATION
13303+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
13304 ---help---
13305 Certain buggy versions of glibc will crash if they are
13306 presented with a 32-bit vDSO that is not mapped at the address
13307diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
13308index 6983314..54ad7e8 100644
13309--- a/arch/x86/Kconfig.cpu
13310+++ b/arch/x86/Kconfig.cpu
13311@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
13312
13313 config X86_F00F_BUG
13314 def_bool y
13315- depends on M586MMX || M586TSC || M586 || M486
13316+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
13317
13318 config X86_INVD_BUG
13319 def_bool y
13320@@ -327,7 +327,7 @@ config X86_INVD_BUG
13321
13322 config X86_ALIGNMENT_16
13323 def_bool y
13324- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
13325+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
13326
13327 config X86_INTEL_USERCOPY
13328 def_bool y
13329@@ -369,7 +369,7 @@ config X86_CMPXCHG64
13330 # generates cmov.
13331 config X86_CMOV
13332 def_bool y
13333- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
13334+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
13335
13336 config X86_MINIMUM_CPU_FAMILY
13337 int
13338diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
13339index 61bd2ad..50b625d 100644
13340--- a/arch/x86/Kconfig.debug
13341+++ b/arch/x86/Kconfig.debug
13342@@ -93,7 +93,7 @@ config EFI_PGT_DUMP
13343 config DEBUG_RODATA
13344 bool "Write protect kernel read-only data structures"
13345 default y
13346- depends on DEBUG_KERNEL
13347+ depends on DEBUG_KERNEL && BROKEN
13348 ---help---
13349 Mark the kernel read-only data as write-protected in the pagetables,
13350 in order to catch accidental (and incorrect) writes to such const
13351@@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
13352
13353 config DEBUG_SET_MODULE_RONX
13354 bool "Set loadable kernel module data as NX and text as RO"
13355- depends on MODULES
13356+ depends on MODULES && BROKEN
13357 ---help---
13358 This option helps catch unintended modifications to loadable
13359 kernel module's text and read-only data. It also prevents execution
13360diff --git a/arch/x86/Makefile b/arch/x86/Makefile
13361index 60087ca..9d9500e 100644
13362--- a/arch/x86/Makefile
13363+++ b/arch/x86/Makefile
13364@@ -68,9 +68,6 @@ ifeq ($(CONFIG_X86_32),y)
13365 # CPU-specific tuning. Anything which can be shared with UML should go here.
13366 include $(srctree)/arch/x86/Makefile_32.cpu
13367 KBUILD_CFLAGS += $(cflags-y)
13368-
13369- # temporary until string.h is fixed
13370- KBUILD_CFLAGS += -ffreestanding
13371 else
13372 BITS := 64
13373 UTS_MACHINE := x86_64
13374@@ -111,6 +108,9 @@ else
13375 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
13376 endif
13377
13378+# temporary until string.h is fixed
13379+KBUILD_CFLAGS += -ffreestanding
13380+
13381 # Make sure compiler does not have buggy stack-protector support.
13382 ifdef CONFIG_CC_STACKPROTECTOR
13383 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
13384@@ -184,6 +184,7 @@ archheaders:
13385 $(Q)$(MAKE) $(build)=arch/x86/syscalls all
13386
13387 archprepare:
13388+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
13389 ifeq ($(CONFIG_KEXEC_FILE),y)
13390 $(Q)$(MAKE) $(build)=arch/x86/purgatory arch/x86/purgatory/kexec-purgatory.c
13391 endif
13392@@ -274,3 +275,9 @@ define archhelp
13393 echo ' FDINITRD=file initrd for the booted kernel'
13394 echo ' kvmconfig - Enable additional options for guest kernel support'
13395 endef
13396+
13397+define OLD_LD
13398+
13399+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
13400+*** Please upgrade your binutils to 2.18 or newer
13401+endef
13402diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
13403index dbe8dd2..2f0a98f 100644
13404--- a/arch/x86/boot/Makefile
13405+++ b/arch/x86/boot/Makefile
13406@@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
13407 # ---------------------------------------------------------------------------
13408
13409 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
13410+ifdef CONSTIFY_PLUGIN
13411+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
13412+endif
13413 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13414 GCOV_PROFILE := n
13415
13416diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
13417index 878e4b9..20537ab 100644
13418--- a/arch/x86/boot/bitops.h
13419+++ b/arch/x86/boot/bitops.h
13420@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
13421 u8 v;
13422 const u32 *p = (const u32 *)addr;
13423
13424- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
13425+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
13426 return v;
13427 }
13428
13429@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
13430
13431 static inline void set_bit(int nr, void *addr)
13432 {
13433- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
13434+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
13435 }
13436
13437 #endif /* BOOT_BITOPS_H */
13438diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
13439index bd49ec6..94c7f58 100644
13440--- a/arch/x86/boot/boot.h
13441+++ b/arch/x86/boot/boot.h
13442@@ -84,7 +84,7 @@ static inline void io_delay(void)
13443 static inline u16 ds(void)
13444 {
13445 u16 seg;
13446- asm("movw %%ds,%0" : "=rm" (seg));
13447+ asm volatile("movw %%ds,%0" : "=rm" (seg));
13448 return seg;
13449 }
13450
13451diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
13452index 0fcd913..3bb5c42 100644
13453--- a/arch/x86/boot/compressed/Makefile
13454+++ b/arch/x86/boot/compressed/Makefile
13455@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
13456 KBUILD_CFLAGS += -mno-mmx -mno-sse
13457 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
13458 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
13459+ifdef CONSTIFY_PLUGIN
13460+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
13461+endif
13462
13463 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
13464 GCOV_PROFILE := n
13465diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
13466index a53440e..c3dbf1e 100644
13467--- a/arch/x86/boot/compressed/efi_stub_32.S
13468+++ b/arch/x86/boot/compressed/efi_stub_32.S
13469@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
13470 * parameter 2, ..., param n. To make things easy, we save the return
13471 * address of efi_call_phys in a global variable.
13472 */
13473- popl %ecx
13474- movl %ecx, saved_return_addr(%edx)
13475- /* get the function pointer into ECX*/
13476- popl %ecx
13477- movl %ecx, efi_rt_function_ptr(%edx)
13478+ popl saved_return_addr(%edx)
13479+ popl efi_rt_function_ptr(%edx)
13480
13481 /*
13482 * 3. Call the physical function.
13483 */
13484- call *%ecx
13485+ call *efi_rt_function_ptr(%edx)
13486
13487 /*
13488 * 4. Balance the stack. And because EAX contain the return value,
13489@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
13490 1: popl %edx
13491 subl $1b, %edx
13492
13493- movl efi_rt_function_ptr(%edx), %ecx
13494- pushl %ecx
13495+ pushl efi_rt_function_ptr(%edx)
13496
13497 /*
13498 * 10. Push the saved return address onto the stack and return.
13499 */
13500- movl saved_return_addr(%edx), %ecx
13501- pushl %ecx
13502- ret
13503+ jmpl *saved_return_addr(%edx)
13504 ENDPROC(efi_call_phys)
13505 .previous
13506
13507diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
13508index cbed140..5f2ca57 100644
13509--- a/arch/x86/boot/compressed/head_32.S
13510+++ b/arch/x86/boot/compressed/head_32.S
13511@@ -140,10 +140,10 @@ preferred_addr:
13512 addl %eax, %ebx
13513 notl %eax
13514 andl %eax, %ebx
13515- cmpl $LOAD_PHYSICAL_ADDR, %ebx
13516+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13517 jge 1f
13518 #endif
13519- movl $LOAD_PHYSICAL_ADDR, %ebx
13520+ movl $____LOAD_PHYSICAL_ADDR, %ebx
13521 1:
13522
13523 /* Target address to relocate to for decompression */
13524diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
13525index 2884e0c..904a2f7 100644
13526--- a/arch/x86/boot/compressed/head_64.S
13527+++ b/arch/x86/boot/compressed/head_64.S
13528@@ -94,10 +94,10 @@ ENTRY(startup_32)
13529 addl %eax, %ebx
13530 notl %eax
13531 andl %eax, %ebx
13532- cmpl $LOAD_PHYSICAL_ADDR, %ebx
13533+ cmpl $____LOAD_PHYSICAL_ADDR, %ebx
13534 jge 1f
13535 #endif
13536- movl $LOAD_PHYSICAL_ADDR, %ebx
13537+ movl $____LOAD_PHYSICAL_ADDR, %ebx
13538 1:
13539
13540 /* Target address to relocate to for decompression */
13541@@ -322,10 +322,10 @@ preferred_addr:
13542 addq %rax, %rbp
13543 notq %rax
13544 andq %rax, %rbp
13545- cmpq $LOAD_PHYSICAL_ADDR, %rbp
13546+ cmpq $____LOAD_PHYSICAL_ADDR, %rbp
13547 jge 1f
13548 #endif
13549- movq $LOAD_PHYSICAL_ADDR, %rbp
13550+ movq $____LOAD_PHYSICAL_ADDR, %rbp
13551 1:
13552
13553 /* Target address to relocate to for decompression */
13554@@ -431,8 +431,8 @@ gdt:
13555 .long gdt
13556 .word 0
13557 .quad 0x0000000000000000 /* NULL descriptor */
13558- .quad 0x00af9a000000ffff /* __KERNEL_CS */
13559- .quad 0x00cf92000000ffff /* __KERNEL_DS */
13560+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
13561+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
13562 .quad 0x0080890000000000 /* TS descriptor */
13563 .quad 0x0000000000000000 /* TS continued */
13564 gdt_end:
13565diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
13566index 57ab74d..7c52182 100644
13567--- a/arch/x86/boot/compressed/misc.c
13568+++ b/arch/x86/boot/compressed/misc.c
13569@@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
13570 * Calculate the delta between where vmlinux was linked to load
13571 * and where it was actually loaded.
13572 */
13573- delta = min_addr - LOAD_PHYSICAL_ADDR;
13574+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
13575 if (!delta) {
13576 debug_putstr("No relocation needed... ");
13577 return;
13578@@ -312,7 +312,7 @@ static void parse_elf(void *output)
13579 Elf32_Ehdr ehdr;
13580 Elf32_Phdr *phdrs, *phdr;
13581 #endif
13582- void *dest;
13583+ void *dest, *prev;
13584 int i;
13585
13586 memcpy(&ehdr, output, sizeof(ehdr));
13587@@ -339,13 +339,16 @@ static void parse_elf(void *output)
13588 case PT_LOAD:
13589 #ifdef CONFIG_RELOCATABLE
13590 dest = output;
13591- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
13592+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
13593 #else
13594 dest = (void *)(phdr->p_paddr);
13595 #endif
13596 memcpy(dest,
13597 output + phdr->p_offset,
13598 phdr->p_filesz);
13599+ if (i)
13600+ memset(prev, 0xff, dest - prev);
13601+ prev = dest + phdr->p_filesz;
13602 break;
13603 default: /* Ignore other PT_* */ break;
13604 }
13605@@ -395,7 +398,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
13606 error("Destination address too large");
13607 #endif
13608 #ifndef CONFIG_RELOCATABLE
13609- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
13610+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
13611 error("Wrong destination address");
13612 #endif
13613
13614diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
13615index 1fd7d57..0f7d096 100644
13616--- a/arch/x86/boot/cpucheck.c
13617+++ b/arch/x86/boot/cpucheck.c
13618@@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13619 u32 ecx = MSR_K7_HWCR;
13620 u32 eax, edx;
13621
13622- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13623+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13624 eax &= ~(1 << 15);
13625- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13626+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13627
13628 get_cpuflags(); /* Make sure it really did something */
13629 err = check_cpuflags();
13630@@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13631 u32 ecx = MSR_VIA_FCR;
13632 u32 eax, edx;
13633
13634- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13635+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13636 eax |= (1<<1)|(1<<7);
13637- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13638+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13639
13640 set_bit(X86_FEATURE_CX8, cpu.flags);
13641 err = check_cpuflags();
13642@@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
13643 u32 eax, edx;
13644 u32 level = 1;
13645
13646- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13647- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13648- asm("cpuid"
13649+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
13650+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
13651+ asm volatile("cpuid"
13652 : "+a" (level), "=d" (cpu.flags[0])
13653 : : "ecx", "ebx");
13654- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13655+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
13656
13657 err = check_cpuflags();
13658 } else if (err == 0x01 &&
13659diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
13660index 16ef025..91e033b 100644
13661--- a/arch/x86/boot/header.S
13662+++ b/arch/x86/boot/header.S
13663@@ -438,10 +438,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
13664 # single linked list of
13665 # struct setup_data
13666
13667-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
13668+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
13669
13670 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
13671+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13672+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
13673+#else
13674 #define VO_INIT_SIZE (VO__end - VO__text)
13675+#endif
13676 #if ZO_INIT_SIZE > VO_INIT_SIZE
13677 #define INIT_SIZE ZO_INIT_SIZE
13678 #else
13679diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
13680index db75d07..8e6d0af 100644
13681--- a/arch/x86/boot/memory.c
13682+++ b/arch/x86/boot/memory.c
13683@@ -19,7 +19,7 @@
13684
13685 static int detect_memory_e820(void)
13686 {
13687- int count = 0;
13688+ unsigned int count = 0;
13689 struct biosregs ireg, oreg;
13690 struct e820entry *desc = boot_params.e820_map;
13691 static struct e820entry buf; /* static so it is zeroed */
13692diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
13693index ba3e100..6501b8f 100644
13694--- a/arch/x86/boot/video-vesa.c
13695+++ b/arch/x86/boot/video-vesa.c
13696@@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
13697
13698 boot_params.screen_info.vesapm_seg = oreg.es;
13699 boot_params.screen_info.vesapm_off = oreg.di;
13700+ boot_params.screen_info.vesapm_size = oreg.cx;
13701 }
13702
13703 /*
13704diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
13705index 43eda28..5ab5fdb 100644
13706--- a/arch/x86/boot/video.c
13707+++ b/arch/x86/boot/video.c
13708@@ -96,7 +96,7 @@ static void store_mode_params(void)
13709 static unsigned int get_entry(void)
13710 {
13711 char entry_buf[4];
13712- int i, len = 0;
13713+ unsigned int i, len = 0;
13714 int key;
13715 unsigned int v;
13716
13717diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
13718index 9105655..41779c1 100644
13719--- a/arch/x86/crypto/aes-x86_64-asm_64.S
13720+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
13721@@ -8,6 +8,8 @@
13722 * including this sentence is retained in full.
13723 */
13724
13725+#include <asm/alternative-asm.h>
13726+
13727 .extern crypto_ft_tab
13728 .extern crypto_it_tab
13729 .extern crypto_fl_tab
13730@@ -70,6 +72,8 @@
13731 je B192; \
13732 leaq 32(r9),r9;
13733
13734+#define ret pax_force_retaddr; ret
13735+
13736 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
13737 movq r1,r2; \
13738 movq r3,r4; \
13739diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
13740index 477e9d7..c92c7d8 100644
13741--- a/arch/x86/crypto/aesni-intel_asm.S
13742+++ b/arch/x86/crypto/aesni-intel_asm.S
13743@@ -31,6 +31,7 @@
13744
13745 #include <linux/linkage.h>
13746 #include <asm/inst.h>
13747+#include <asm/alternative-asm.h>
13748
13749 #ifdef __x86_64__
13750 .data
13751@@ -205,7 +206,7 @@ enc: .octa 0x2
13752 * num_initial_blocks = b mod 4
13753 * encrypt the initial num_initial_blocks blocks and apply ghash on
13754 * the ciphertext
13755-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13756+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13757 * are clobbered
13758 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13759 */
13760@@ -214,8 +215,8 @@ enc: .octa 0x2
13761 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13762 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13763 mov arg7, %r10 # %r10 = AAD
13764- mov arg8, %r12 # %r12 = aadLen
13765- mov %r12, %r11
13766+ mov arg8, %r15 # %r15 = aadLen
13767+ mov %r15, %r11
13768 pxor %xmm\i, %xmm\i
13769 _get_AAD_loop\num_initial_blocks\operation:
13770 movd (%r10), \TMP1
13771@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13772 psrldq $4, %xmm\i
13773 pxor \TMP1, %xmm\i
13774 add $4, %r10
13775- sub $4, %r12
13776+ sub $4, %r15
13777 jne _get_AAD_loop\num_initial_blocks\operation
13778 cmp $16, %r11
13779 je _get_AAD_loop2_done\num_initial_blocks\operation
13780- mov $16, %r12
13781+ mov $16, %r15
13782 _get_AAD_loop2\num_initial_blocks\operation:
13783 psrldq $4, %xmm\i
13784- sub $4, %r12
13785- cmp %r11, %r12
13786+ sub $4, %r15
13787+ cmp %r11, %r15
13788 jne _get_AAD_loop2\num_initial_blocks\operation
13789 _get_AAD_loop2_done\num_initial_blocks\operation:
13790 movdqa SHUF_MASK(%rip), %xmm14
13791@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
13792 * num_initial_blocks = b mod 4
13793 * encrypt the initial num_initial_blocks blocks and apply ghash on
13794 * the ciphertext
13795-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13796+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
13797 * are clobbered
13798 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
13799 */
13800@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
13801 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
13802 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
13803 mov arg7, %r10 # %r10 = AAD
13804- mov arg8, %r12 # %r12 = aadLen
13805- mov %r12, %r11
13806+ mov arg8, %r15 # %r15 = aadLen
13807+ mov %r15, %r11
13808 pxor %xmm\i, %xmm\i
13809 _get_AAD_loop\num_initial_blocks\operation:
13810 movd (%r10), \TMP1
13811@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
13812 psrldq $4, %xmm\i
13813 pxor \TMP1, %xmm\i
13814 add $4, %r10
13815- sub $4, %r12
13816+ sub $4, %r15
13817 jne _get_AAD_loop\num_initial_blocks\operation
13818 cmp $16, %r11
13819 je _get_AAD_loop2_done\num_initial_blocks\operation
13820- mov $16, %r12
13821+ mov $16, %r15
13822 _get_AAD_loop2\num_initial_blocks\operation:
13823 psrldq $4, %xmm\i
13824- sub $4, %r12
13825- cmp %r11, %r12
13826+ sub $4, %r15
13827+ cmp %r11, %r15
13828 jne _get_AAD_loop2\num_initial_blocks\operation
13829 _get_AAD_loop2_done\num_initial_blocks\operation:
13830 movdqa SHUF_MASK(%rip), %xmm14
13831@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
13832 *
13833 *****************************************************************************/
13834 ENTRY(aesni_gcm_dec)
13835- push %r12
13836+ push %r15
13837 push %r13
13838 push %r14
13839 mov %rsp, %r14
13840@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
13841 */
13842 sub $VARIABLE_OFFSET, %rsp
13843 and $~63, %rsp # align rsp to 64 bytes
13844- mov %arg6, %r12
13845- movdqu (%r12), %xmm13 # %xmm13 = HashKey
13846+ mov %arg6, %r15
13847+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
13848 movdqa SHUF_MASK(%rip), %xmm2
13849 PSHUFB_XMM %xmm2, %xmm13
13850
13851@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
13852 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
13853 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
13854 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
13855- mov %r13, %r12
13856- and $(3<<4), %r12
13857+ mov %r13, %r15
13858+ and $(3<<4), %r15
13859 jz _initial_num_blocks_is_0_decrypt
13860- cmp $(2<<4), %r12
13861+ cmp $(2<<4), %r15
13862 jb _initial_num_blocks_is_1_decrypt
13863 je _initial_num_blocks_is_2_decrypt
13864 _initial_num_blocks_is_3_decrypt:
13865@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
13866 sub $16, %r11
13867 add %r13, %r11
13868 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
13869- lea SHIFT_MASK+16(%rip), %r12
13870- sub %r13, %r12
13871+ lea SHIFT_MASK+16(%rip), %r15
13872+ sub %r13, %r15
13873 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
13874 # (%r13 is the number of bytes in plaintext mod 16)
13875- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13876+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13877 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
13878
13879 movdqa %xmm1, %xmm2
13880 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
13881- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13882+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13883 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
13884 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
13885 pand %xmm1, %xmm2
13886@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
13887 sub $1, %r13
13888 jne _less_than_8_bytes_left_decrypt
13889 _multiple_of_16_bytes_decrypt:
13890- mov arg8, %r12 # %r13 = aadLen (number of bytes)
13891- shl $3, %r12 # convert into number of bits
13892- movd %r12d, %xmm15 # len(A) in %xmm15
13893+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
13894+ shl $3, %r15 # convert into number of bits
13895+ movd %r15d, %xmm15 # len(A) in %xmm15
13896 shl $3, %arg4 # len(C) in bits (*128)
13897 MOVQ_R64_XMM %arg4, %xmm1
13898 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13899@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
13900 mov %r14, %rsp
13901 pop %r14
13902 pop %r13
13903- pop %r12
13904+ pop %r15
13905+ pax_force_retaddr
13906 ret
13907 ENDPROC(aesni_gcm_dec)
13908
13909@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
13910 * poly = x^128 + x^127 + x^126 + x^121 + 1
13911 ***************************************************************************/
13912 ENTRY(aesni_gcm_enc)
13913- push %r12
13914+ push %r15
13915 push %r13
13916 push %r14
13917 mov %rsp, %r14
13918@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
13919 #
13920 sub $VARIABLE_OFFSET, %rsp
13921 and $~63, %rsp
13922- mov %arg6, %r12
13923- movdqu (%r12), %xmm13
13924+ mov %arg6, %r15
13925+ movdqu (%r15), %xmm13
13926 movdqa SHUF_MASK(%rip), %xmm2
13927 PSHUFB_XMM %xmm2, %xmm13
13928
13929@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
13930 movdqa %xmm13, HashKey(%rsp)
13931 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
13932 and $-16, %r13
13933- mov %r13, %r12
13934+ mov %r13, %r15
13935
13936 # Encrypt first few blocks
13937
13938- and $(3<<4), %r12
13939+ and $(3<<4), %r15
13940 jz _initial_num_blocks_is_0_encrypt
13941- cmp $(2<<4), %r12
13942+ cmp $(2<<4), %r15
13943 jb _initial_num_blocks_is_1_encrypt
13944 je _initial_num_blocks_is_2_encrypt
13945 _initial_num_blocks_is_3_encrypt:
13946@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13947 sub $16, %r11
13948 add %r13, %r11
13949 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13950- lea SHIFT_MASK+16(%rip), %r12
13951- sub %r13, %r12
13952+ lea SHIFT_MASK+16(%rip), %r15
13953+ sub %r13, %r15
13954 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13955 # (%r13 is the number of bytes in plaintext mod 16)
13956- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13957+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13958 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13959 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13960- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13961+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13962 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13963 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13964 movdqa SHUF_MASK(%rip), %xmm10
13965@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13966 sub $1, %r13
13967 jne _less_than_8_bytes_left_encrypt
13968 _multiple_of_16_bytes_encrypt:
13969- mov arg8, %r12 # %r12 = addLen (number of bytes)
13970- shl $3, %r12
13971- movd %r12d, %xmm15 # len(A) in %xmm15
13972+ mov arg8, %r15 # %r15 = addLen (number of bytes)
13973+ shl $3, %r15
13974+ movd %r15d, %xmm15 # len(A) in %xmm15
13975 shl $3, %arg4 # len(C) in bits (*128)
13976 MOVQ_R64_XMM %arg4, %xmm1
13977 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13978@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13979 mov %r14, %rsp
13980 pop %r14
13981 pop %r13
13982- pop %r12
13983+ pop %r15
13984+ pax_force_retaddr
13985 ret
13986 ENDPROC(aesni_gcm_enc)
13987
13988@@ -1722,6 +1725,7 @@ _key_expansion_256a:
13989 pxor %xmm1, %xmm0
13990 movaps %xmm0, (TKEYP)
13991 add $0x10, TKEYP
13992+ pax_force_retaddr
13993 ret
13994 ENDPROC(_key_expansion_128)
13995 ENDPROC(_key_expansion_256a)
13996@@ -1748,6 +1752,7 @@ _key_expansion_192a:
13997 shufps $0b01001110, %xmm2, %xmm1
13998 movaps %xmm1, 0x10(TKEYP)
13999 add $0x20, TKEYP
14000+ pax_force_retaddr
14001 ret
14002 ENDPROC(_key_expansion_192a)
14003
14004@@ -1768,6 +1773,7 @@ _key_expansion_192b:
14005
14006 movaps %xmm0, (TKEYP)
14007 add $0x10, TKEYP
14008+ pax_force_retaddr
14009 ret
14010 ENDPROC(_key_expansion_192b)
14011
14012@@ -1781,6 +1787,7 @@ _key_expansion_256b:
14013 pxor %xmm1, %xmm2
14014 movaps %xmm2, (TKEYP)
14015 add $0x10, TKEYP
14016+ pax_force_retaddr
14017 ret
14018 ENDPROC(_key_expansion_256b)
14019
14020@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
14021 #ifndef __x86_64__
14022 popl KEYP
14023 #endif
14024+ pax_force_retaddr
14025 ret
14026 ENDPROC(aesni_set_key)
14027
14028@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
14029 popl KLEN
14030 popl KEYP
14031 #endif
14032+ pax_force_retaddr
14033 ret
14034 ENDPROC(aesni_enc)
14035
14036@@ -1974,6 +1983,7 @@ _aesni_enc1:
14037 AESENC KEY STATE
14038 movaps 0x70(TKEYP), KEY
14039 AESENCLAST KEY STATE
14040+ pax_force_retaddr
14041 ret
14042 ENDPROC(_aesni_enc1)
14043
14044@@ -2083,6 +2093,7 @@ _aesni_enc4:
14045 AESENCLAST KEY STATE2
14046 AESENCLAST KEY STATE3
14047 AESENCLAST KEY STATE4
14048+ pax_force_retaddr
14049 ret
14050 ENDPROC(_aesni_enc4)
14051
14052@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
14053 popl KLEN
14054 popl KEYP
14055 #endif
14056+ pax_force_retaddr
14057 ret
14058 ENDPROC(aesni_dec)
14059
14060@@ -2164,6 +2176,7 @@ _aesni_dec1:
14061 AESDEC KEY STATE
14062 movaps 0x70(TKEYP), KEY
14063 AESDECLAST KEY STATE
14064+ pax_force_retaddr
14065 ret
14066 ENDPROC(_aesni_dec1)
14067
14068@@ -2273,6 +2286,7 @@ _aesni_dec4:
14069 AESDECLAST KEY STATE2
14070 AESDECLAST KEY STATE3
14071 AESDECLAST KEY STATE4
14072+ pax_force_retaddr
14073 ret
14074 ENDPROC(_aesni_dec4)
14075
14076@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
14077 popl KEYP
14078 popl LEN
14079 #endif
14080+ pax_force_retaddr
14081 ret
14082 ENDPROC(aesni_ecb_enc)
14083
14084@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
14085 popl KEYP
14086 popl LEN
14087 #endif
14088+ pax_force_retaddr
14089 ret
14090 ENDPROC(aesni_ecb_dec)
14091
14092@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
14093 popl LEN
14094 popl IVP
14095 #endif
14096+ pax_force_retaddr
14097 ret
14098 ENDPROC(aesni_cbc_enc)
14099
14100@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
14101 popl LEN
14102 popl IVP
14103 #endif
14104+ pax_force_retaddr
14105 ret
14106 ENDPROC(aesni_cbc_dec)
14107
14108@@ -2550,6 +2568,7 @@ _aesni_inc_init:
14109 mov $1, TCTR_LOW
14110 MOVQ_R64_XMM TCTR_LOW INC
14111 MOVQ_R64_XMM CTR TCTR_LOW
14112+ pax_force_retaddr
14113 ret
14114 ENDPROC(_aesni_inc_init)
14115
14116@@ -2579,6 +2598,7 @@ _aesni_inc:
14117 .Linc_low:
14118 movaps CTR, IV
14119 PSHUFB_XMM BSWAP_MASK IV
14120+ pax_force_retaddr
14121 ret
14122 ENDPROC(_aesni_inc)
14123
14124@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
14125 .Lctr_enc_ret:
14126 movups IV, (IVP)
14127 .Lctr_enc_just_ret:
14128+ pax_force_retaddr
14129 ret
14130 ENDPROC(aesni_ctr_enc)
14131
14132@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
14133 pxor INC, STATE4
14134 movdqu STATE4, 0x70(OUTP)
14135
14136+ pax_force_retaddr
14137 ret
14138 ENDPROC(aesni_xts_crypt8)
14139
14140diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
14141index 246c670..466e2d6 100644
14142--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
14143+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
14144@@ -21,6 +21,7 @@
14145 */
14146
14147 #include <linux/linkage.h>
14148+#include <asm/alternative-asm.h>
14149
14150 .file "blowfish-x86_64-asm.S"
14151 .text
14152@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
14153 jnz .L__enc_xor;
14154
14155 write_block();
14156+ pax_force_retaddr
14157 ret;
14158 .L__enc_xor:
14159 xor_block();
14160+ pax_force_retaddr
14161 ret;
14162 ENDPROC(__blowfish_enc_blk)
14163
14164@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
14165
14166 movq %r11, %rbp;
14167
14168+ pax_force_retaddr
14169 ret;
14170 ENDPROC(blowfish_dec_blk)
14171
14172@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
14173
14174 popq %rbx;
14175 popq %rbp;
14176+ pax_force_retaddr
14177 ret;
14178
14179 .L__enc_xor4:
14180@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
14181
14182 popq %rbx;
14183 popq %rbp;
14184+ pax_force_retaddr
14185 ret;
14186 ENDPROC(__blowfish_enc_blk_4way)
14187
14188@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
14189 popq %rbx;
14190 popq %rbp;
14191
14192+ pax_force_retaddr
14193 ret;
14194 ENDPROC(blowfish_dec_blk_4way)
14195diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
14196index ce71f92..1dce7ec 100644
14197--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
14198+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
14199@@ -16,6 +16,7 @@
14200 */
14201
14202 #include <linux/linkage.h>
14203+#include <asm/alternative-asm.h>
14204
14205 #define CAMELLIA_TABLE_BYTE_LEN 272
14206
14207@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
14208 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
14209 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
14210 %rcx, (%r9));
14211+ pax_force_retaddr
14212 ret;
14213 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
14214
14215@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
14216 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
14217 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
14218 %rax, (%r9));
14219+ pax_force_retaddr
14220 ret;
14221 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
14222
14223@@ -780,6 +783,7 @@ __camellia_enc_blk16:
14224 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
14225 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
14226
14227+ pax_force_retaddr
14228 ret;
14229
14230 .align 8
14231@@ -865,6 +869,7 @@ __camellia_dec_blk16:
14232 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
14233 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
14234
14235+ pax_force_retaddr
14236 ret;
14237
14238 .align 8
14239@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
14240 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14241 %xmm8, %rsi);
14242
14243+ pax_force_retaddr
14244 ret;
14245 ENDPROC(camellia_ecb_enc_16way)
14246
14247@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
14248 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14249 %xmm8, %rsi);
14250
14251+ pax_force_retaddr
14252 ret;
14253 ENDPROC(camellia_ecb_dec_16way)
14254
14255@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
14256 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14257 %xmm8, %rsi);
14258
14259+ pax_force_retaddr
14260 ret;
14261 ENDPROC(camellia_cbc_dec_16way)
14262
14263@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
14264 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14265 %xmm8, %rsi);
14266
14267+ pax_force_retaddr
14268 ret;
14269 ENDPROC(camellia_ctr_16way)
14270
14271@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
14272 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
14273 %xmm8, %rsi);
14274
14275+ pax_force_retaddr
14276 ret;
14277 ENDPROC(camellia_xts_crypt_16way)
14278
14279diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
14280index 0e0b886..5a3123c 100644
14281--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
14282+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
14283@@ -11,6 +11,7 @@
14284 */
14285
14286 #include <linux/linkage.h>
14287+#include <asm/alternative-asm.h>
14288
14289 #define CAMELLIA_TABLE_BYTE_LEN 272
14290
14291@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
14292 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
14293 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
14294 %rcx, (%r9));
14295+ pax_force_retaddr
14296 ret;
14297 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
14298
14299@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
14300 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
14301 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
14302 %rax, (%r9));
14303+ pax_force_retaddr
14304 ret;
14305 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
14306
14307@@ -820,6 +823,7 @@ __camellia_enc_blk32:
14308 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
14309 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
14310
14311+ pax_force_retaddr
14312 ret;
14313
14314 .align 8
14315@@ -905,6 +909,7 @@ __camellia_dec_blk32:
14316 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
14317 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
14318
14319+ pax_force_retaddr
14320 ret;
14321
14322 .align 8
14323@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
14324
14325 vzeroupper;
14326
14327+ pax_force_retaddr
14328 ret;
14329 ENDPROC(camellia_ecb_enc_32way)
14330
14331@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
14332
14333 vzeroupper;
14334
14335+ pax_force_retaddr
14336 ret;
14337 ENDPROC(camellia_ecb_dec_32way)
14338
14339@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
14340
14341 vzeroupper;
14342
14343+ pax_force_retaddr
14344 ret;
14345 ENDPROC(camellia_cbc_dec_32way)
14346
14347@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
14348
14349 vzeroupper;
14350
14351+ pax_force_retaddr
14352 ret;
14353 ENDPROC(camellia_ctr_32way)
14354
14355@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
14356
14357 vzeroupper;
14358
14359+ pax_force_retaddr
14360 ret;
14361 ENDPROC(camellia_xts_crypt_32way)
14362
14363diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
14364index 310319c..db3d7b5 100644
14365--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
14366+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
14367@@ -21,6 +21,7 @@
14368 */
14369
14370 #include <linux/linkage.h>
14371+#include <asm/alternative-asm.h>
14372
14373 .file "camellia-x86_64-asm_64.S"
14374 .text
14375@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
14376 enc_outunpack(mov, RT1);
14377
14378 movq RRBP, %rbp;
14379+ pax_force_retaddr
14380 ret;
14381
14382 .L__enc_xor:
14383 enc_outunpack(xor, RT1);
14384
14385 movq RRBP, %rbp;
14386+ pax_force_retaddr
14387 ret;
14388 ENDPROC(__camellia_enc_blk)
14389
14390@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
14391 dec_outunpack();
14392
14393 movq RRBP, %rbp;
14394+ pax_force_retaddr
14395 ret;
14396 ENDPROC(camellia_dec_blk)
14397
14398@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
14399
14400 movq RRBP, %rbp;
14401 popq %rbx;
14402+ pax_force_retaddr
14403 ret;
14404
14405 .L__enc2_xor:
14406@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
14407
14408 movq RRBP, %rbp;
14409 popq %rbx;
14410+ pax_force_retaddr
14411 ret;
14412 ENDPROC(__camellia_enc_blk_2way)
14413
14414@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
14415
14416 movq RRBP, %rbp;
14417 movq RXOR, %rbx;
14418+ pax_force_retaddr
14419 ret;
14420 ENDPROC(camellia_dec_blk_2way)
14421diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
14422index c35fd5d..2d8c7db 100644
14423--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
14424+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
14425@@ -24,6 +24,7 @@
14426 */
14427
14428 #include <linux/linkage.h>
14429+#include <asm/alternative-asm.h>
14430
14431 .file "cast5-avx-x86_64-asm_64.S"
14432
14433@@ -281,6 +282,7 @@ __cast5_enc_blk16:
14434 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
14435 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
14436
14437+ pax_force_retaddr
14438 ret;
14439 ENDPROC(__cast5_enc_blk16)
14440
14441@@ -352,6 +354,7 @@ __cast5_dec_blk16:
14442 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
14443 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
14444
14445+ pax_force_retaddr
14446 ret;
14447
14448 .L__skip_dec:
14449@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
14450 vmovdqu RR4, (6*4*4)(%r11);
14451 vmovdqu RL4, (7*4*4)(%r11);
14452
14453+ pax_force_retaddr
14454 ret;
14455 ENDPROC(cast5_ecb_enc_16way)
14456
14457@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
14458 vmovdqu RR4, (6*4*4)(%r11);
14459 vmovdqu RL4, (7*4*4)(%r11);
14460
14461+ pax_force_retaddr
14462 ret;
14463 ENDPROC(cast5_ecb_dec_16way)
14464
14465@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
14466 * %rdx: src
14467 */
14468
14469- pushq %r12;
14470+ pushq %r14;
14471
14472 movq %rsi, %r11;
14473- movq %rdx, %r12;
14474+ movq %rdx, %r14;
14475
14476 vmovdqu (0*16)(%rdx), RL1;
14477 vmovdqu (1*16)(%rdx), RR1;
14478@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
14479 call __cast5_dec_blk16;
14480
14481 /* xor with src */
14482- vmovq (%r12), RX;
14483+ vmovq (%r14), RX;
14484 vpshufd $0x4f, RX, RX;
14485 vpxor RX, RR1, RR1;
14486- vpxor 0*16+8(%r12), RL1, RL1;
14487- vpxor 1*16+8(%r12), RR2, RR2;
14488- vpxor 2*16+8(%r12), RL2, RL2;
14489- vpxor 3*16+8(%r12), RR3, RR3;
14490- vpxor 4*16+8(%r12), RL3, RL3;
14491- vpxor 5*16+8(%r12), RR4, RR4;
14492- vpxor 6*16+8(%r12), RL4, RL4;
14493+ vpxor 0*16+8(%r14), RL1, RL1;
14494+ vpxor 1*16+8(%r14), RR2, RR2;
14495+ vpxor 2*16+8(%r14), RL2, RL2;
14496+ vpxor 3*16+8(%r14), RR3, RR3;
14497+ vpxor 4*16+8(%r14), RL3, RL3;
14498+ vpxor 5*16+8(%r14), RR4, RR4;
14499+ vpxor 6*16+8(%r14), RL4, RL4;
14500
14501 vmovdqu RR1, (0*16)(%r11);
14502 vmovdqu RL1, (1*16)(%r11);
14503@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
14504 vmovdqu RR4, (6*16)(%r11);
14505 vmovdqu RL4, (7*16)(%r11);
14506
14507- popq %r12;
14508+ popq %r14;
14509
14510+ pax_force_retaddr
14511 ret;
14512 ENDPROC(cast5_cbc_dec_16way)
14513
14514@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
14515 * %rcx: iv (big endian, 64bit)
14516 */
14517
14518- pushq %r12;
14519+ pushq %r14;
14520
14521 movq %rsi, %r11;
14522- movq %rdx, %r12;
14523+ movq %rdx, %r14;
14524
14525 vpcmpeqd RTMP, RTMP, RTMP;
14526 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
14527@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
14528 call __cast5_enc_blk16;
14529
14530 /* dst = src ^ iv */
14531- vpxor (0*16)(%r12), RR1, RR1;
14532- vpxor (1*16)(%r12), RL1, RL1;
14533- vpxor (2*16)(%r12), RR2, RR2;
14534- vpxor (3*16)(%r12), RL2, RL2;
14535- vpxor (4*16)(%r12), RR3, RR3;
14536- vpxor (5*16)(%r12), RL3, RL3;
14537- vpxor (6*16)(%r12), RR4, RR4;
14538- vpxor (7*16)(%r12), RL4, RL4;
14539+ vpxor (0*16)(%r14), RR1, RR1;
14540+ vpxor (1*16)(%r14), RL1, RL1;
14541+ vpxor (2*16)(%r14), RR2, RR2;
14542+ vpxor (3*16)(%r14), RL2, RL2;
14543+ vpxor (4*16)(%r14), RR3, RR3;
14544+ vpxor (5*16)(%r14), RL3, RL3;
14545+ vpxor (6*16)(%r14), RR4, RR4;
14546+ vpxor (7*16)(%r14), RL4, RL4;
14547 vmovdqu RR1, (0*16)(%r11);
14548 vmovdqu RL1, (1*16)(%r11);
14549 vmovdqu RR2, (2*16)(%r11);
14550@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
14551 vmovdqu RR4, (6*16)(%r11);
14552 vmovdqu RL4, (7*16)(%r11);
14553
14554- popq %r12;
14555+ popq %r14;
14556
14557+ pax_force_retaddr
14558 ret;
14559 ENDPROC(cast5_ctr_16way)
14560diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14561index e3531f8..e123f35 100644
14562--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14563+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
14564@@ -24,6 +24,7 @@
14565 */
14566
14567 #include <linux/linkage.h>
14568+#include <asm/alternative-asm.h>
14569 #include "glue_helper-asm-avx.S"
14570
14571 .file "cast6-avx-x86_64-asm_64.S"
14572@@ -295,6 +296,7 @@ __cast6_enc_blk8:
14573 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14574 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14575
14576+ pax_force_retaddr
14577 ret;
14578 ENDPROC(__cast6_enc_blk8)
14579
14580@@ -340,6 +342,7 @@ __cast6_dec_blk8:
14581 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
14582 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
14583
14584+ pax_force_retaddr
14585 ret;
14586 ENDPROC(__cast6_dec_blk8)
14587
14588@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
14589
14590 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14591
14592+ pax_force_retaddr
14593 ret;
14594 ENDPROC(cast6_ecb_enc_8way)
14595
14596@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
14597
14598 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14599
14600+ pax_force_retaddr
14601 ret;
14602 ENDPROC(cast6_ecb_dec_8way)
14603
14604@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
14605 * %rdx: src
14606 */
14607
14608- pushq %r12;
14609+ pushq %r14;
14610
14611 movq %rsi, %r11;
14612- movq %rdx, %r12;
14613+ movq %rdx, %r14;
14614
14615 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14616
14617 call __cast6_dec_blk8;
14618
14619- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14620+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14621
14622- popq %r12;
14623+ popq %r14;
14624
14625+ pax_force_retaddr
14626 ret;
14627 ENDPROC(cast6_cbc_dec_8way)
14628
14629@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
14630 * %rcx: iv (little endian, 128bit)
14631 */
14632
14633- pushq %r12;
14634+ pushq %r14;
14635
14636 movq %rsi, %r11;
14637- movq %rdx, %r12;
14638+ movq %rdx, %r14;
14639
14640 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14641 RD2, RX, RKR, RKM);
14642
14643 call __cast6_enc_blk8;
14644
14645- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14646+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14647
14648- popq %r12;
14649+ popq %r14;
14650
14651+ pax_force_retaddr
14652 ret;
14653 ENDPROC(cast6_ctr_8way)
14654
14655@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
14656 /* dst <= regs xor IVs(in dst) */
14657 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14658
14659+ pax_force_retaddr
14660 ret;
14661 ENDPROC(cast6_xts_enc_8way)
14662
14663@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
14664 /* dst <= regs xor IVs(in dst) */
14665 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14666
14667+ pax_force_retaddr
14668 ret;
14669 ENDPROC(cast6_xts_dec_8way)
14670diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14671index 26d49eb..c0a8c84 100644
14672--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14673+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
14674@@ -45,6 +45,7 @@
14675
14676 #include <asm/inst.h>
14677 #include <linux/linkage.h>
14678+#include <asm/alternative-asm.h>
14679
14680 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
14681
14682@@ -309,6 +310,7 @@ do_return:
14683 popq %rsi
14684 popq %rdi
14685 popq %rbx
14686+ pax_force_retaddr
14687 ret
14688
14689 ################################################################
14690diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14691index 5d1e007..098cb4f 100644
14692--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
14693+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
14694@@ -18,6 +18,7 @@
14695
14696 #include <linux/linkage.h>
14697 #include <asm/inst.h>
14698+#include <asm/alternative-asm.h>
14699
14700 .data
14701
14702@@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
14703 psrlq $1, T2
14704 pxor T2, T1
14705 pxor T1, DATA
14706+ pax_force_retaddr
14707 ret
14708 ENDPROC(__clmul_gf128mul_ble)
14709
14710@@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
14711 call __clmul_gf128mul_ble
14712 PSHUFB_XMM BSWAP DATA
14713 movups DATA, (%rdi)
14714+ pax_force_retaddr
14715 ret
14716 ENDPROC(clmul_ghash_mul)
14717
14718@@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
14719 PSHUFB_XMM BSWAP DATA
14720 movups DATA, (%rdi)
14721 .Lupdate_just_ret:
14722+ pax_force_retaddr
14723 ret
14724 ENDPROC(clmul_ghash_update)
14725diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14726index 9279e0b..c4b3d2c 100644
14727--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
14728+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
14729@@ -1,4 +1,5 @@
14730 #include <linux/linkage.h>
14731+#include <asm/alternative-asm.h>
14732
14733 # enter salsa20_encrypt_bytes
14734 ENTRY(salsa20_encrypt_bytes)
14735@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
14736 add %r11,%rsp
14737 mov %rdi,%rax
14738 mov %rsi,%rdx
14739+ pax_force_retaddr
14740 ret
14741 # bytesatleast65:
14742 ._bytesatleast65:
14743@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
14744 add %r11,%rsp
14745 mov %rdi,%rax
14746 mov %rsi,%rdx
14747+ pax_force_retaddr
14748 ret
14749 ENDPROC(salsa20_keysetup)
14750
14751@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
14752 add %r11,%rsp
14753 mov %rdi,%rax
14754 mov %rsi,%rdx
14755+ pax_force_retaddr
14756 ret
14757 ENDPROC(salsa20_ivsetup)
14758diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14759index 2f202f4..d9164d6 100644
14760--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14761+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
14762@@ -24,6 +24,7 @@
14763 */
14764
14765 #include <linux/linkage.h>
14766+#include <asm/alternative-asm.h>
14767 #include "glue_helper-asm-avx.S"
14768
14769 .file "serpent-avx-x86_64-asm_64.S"
14770@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
14771 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14772 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14773
14774+ pax_force_retaddr
14775 ret;
14776 ENDPROC(__serpent_enc_blk8_avx)
14777
14778@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
14779 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14780 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14781
14782+ pax_force_retaddr
14783 ret;
14784 ENDPROC(__serpent_dec_blk8_avx)
14785
14786@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
14787
14788 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14789
14790+ pax_force_retaddr
14791 ret;
14792 ENDPROC(serpent_ecb_enc_8way_avx)
14793
14794@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
14795
14796 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14797
14798+ pax_force_retaddr
14799 ret;
14800 ENDPROC(serpent_ecb_dec_8way_avx)
14801
14802@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
14803
14804 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14805
14806+ pax_force_retaddr
14807 ret;
14808 ENDPROC(serpent_cbc_dec_8way_avx)
14809
14810@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
14811
14812 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14813
14814+ pax_force_retaddr
14815 ret;
14816 ENDPROC(serpent_ctr_8way_avx)
14817
14818@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
14819 /* dst <= regs xor IVs(in dst) */
14820 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14821
14822+ pax_force_retaddr
14823 ret;
14824 ENDPROC(serpent_xts_enc_8way_avx)
14825
14826@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
14827 /* dst <= regs xor IVs(in dst) */
14828 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
14829
14830+ pax_force_retaddr
14831 ret;
14832 ENDPROC(serpent_xts_dec_8way_avx)
14833diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
14834index b222085..abd483c 100644
14835--- a/arch/x86/crypto/serpent-avx2-asm_64.S
14836+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
14837@@ -15,6 +15,7 @@
14838 */
14839
14840 #include <linux/linkage.h>
14841+#include <asm/alternative-asm.h>
14842 #include "glue_helper-asm-avx2.S"
14843
14844 .file "serpent-avx2-asm_64.S"
14845@@ -610,6 +611,7 @@ __serpent_enc_blk16:
14846 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14847 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14848
14849+ pax_force_retaddr
14850 ret;
14851 ENDPROC(__serpent_enc_blk16)
14852
14853@@ -664,6 +666,7 @@ __serpent_dec_blk16:
14854 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14855 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14856
14857+ pax_force_retaddr
14858 ret;
14859 ENDPROC(__serpent_dec_blk16)
14860
14861@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
14862
14863 vzeroupper;
14864
14865+ pax_force_retaddr
14866 ret;
14867 ENDPROC(serpent_ecb_enc_16way)
14868
14869@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
14870
14871 vzeroupper;
14872
14873+ pax_force_retaddr
14874 ret;
14875 ENDPROC(serpent_ecb_dec_16way)
14876
14877@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
14878
14879 vzeroupper;
14880
14881+ pax_force_retaddr
14882 ret;
14883 ENDPROC(serpent_cbc_dec_16way)
14884
14885@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
14886
14887 vzeroupper;
14888
14889+ pax_force_retaddr
14890 ret;
14891 ENDPROC(serpent_ctr_16way)
14892
14893@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
14894
14895 vzeroupper;
14896
14897+ pax_force_retaddr
14898 ret;
14899 ENDPROC(serpent_xts_enc_16way)
14900
14901@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
14902
14903 vzeroupper;
14904
14905+ pax_force_retaddr
14906 ret;
14907 ENDPROC(serpent_xts_dec_16way)
14908diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14909index acc066c..1559cc4 100644
14910--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14911+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
14912@@ -25,6 +25,7 @@
14913 */
14914
14915 #include <linux/linkage.h>
14916+#include <asm/alternative-asm.h>
14917
14918 .file "serpent-sse2-x86_64-asm_64.S"
14919 .text
14920@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
14921 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14922 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14923
14924+ pax_force_retaddr
14925 ret;
14926
14927 .L__enc_xor8:
14928 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
14929 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
14930
14931+ pax_force_retaddr
14932 ret;
14933 ENDPROC(__serpent_enc_blk_8way)
14934
14935@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
14936 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
14937 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
14938
14939+ pax_force_retaddr
14940 ret;
14941 ENDPROC(serpent_dec_blk_8way)
14942diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14943index a410950..9dfe7ad 100644
14944--- a/arch/x86/crypto/sha1_ssse3_asm.S
14945+++ b/arch/x86/crypto/sha1_ssse3_asm.S
14946@@ -29,6 +29,7 @@
14947 */
14948
14949 #include <linux/linkage.h>
14950+#include <asm/alternative-asm.h>
14951
14952 #define CTX %rdi // arg1
14953 #define BUF %rsi // arg2
14954@@ -75,9 +76,9 @@
14955
14956 push %rbx
14957 push %rbp
14958- push %r12
14959+ push %r14
14960
14961- mov %rsp, %r12
14962+ mov %rsp, %r14
14963 sub $64, %rsp # allocate workspace
14964 and $~15, %rsp # align stack
14965
14966@@ -99,11 +100,12 @@
14967 xor %rax, %rax
14968 rep stosq
14969
14970- mov %r12, %rsp # deallocate workspace
14971+ mov %r14, %rsp # deallocate workspace
14972
14973- pop %r12
14974+ pop %r14
14975 pop %rbp
14976 pop %rbx
14977+ pax_force_retaddr
14978 ret
14979
14980 ENDPROC(\name)
14981diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14982index 642f156..51a513c 100644
14983--- a/arch/x86/crypto/sha256-avx-asm.S
14984+++ b/arch/x86/crypto/sha256-avx-asm.S
14985@@ -49,6 +49,7 @@
14986
14987 #ifdef CONFIG_AS_AVX
14988 #include <linux/linkage.h>
14989+#include <asm/alternative-asm.h>
14990
14991 ## assume buffers not aligned
14992 #define VMOVDQ vmovdqu
14993@@ -460,6 +461,7 @@ done_hash:
14994 popq %r13
14995 popq %rbp
14996 popq %rbx
14997+ pax_force_retaddr
14998 ret
14999 ENDPROC(sha256_transform_avx)
15000
15001diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
15002index 9e86944..3795e6a 100644
15003--- a/arch/x86/crypto/sha256-avx2-asm.S
15004+++ b/arch/x86/crypto/sha256-avx2-asm.S
15005@@ -50,6 +50,7 @@
15006
15007 #ifdef CONFIG_AS_AVX2
15008 #include <linux/linkage.h>
15009+#include <asm/alternative-asm.h>
15010
15011 ## assume buffers not aligned
15012 #define VMOVDQ vmovdqu
15013@@ -720,6 +721,7 @@ done_hash:
15014 popq %r12
15015 popq %rbp
15016 popq %rbx
15017+ pax_force_retaddr
15018 ret
15019 ENDPROC(sha256_transform_rorx)
15020
15021diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
15022index f833b74..8c62a9e 100644
15023--- a/arch/x86/crypto/sha256-ssse3-asm.S
15024+++ b/arch/x86/crypto/sha256-ssse3-asm.S
15025@@ -47,6 +47,7 @@
15026 ########################################################################
15027
15028 #include <linux/linkage.h>
15029+#include <asm/alternative-asm.h>
15030
15031 ## assume buffers not aligned
15032 #define MOVDQ movdqu
15033@@ -471,6 +472,7 @@ done_hash:
15034 popq %rbp
15035 popq %rbx
15036
15037+ pax_force_retaddr
15038 ret
15039 ENDPROC(sha256_transform_ssse3)
15040
15041diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
15042index 974dde9..a823ff9 100644
15043--- a/arch/x86/crypto/sha512-avx-asm.S
15044+++ b/arch/x86/crypto/sha512-avx-asm.S
15045@@ -49,6 +49,7 @@
15046
15047 #ifdef CONFIG_AS_AVX
15048 #include <linux/linkage.h>
15049+#include <asm/alternative-asm.h>
15050
15051 .text
15052
15053@@ -364,6 +365,7 @@ updateblock:
15054 mov frame_RSPSAVE(%rsp), %rsp
15055
15056 nowork:
15057+ pax_force_retaddr
15058 ret
15059 ENDPROC(sha512_transform_avx)
15060
15061diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
15062index 568b961..ed20c37 100644
15063--- a/arch/x86/crypto/sha512-avx2-asm.S
15064+++ b/arch/x86/crypto/sha512-avx2-asm.S
15065@@ -51,6 +51,7 @@
15066
15067 #ifdef CONFIG_AS_AVX2
15068 #include <linux/linkage.h>
15069+#include <asm/alternative-asm.h>
15070
15071 .text
15072
15073@@ -678,6 +679,7 @@ done_hash:
15074
15075 # Restore Stack Pointer
15076 mov frame_RSPSAVE(%rsp), %rsp
15077+ pax_force_retaddr
15078 ret
15079 ENDPROC(sha512_transform_rorx)
15080
15081diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
15082index fb56855..6edd768 100644
15083--- a/arch/x86/crypto/sha512-ssse3-asm.S
15084+++ b/arch/x86/crypto/sha512-ssse3-asm.S
15085@@ -48,6 +48,7 @@
15086 ########################################################################
15087
15088 #include <linux/linkage.h>
15089+#include <asm/alternative-asm.h>
15090
15091 .text
15092
15093@@ -363,6 +364,7 @@ updateblock:
15094 mov frame_RSPSAVE(%rsp), %rsp
15095
15096 nowork:
15097+ pax_force_retaddr
15098 ret
15099 ENDPROC(sha512_transform_ssse3)
15100
15101diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
15102index 0505813..b067311 100644
15103--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
15104+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
15105@@ -24,6 +24,7 @@
15106 */
15107
15108 #include <linux/linkage.h>
15109+#include <asm/alternative-asm.h>
15110 #include "glue_helper-asm-avx.S"
15111
15112 .file "twofish-avx-x86_64-asm_64.S"
15113@@ -284,6 +285,7 @@ __twofish_enc_blk8:
15114 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
15115 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
15116
15117+ pax_force_retaddr
15118 ret;
15119 ENDPROC(__twofish_enc_blk8)
15120
15121@@ -324,6 +326,7 @@ __twofish_dec_blk8:
15122 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
15123 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
15124
15125+ pax_force_retaddr
15126 ret;
15127 ENDPROC(__twofish_dec_blk8)
15128
15129@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
15130
15131 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15132
15133+ pax_force_retaddr
15134 ret;
15135 ENDPROC(twofish_ecb_enc_8way)
15136
15137@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
15138
15139 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15140
15141+ pax_force_retaddr
15142 ret;
15143 ENDPROC(twofish_ecb_dec_8way)
15144
15145@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
15146 * %rdx: src
15147 */
15148
15149- pushq %r12;
15150+ pushq %r14;
15151
15152 movq %rsi, %r11;
15153- movq %rdx, %r12;
15154+ movq %rdx, %r14;
15155
15156 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15157
15158 call __twofish_dec_blk8;
15159
15160- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15161+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15162
15163- popq %r12;
15164+ popq %r14;
15165
15166+ pax_force_retaddr
15167 ret;
15168 ENDPROC(twofish_cbc_dec_8way)
15169
15170@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
15171 * %rcx: iv (little endian, 128bit)
15172 */
15173
15174- pushq %r12;
15175+ pushq %r14;
15176
15177 movq %rsi, %r11;
15178- movq %rdx, %r12;
15179+ movq %rdx, %r14;
15180
15181 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
15182 RD2, RX0, RX1, RY0);
15183
15184 call __twofish_enc_blk8;
15185
15186- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15187+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15188
15189- popq %r12;
15190+ popq %r14;
15191
15192+ pax_force_retaddr
15193 ret;
15194 ENDPROC(twofish_ctr_8way)
15195
15196@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
15197 /* dst <= regs xor IVs(in dst) */
15198 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
15199
15200+ pax_force_retaddr
15201 ret;
15202 ENDPROC(twofish_xts_enc_8way)
15203
15204@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
15205 /* dst <= regs xor IVs(in dst) */
15206 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
15207
15208+ pax_force_retaddr
15209 ret;
15210 ENDPROC(twofish_xts_dec_8way)
15211diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
15212index 1c3b7ce..02f578d 100644
15213--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
15214+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
15215@@ -21,6 +21,7 @@
15216 */
15217
15218 #include <linux/linkage.h>
15219+#include <asm/alternative-asm.h>
15220
15221 .file "twofish-x86_64-asm-3way.S"
15222 .text
15223@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
15224 popq %r13;
15225 popq %r14;
15226 popq %r15;
15227+ pax_force_retaddr
15228 ret;
15229
15230 .L__enc_xor3:
15231@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
15232 popq %r13;
15233 popq %r14;
15234 popq %r15;
15235+ pax_force_retaddr
15236 ret;
15237 ENDPROC(__twofish_enc_blk_3way)
15238
15239@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
15240 popq %r13;
15241 popq %r14;
15242 popq %r15;
15243+ pax_force_retaddr
15244 ret;
15245 ENDPROC(twofish_dec_blk_3way)
15246diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
15247index a039d21..524b8b2 100644
15248--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
15249+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
15250@@ -22,6 +22,7 @@
15251
15252 #include <linux/linkage.h>
15253 #include <asm/asm-offsets.h>
15254+#include <asm/alternative-asm.h>
15255
15256 #define a_offset 0
15257 #define b_offset 4
15258@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
15259
15260 popq R1
15261 movq $1,%rax
15262+ pax_force_retaddr
15263 ret
15264 ENDPROC(twofish_enc_blk)
15265
15266@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
15267
15268 popq R1
15269 movq $1,%rax
15270+ pax_force_retaddr
15271 ret
15272 ENDPROC(twofish_dec_blk)
15273diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
15274index d21ff89..6da8e6e 100644
15275--- a/arch/x86/ia32/ia32_aout.c
15276+++ b/arch/x86/ia32/ia32_aout.c
15277@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
15278 unsigned long dump_start, dump_size;
15279 struct user32 dump;
15280
15281+ memset(&dump, 0, sizeof(dump));
15282+
15283 fs = get_fs();
15284 set_fs(KERNEL_DS);
15285 has_dumped = 1;
15286diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
15287index f9e181a..db313b5 100644
15288--- a/arch/x86/ia32/ia32_signal.c
15289+++ b/arch/x86/ia32/ia32_signal.c
15290@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
15291 if (__get_user(set.sig[0], &frame->sc.oldmask)
15292 || (_COMPAT_NSIG_WORDS > 1
15293 && __copy_from_user((((char *) &set.sig) + 4),
15294- &frame->extramask,
15295+ frame->extramask,
15296 sizeof(frame->extramask))))
15297 goto badframe;
15298
15299@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
15300 sp -= frame_size;
15301 /* Align the stack pointer according to the i386 ABI,
15302 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
15303- sp = ((sp + 4) & -16ul) - 4;
15304+ sp = ((sp - 12) & -16ul) - 4;
15305 return (void __user *) sp;
15306 }
15307
15308@@ -383,10 +383,10 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
15309 } else {
15310 /* Return stub is in 32bit vsyscall page */
15311 if (current->mm->context.vdso)
15312- restorer = current->mm->context.vdso +
15313- selected_vdso32->sym___kernel_sigreturn;
15314+ restorer = (void __force_user *)(current->mm->context.vdso +
15315+ selected_vdso32->sym___kernel_sigreturn);
15316 else
15317- restorer = &frame->retcode;
15318+ restorer = frame->retcode;
15319 }
15320
15321 put_user_try {
15322@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
15323 * These are actually not used anymore, but left because some
15324 * gdb versions depend on them as a marker.
15325 */
15326- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
15327+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
15328 } put_user_catch(err);
15329
15330 if (err)
15331@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
15332 0xb8,
15333 __NR_ia32_rt_sigreturn,
15334 0x80cd,
15335- 0,
15336+ 0
15337 };
15338
15339 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
15340@@ -461,16 +461,19 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
15341
15342 if (ksig->ka.sa.sa_flags & SA_RESTORER)
15343 restorer = ksig->ka.sa.sa_restorer;
15344- else
15345+ else if (current->mm->context.vdso)
15346+ /* Return stub is in 32bit vsyscall page */
15347 restorer = current->mm->context.vdso +
15348 selected_vdso32->sym___kernel_rt_sigreturn;
15349+ else
15350+ restorer = frame->retcode;
15351 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
15352
15353 /*
15354 * Not actually used anymore, but left because some gdb
15355 * versions need it.
15356 */
15357- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
15358+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
15359 } put_user_catch(err);
15360
15361 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
15362diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
15363index 92a2e93..cd4d95f 100644
15364--- a/arch/x86/ia32/ia32entry.S
15365+++ b/arch/x86/ia32/ia32entry.S
15366@@ -15,8 +15,10 @@
15367 #include <asm/irqflags.h>
15368 #include <asm/asm.h>
15369 #include <asm/smap.h>
15370+#include <asm/pgtable.h>
15371 #include <linux/linkage.h>
15372 #include <linux/err.h>
15373+#include <asm/alternative-asm.h>
15374
15375 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15376 #include <linux/elf-em.h>
15377@@ -62,12 +64,12 @@
15378 */
15379 .macro LOAD_ARGS32 offset, _r9=0
15380 .if \_r9
15381- movl \offset+16(%rsp),%r9d
15382+ movl \offset+R9(%rsp),%r9d
15383 .endif
15384- movl \offset+40(%rsp),%ecx
15385- movl \offset+48(%rsp),%edx
15386- movl \offset+56(%rsp),%esi
15387- movl \offset+64(%rsp),%edi
15388+ movl \offset+RCX(%rsp),%ecx
15389+ movl \offset+RDX(%rsp),%edx
15390+ movl \offset+RSI(%rsp),%esi
15391+ movl \offset+RDI(%rsp),%edi
15392 movl %eax,%eax /* zero extension */
15393 .endm
15394
15395@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
15396 ENDPROC(native_irq_enable_sysexit)
15397 #endif
15398
15399+ .macro pax_enter_kernel_user
15400+ pax_set_fptr_mask
15401+#ifdef CONFIG_PAX_MEMORY_UDEREF
15402+ call pax_enter_kernel_user
15403+#endif
15404+ .endm
15405+
15406+ .macro pax_exit_kernel_user
15407+#ifdef CONFIG_PAX_MEMORY_UDEREF
15408+ call pax_exit_kernel_user
15409+#endif
15410+#ifdef CONFIG_PAX_RANDKSTACK
15411+ pushq %rax
15412+ pushq %r11
15413+ call pax_randomize_kstack
15414+ popq %r11
15415+ popq %rax
15416+#endif
15417+ .endm
15418+
15419+ .macro pax_erase_kstack
15420+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15421+ call pax_erase_kstack
15422+#endif
15423+ .endm
15424+
15425 /*
15426 * 32bit SYSENTER instruction entry.
15427 *
15428@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
15429 CFI_REGISTER rsp,rbp
15430 SWAPGS_UNSAFE_STACK
15431 movq PER_CPU_VAR(kernel_stack), %rsp
15432- addq $(KERNEL_STACK_OFFSET),%rsp
15433- /*
15434- * No need to follow this irqs on/off section: the syscall
15435- * disabled irqs, here we enable it straight after entry:
15436- */
15437- ENABLE_INTERRUPTS(CLBR_NONE)
15438 movl %ebp,%ebp /* zero extension */
15439 pushq_cfi $__USER32_DS
15440 /*CFI_REL_OFFSET ss,0*/
15441@@ -135,23 +157,46 @@ ENTRY(ia32_sysenter_target)
15442 CFI_REL_OFFSET rsp,0
15443 pushfq_cfi
15444 /*CFI_REL_OFFSET rflags,0*/
15445- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
15446- CFI_REGISTER rip,r10
15447+ orl $X86_EFLAGS_IF,(%rsp)
15448+ GET_THREAD_INFO(%r11)
15449+ movl TI_sysenter_return(%r11), %r11d
15450+ CFI_REGISTER rip,r11
15451 pushq_cfi $__USER32_CS
15452 /*CFI_REL_OFFSET cs,0*/
15453 movl %eax, %eax
15454- pushq_cfi %r10
15455+ pushq_cfi %r11
15456 CFI_REL_OFFSET rip,0
15457 pushq_cfi %rax
15458 cld
15459 SAVE_ARGS 0,1,0
15460+ pax_enter_kernel_user
15461+
15462+#ifdef CONFIG_PAX_RANDKSTACK
15463+ pax_erase_kstack
15464+#endif
15465+
15466+ /*
15467+ * No need to follow this irqs on/off section: the syscall
15468+ * disabled irqs, here we enable it straight after entry:
15469+ */
15470+ ENABLE_INTERRUPTS(CLBR_NONE)
15471 /* no need to do an access_ok check here because rbp has been
15472 32bit zero extended */
15473+
15474+#ifdef CONFIG_PAX_MEMORY_UDEREF
15475+ addq pax_user_shadow_base,%rbp
15476+ ASM_PAX_OPEN_USERLAND
15477+#endif
15478+
15479 ASM_STAC
15480 1: movl (%rbp),%ebp
15481 _ASM_EXTABLE(1b,ia32_badarg)
15482 ASM_CLAC
15483
15484+#ifdef CONFIG_PAX_MEMORY_UDEREF
15485+ ASM_PAX_CLOSE_USERLAND
15486+#endif
15487+
15488 /*
15489 * Sysenter doesn't filter flags, so we need to clear NT
15490 * ourselves. To save a few cycles, we can check whether
15491@@ -161,8 +206,9 @@ ENTRY(ia32_sysenter_target)
15492 jnz sysenter_fix_flags
15493 sysenter_flags_fixed:
15494
15495- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15496- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15497+ GET_THREAD_INFO(%r11)
15498+ orl $TS_COMPAT,TI_status(%r11)
15499+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15500 CFI_REMEMBER_STATE
15501 jnz sysenter_tracesys
15502 cmpq $(IA32_NR_syscalls-1),%rax
15503@@ -172,15 +218,18 @@ sysenter_do_call:
15504 sysenter_dispatch:
15505 call *ia32_sys_call_table(,%rax,8)
15506 movq %rax,RAX-ARGOFFSET(%rsp)
15507+ GET_THREAD_INFO(%r11)
15508 DISABLE_INTERRUPTS(CLBR_NONE)
15509 TRACE_IRQS_OFF
15510- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15511+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15512 jnz sysexit_audit
15513 sysexit_from_sys_call:
15514- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15515+ pax_exit_kernel_user
15516+ pax_erase_kstack
15517+ andl $~TS_COMPAT,TI_status(%r11)
15518 /* clear IF, that popfq doesn't enable interrupts early */
15519- andl $~0x200,EFLAGS-R11(%rsp)
15520- movl RIP-R11(%rsp),%edx /* User %eip */
15521+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
15522+ movl RIP(%rsp),%edx /* User %eip */
15523 CFI_REGISTER rip,rdx
15524 RESTORE_ARGS 0,24,0,0,0,0
15525 xorq %r8,%r8
15526@@ -205,6 +254,9 @@ sysexit_from_sys_call:
15527 movl %eax,%esi /* 2nd arg: syscall number */
15528 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
15529 call __audit_syscall_entry
15530+
15531+ pax_erase_kstack
15532+
15533 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
15534 cmpq $(IA32_NR_syscalls-1),%rax
15535 ja ia32_badsys
15536@@ -216,7 +268,7 @@ sysexit_from_sys_call:
15537 .endm
15538
15539 .macro auditsys_exit exit
15540- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15541+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15542 jnz ia32_ret_from_sys_call
15543 TRACE_IRQS_ON
15544 ENABLE_INTERRUPTS(CLBR_NONE)
15545@@ -227,11 +279,12 @@ sysexit_from_sys_call:
15546 1: setbe %al /* 1 if error, 0 if not */
15547 movzbl %al,%edi /* zero-extend that into %edi */
15548 call __audit_syscall_exit
15549+ GET_THREAD_INFO(%r11)
15550 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
15551 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
15552 DISABLE_INTERRUPTS(CLBR_NONE)
15553 TRACE_IRQS_OFF
15554- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15555+ testl %edi,TI_flags(%r11)
15556 jz \exit
15557 CLEAR_RREGS -ARGOFFSET
15558 jmp int_with_check
15559@@ -253,7 +306,7 @@ sysenter_fix_flags:
15560
15561 sysenter_tracesys:
15562 #ifdef CONFIG_AUDITSYSCALL
15563- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15564+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15565 jz sysenter_auditsys
15566 #endif
15567 SAVE_REST
15568@@ -265,6 +318,9 @@ sysenter_tracesys:
15569 RESTORE_REST
15570 cmpq $(IA32_NR_syscalls-1),%rax
15571 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
15572+
15573+ pax_erase_kstack
15574+
15575 jmp sysenter_do_call
15576 CFI_ENDPROC
15577 ENDPROC(ia32_sysenter_target)
15578@@ -292,19 +348,25 @@ ENDPROC(ia32_sysenter_target)
15579 ENTRY(ia32_cstar_target)
15580 CFI_STARTPROC32 simple
15581 CFI_SIGNAL_FRAME
15582- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
15583+ CFI_DEF_CFA rsp,0
15584 CFI_REGISTER rip,rcx
15585 /*CFI_REGISTER rflags,r11*/
15586 SWAPGS_UNSAFE_STACK
15587 movl %esp,%r8d
15588 CFI_REGISTER rsp,r8
15589 movq PER_CPU_VAR(kernel_stack),%rsp
15590+ SAVE_ARGS 8*6,0,0
15591+ pax_enter_kernel_user
15592+
15593+#ifdef CONFIG_PAX_RANDKSTACK
15594+ pax_erase_kstack
15595+#endif
15596+
15597 /*
15598 * No need to follow this irqs on/off section: the syscall
15599 * disabled irqs and here we enable it straight after entry:
15600 */
15601 ENABLE_INTERRUPTS(CLBR_NONE)
15602- SAVE_ARGS 8,0,0
15603 movl %eax,%eax /* zero extension */
15604 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
15605 movq %rcx,RIP-ARGOFFSET(%rsp)
15606@@ -320,12 +382,25 @@ ENTRY(ia32_cstar_target)
15607 /* no need to do an access_ok check here because r8 has been
15608 32bit zero extended */
15609 /* hardware stack frame is complete now */
15610+
15611+#ifdef CONFIG_PAX_MEMORY_UDEREF
15612+ ASM_PAX_OPEN_USERLAND
15613+ movq pax_user_shadow_base,%r8
15614+ addq RSP-ARGOFFSET(%rsp),%r8
15615+#endif
15616+
15617 ASM_STAC
15618 1: movl (%r8),%r9d
15619 _ASM_EXTABLE(1b,ia32_badarg)
15620 ASM_CLAC
15621- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15622- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15623+
15624+#ifdef CONFIG_PAX_MEMORY_UDEREF
15625+ ASM_PAX_CLOSE_USERLAND
15626+#endif
15627+
15628+ GET_THREAD_INFO(%r11)
15629+ orl $TS_COMPAT,TI_status(%r11)
15630+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15631 CFI_REMEMBER_STATE
15632 jnz cstar_tracesys
15633 cmpq $IA32_NR_syscalls-1,%rax
15634@@ -335,13 +410,16 @@ cstar_do_call:
15635 cstar_dispatch:
15636 call *ia32_sys_call_table(,%rax,8)
15637 movq %rax,RAX-ARGOFFSET(%rsp)
15638+ GET_THREAD_INFO(%r11)
15639 DISABLE_INTERRUPTS(CLBR_NONE)
15640 TRACE_IRQS_OFF
15641- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15642+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
15643 jnz sysretl_audit
15644 sysretl_from_sys_call:
15645- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15646- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
15647+ pax_exit_kernel_user
15648+ pax_erase_kstack
15649+ andl $~TS_COMPAT,TI_status(%r11)
15650+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
15651 movl RIP-ARGOFFSET(%rsp),%ecx
15652 CFI_REGISTER rip,rcx
15653 movl EFLAGS-ARGOFFSET(%rsp),%r11d
15654@@ -368,7 +446,7 @@ sysretl_audit:
15655
15656 cstar_tracesys:
15657 #ifdef CONFIG_AUDITSYSCALL
15658- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15659+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
15660 jz cstar_auditsys
15661 #endif
15662 xchgl %r9d,%ebp
15663@@ -382,11 +460,19 @@ cstar_tracesys:
15664 xchgl %ebp,%r9d
15665 cmpq $(IA32_NR_syscalls-1),%rax
15666 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
15667+
15668+ pax_erase_kstack
15669+
15670 jmp cstar_do_call
15671 END(ia32_cstar_target)
15672
15673 ia32_badarg:
15674 ASM_CLAC
15675+
15676+#ifdef CONFIG_PAX_MEMORY_UDEREF
15677+ ASM_PAX_CLOSE_USERLAND
15678+#endif
15679+
15680 movq $-EFAULT,%rax
15681 jmp ia32_sysret
15682 CFI_ENDPROC
15683@@ -423,19 +509,26 @@ ENTRY(ia32_syscall)
15684 CFI_REL_OFFSET rip,RIP-RIP
15685 PARAVIRT_ADJUST_EXCEPTION_FRAME
15686 SWAPGS
15687- /*
15688- * No need to follow this irqs on/off section: the syscall
15689- * disabled irqs and here we enable it straight after entry:
15690- */
15691- ENABLE_INTERRUPTS(CLBR_NONE)
15692 movl %eax,%eax
15693 pushq_cfi %rax
15694 cld
15695 /* note the registers are not zero extended to the sf.
15696 this could be a problem. */
15697 SAVE_ARGS 0,1,0
15698- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15699- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
15700+ pax_enter_kernel_user
15701+
15702+#ifdef CONFIG_PAX_RANDKSTACK
15703+ pax_erase_kstack
15704+#endif
15705+
15706+ /*
15707+ * No need to follow this irqs on/off section: the syscall
15708+ * disabled irqs and here we enable it straight after entry:
15709+ */
15710+ ENABLE_INTERRUPTS(CLBR_NONE)
15711+ GET_THREAD_INFO(%r11)
15712+ orl $TS_COMPAT,TI_status(%r11)
15713+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
15714 jnz ia32_tracesys
15715 cmpq $(IA32_NR_syscalls-1),%rax
15716 ja ia32_badsys
15717@@ -458,6 +551,9 @@ ia32_tracesys:
15718 RESTORE_REST
15719 cmpq $(IA32_NR_syscalls-1),%rax
15720 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
15721+
15722+ pax_erase_kstack
15723+
15724 jmp ia32_do_call
15725 END(ia32_syscall)
15726
15727diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
15728index 8e0ceec..af13504 100644
15729--- a/arch/x86/ia32/sys_ia32.c
15730+++ b/arch/x86/ia32/sys_ia32.c
15731@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
15732 */
15733 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
15734 {
15735- typeof(ubuf->st_uid) uid = 0;
15736- typeof(ubuf->st_gid) gid = 0;
15737+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
15738+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
15739 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
15740 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
15741 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
15742diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
15743index 372231c..51b537d 100644
15744--- a/arch/x86/include/asm/alternative-asm.h
15745+++ b/arch/x86/include/asm/alternative-asm.h
15746@@ -18,6 +18,45 @@
15747 .endm
15748 #endif
15749
15750+#ifdef KERNEXEC_PLUGIN
15751+ .macro pax_force_retaddr_bts rip=0
15752+ btsq $63,\rip(%rsp)
15753+ .endm
15754+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
15755+ .macro pax_force_retaddr rip=0, reload=0
15756+ btsq $63,\rip(%rsp)
15757+ .endm
15758+ .macro pax_force_fptr ptr
15759+ btsq $63,\ptr
15760+ .endm
15761+ .macro pax_set_fptr_mask
15762+ .endm
15763+#endif
15764+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15765+ .macro pax_force_retaddr rip=0, reload=0
15766+ .if \reload
15767+ pax_set_fptr_mask
15768+ .endif
15769+ orq %r12,\rip(%rsp)
15770+ .endm
15771+ .macro pax_force_fptr ptr
15772+ orq %r12,\ptr
15773+ .endm
15774+ .macro pax_set_fptr_mask
15775+ movabs $0x8000000000000000,%r12
15776+ .endm
15777+#endif
15778+#else
15779+ .macro pax_force_retaddr rip=0, reload=0
15780+ .endm
15781+ .macro pax_force_fptr ptr
15782+ .endm
15783+ .macro pax_force_retaddr_bts rip=0
15784+ .endm
15785+ .macro pax_set_fptr_mask
15786+ .endm
15787+#endif
15788+
15789 .macro altinstruction_entry orig alt feature orig_len alt_len
15790 .long \orig - .
15791 .long \alt - .
15792diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
15793index 473bdbe..b1e3377 100644
15794--- a/arch/x86/include/asm/alternative.h
15795+++ b/arch/x86/include/asm/alternative.h
15796@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15797 ".pushsection .discard,\"aw\",@progbits\n" \
15798 DISCARD_ENTRY(1) \
15799 ".popsection\n" \
15800- ".pushsection .altinstr_replacement, \"ax\"\n" \
15801+ ".pushsection .altinstr_replacement, \"a\"\n" \
15802 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
15803 ".popsection"
15804
15805@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
15806 DISCARD_ENTRY(1) \
15807 DISCARD_ENTRY(2) \
15808 ".popsection\n" \
15809- ".pushsection .altinstr_replacement, \"ax\"\n" \
15810+ ".pushsection .altinstr_replacement, \"a\"\n" \
15811 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
15812 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
15813 ".popsection"
15814diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
15815index 465b309..ab7e51f 100644
15816--- a/arch/x86/include/asm/apic.h
15817+++ b/arch/x86/include/asm/apic.h
15818@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
15819
15820 #ifdef CONFIG_X86_LOCAL_APIC
15821
15822-extern unsigned int apic_verbosity;
15823+extern int apic_verbosity;
15824 extern int local_apic_timer_c2_ok;
15825
15826 extern int disable_apic;
15827diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
15828index 20370c6..a2eb9b0 100644
15829--- a/arch/x86/include/asm/apm.h
15830+++ b/arch/x86/include/asm/apm.h
15831@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
15832 __asm__ __volatile__(APM_DO_ZERO_SEGS
15833 "pushl %%edi\n\t"
15834 "pushl %%ebp\n\t"
15835- "lcall *%%cs:apm_bios_entry\n\t"
15836+ "lcall *%%ss:apm_bios_entry\n\t"
15837 "setc %%al\n\t"
15838 "popl %%ebp\n\t"
15839 "popl %%edi\n\t"
15840@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
15841 __asm__ __volatile__(APM_DO_ZERO_SEGS
15842 "pushl %%edi\n\t"
15843 "pushl %%ebp\n\t"
15844- "lcall *%%cs:apm_bios_entry\n\t"
15845+ "lcall *%%ss:apm_bios_entry\n\t"
15846 "setc %%bl\n\t"
15847 "popl %%ebp\n\t"
15848 "popl %%edi\n\t"
15849diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
15850index 6dd1c7dd..2edd216 100644
15851--- a/arch/x86/include/asm/atomic.h
15852+++ b/arch/x86/include/asm/atomic.h
15853@@ -24,7 +24,18 @@
15854 */
15855 static inline int atomic_read(const atomic_t *v)
15856 {
15857- return (*(volatile int *)&(v)->counter);
15858+ return (*(volatile const int *)&(v)->counter);
15859+}
15860+
15861+/**
15862+ * atomic_read_unchecked - read atomic variable
15863+ * @v: pointer of type atomic_unchecked_t
15864+ *
15865+ * Atomically reads the value of @v.
15866+ */
15867+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
15868+{
15869+ return (*(volatile const int *)&(v)->counter);
15870 }
15871
15872 /**
15873@@ -40,6 +51,18 @@ static inline void atomic_set(atomic_t *v, int i)
15874 }
15875
15876 /**
15877+ * atomic_set_unchecked - set atomic variable
15878+ * @v: pointer of type atomic_unchecked_t
15879+ * @i: required value
15880+ *
15881+ * Atomically sets the value of @v to @i.
15882+ */
15883+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
15884+{
15885+ v->counter = i;
15886+}
15887+
15888+/**
15889 * atomic_add - add integer to atomic variable
15890 * @i: integer value to add
15891 * @v: pointer of type atomic_t
15892@@ -48,7 +71,29 @@ static inline void atomic_set(atomic_t *v, int i)
15893 */
15894 static inline void atomic_add(int i, atomic_t *v)
15895 {
15896- asm volatile(LOCK_PREFIX "addl %1,%0"
15897+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15898+
15899+#ifdef CONFIG_PAX_REFCOUNT
15900+ "jno 0f\n"
15901+ LOCK_PREFIX "subl %1,%0\n"
15902+ "int $4\n0:\n"
15903+ _ASM_EXTABLE(0b, 0b)
15904+#endif
15905+
15906+ : "+m" (v->counter)
15907+ : "ir" (i));
15908+}
15909+
15910+/**
15911+ * atomic_add_unchecked - add integer to atomic variable
15912+ * @i: integer value to add
15913+ * @v: pointer of type atomic_unchecked_t
15914+ *
15915+ * Atomically adds @i to @v.
15916+ */
15917+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
15918+{
15919+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
15920 : "+m" (v->counter)
15921 : "ir" (i));
15922 }
15923@@ -62,7 +107,29 @@ static inline void atomic_add(int i, atomic_t *v)
15924 */
15925 static inline void atomic_sub(int i, atomic_t *v)
15926 {
15927- asm volatile(LOCK_PREFIX "subl %1,%0"
15928+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15929+
15930+#ifdef CONFIG_PAX_REFCOUNT
15931+ "jno 0f\n"
15932+ LOCK_PREFIX "addl %1,%0\n"
15933+ "int $4\n0:\n"
15934+ _ASM_EXTABLE(0b, 0b)
15935+#endif
15936+
15937+ : "+m" (v->counter)
15938+ : "ir" (i));
15939+}
15940+
15941+/**
15942+ * atomic_sub_unchecked - subtract integer from atomic variable
15943+ * @i: integer value to subtract
15944+ * @v: pointer of type atomic_unchecked_t
15945+ *
15946+ * Atomically subtracts @i from @v.
15947+ */
15948+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
15949+{
15950+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
15951 : "+m" (v->counter)
15952 : "ir" (i));
15953 }
15954@@ -78,7 +145,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15955 */
15956 static inline int atomic_sub_and_test(int i, atomic_t *v)
15957 {
15958- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15959+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15960 }
15961
15962 /**
15963@@ -89,7 +156,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15964 */
15965 static inline void atomic_inc(atomic_t *v)
15966 {
15967- asm volatile(LOCK_PREFIX "incl %0"
15968+ asm volatile(LOCK_PREFIX "incl %0\n"
15969+
15970+#ifdef CONFIG_PAX_REFCOUNT
15971+ "jno 0f\n"
15972+ LOCK_PREFIX "decl %0\n"
15973+ "int $4\n0:\n"
15974+ _ASM_EXTABLE(0b, 0b)
15975+#endif
15976+
15977+ : "+m" (v->counter));
15978+}
15979+
15980+/**
15981+ * atomic_inc_unchecked - increment atomic variable
15982+ * @v: pointer of type atomic_unchecked_t
15983+ *
15984+ * Atomically increments @v by 1.
15985+ */
15986+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15987+{
15988+ asm volatile(LOCK_PREFIX "incl %0\n"
15989 : "+m" (v->counter));
15990 }
15991
15992@@ -101,7 +188,27 @@ static inline void atomic_inc(atomic_t *v)
15993 */
15994 static inline void atomic_dec(atomic_t *v)
15995 {
15996- asm volatile(LOCK_PREFIX "decl %0"
15997+ asm volatile(LOCK_PREFIX "decl %0\n"
15998+
15999+#ifdef CONFIG_PAX_REFCOUNT
16000+ "jno 0f\n"
16001+ LOCK_PREFIX "incl %0\n"
16002+ "int $4\n0:\n"
16003+ _ASM_EXTABLE(0b, 0b)
16004+#endif
16005+
16006+ : "+m" (v->counter));
16007+}
16008+
16009+/**
16010+ * atomic_dec_unchecked - decrement atomic variable
16011+ * @v: pointer of type atomic_unchecked_t
16012+ *
16013+ * Atomically decrements @v by 1.
16014+ */
16015+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
16016+{
16017+ asm volatile(LOCK_PREFIX "decl %0\n"
16018 : "+m" (v->counter));
16019 }
16020
16021@@ -115,7 +222,7 @@ static inline void atomic_dec(atomic_t *v)
16022 */
16023 static inline int atomic_dec_and_test(atomic_t *v)
16024 {
16025- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
16026+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
16027 }
16028
16029 /**
16030@@ -128,7 +235,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
16031 */
16032 static inline int atomic_inc_and_test(atomic_t *v)
16033 {
16034- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
16035+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
16036+}
16037+
16038+/**
16039+ * atomic_inc_and_test_unchecked - increment and test
16040+ * @v: pointer of type atomic_unchecked_t
16041+ *
16042+ * Atomically increments @v by 1
16043+ * and returns true if the result is zero, or false for all
16044+ * other cases.
16045+ */
16046+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
16047+{
16048+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
16049 }
16050
16051 /**
16052@@ -142,7 +262,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
16053 */
16054 static inline int atomic_add_negative(int i, atomic_t *v)
16055 {
16056- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
16057+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
16058 }
16059
16060 /**
16061@@ -154,6 +274,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
16062 */
16063 static inline int atomic_add_return(int i, atomic_t *v)
16064 {
16065+ return i + xadd_check_overflow(&v->counter, i);
16066+}
16067+
16068+/**
16069+ * atomic_add_return_unchecked - add integer and return
16070+ * @i: integer value to add
16071+ * @v: pointer of type atomic_unchecked_t
16072+ *
16073+ * Atomically adds @i to @v and returns @i + @v
16074+ */
16075+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
16076+{
16077 return i + xadd(&v->counter, i);
16078 }
16079
16080@@ -170,9 +302,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
16081 }
16082
16083 #define atomic_inc_return(v) (atomic_add_return(1, v))
16084+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
16085+{
16086+ return atomic_add_return_unchecked(1, v);
16087+}
16088 #define atomic_dec_return(v) (atomic_sub_return(1, v))
16089
16090-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
16091+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
16092+{
16093+ return cmpxchg(&v->counter, old, new);
16094+}
16095+
16096+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
16097 {
16098 return cmpxchg(&v->counter, old, new);
16099 }
16100@@ -182,6 +323,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
16101 return xchg(&v->counter, new);
16102 }
16103
16104+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
16105+{
16106+ return xchg(&v->counter, new);
16107+}
16108+
16109 /**
16110 * __atomic_add_unless - add unless the number is already a given value
16111 * @v: pointer of type atomic_t
16112@@ -191,14 +337,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
16113 * Atomically adds @a to @v, so long as @v was not already @u.
16114 * Returns the old value of @v.
16115 */
16116-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
16117+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
16118 {
16119- int c, old;
16120+ int c, old, new;
16121 c = atomic_read(v);
16122 for (;;) {
16123- if (unlikely(c == (u)))
16124+ if (unlikely(c == u))
16125 break;
16126- old = atomic_cmpxchg((v), c, c + (a));
16127+
16128+ asm volatile("addl %2,%0\n"
16129+
16130+#ifdef CONFIG_PAX_REFCOUNT
16131+ "jno 0f\n"
16132+ "subl %2,%0\n"
16133+ "int $4\n0:\n"
16134+ _ASM_EXTABLE(0b, 0b)
16135+#endif
16136+
16137+ : "=r" (new)
16138+ : "0" (c), "ir" (a));
16139+
16140+ old = atomic_cmpxchg(v, c, new);
16141 if (likely(old == c))
16142 break;
16143 c = old;
16144@@ -207,6 +366,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
16145 }
16146
16147 /**
16148+ * atomic_inc_not_zero_hint - increment if not null
16149+ * @v: pointer of type atomic_t
16150+ * @hint: probable value of the atomic before the increment
16151+ *
16152+ * This version of atomic_inc_not_zero() gives a hint of probable
16153+ * value of the atomic. This helps processor to not read the memory
16154+ * before doing the atomic read/modify/write cycle, lowering
16155+ * number of bus transactions on some arches.
16156+ *
16157+ * Returns: 0 if increment was not done, 1 otherwise.
16158+ */
16159+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
16160+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
16161+{
16162+ int val, c = hint, new;
16163+
16164+ /* sanity test, should be removed by compiler if hint is a constant */
16165+ if (!hint)
16166+ return __atomic_add_unless(v, 1, 0);
16167+
16168+ do {
16169+ asm volatile("incl %0\n"
16170+
16171+#ifdef CONFIG_PAX_REFCOUNT
16172+ "jno 0f\n"
16173+ "decl %0\n"
16174+ "int $4\n0:\n"
16175+ _ASM_EXTABLE(0b, 0b)
16176+#endif
16177+
16178+ : "=r" (new)
16179+ : "0" (c));
16180+
16181+ val = atomic_cmpxchg(v, c, new);
16182+ if (val == c)
16183+ return 1;
16184+ c = val;
16185+ } while (c);
16186+
16187+ return 0;
16188+}
16189+
16190+/**
16191 * atomic_inc_short - increment of a short integer
16192 * @v: pointer to type int
16193 *
16194@@ -235,14 +437,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
16195 #endif
16196
16197 /* These are x86-specific, used by some header files */
16198-#define atomic_clear_mask(mask, addr) \
16199- asm volatile(LOCK_PREFIX "andl %0,%1" \
16200- : : "r" (~(mask)), "m" (*(addr)) : "memory")
16201+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
16202+{
16203+ asm volatile(LOCK_PREFIX "andl %1,%0"
16204+ : "+m" (v->counter)
16205+ : "r" (~(mask))
16206+ : "memory");
16207+}
16208
16209-#define atomic_set_mask(mask, addr) \
16210- asm volatile(LOCK_PREFIX "orl %0,%1" \
16211- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
16212- : "memory")
16213+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
16214+{
16215+ asm volatile(LOCK_PREFIX "andl %1,%0"
16216+ : "+m" (v->counter)
16217+ : "r" (~(mask))
16218+ : "memory");
16219+}
16220+
16221+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
16222+{
16223+ asm volatile(LOCK_PREFIX "orl %1,%0"
16224+ : "+m" (v->counter)
16225+ : "r" (mask)
16226+ : "memory");
16227+}
16228+
16229+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
16230+{
16231+ asm volatile(LOCK_PREFIX "orl %1,%0"
16232+ : "+m" (v->counter)
16233+ : "r" (mask)
16234+ : "memory");
16235+}
16236
16237 #ifdef CONFIG_X86_32
16238 # include <asm/atomic64_32.h>
16239diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
16240index b154de7..bf18a5a 100644
16241--- a/arch/x86/include/asm/atomic64_32.h
16242+++ b/arch/x86/include/asm/atomic64_32.h
16243@@ -12,6 +12,14 @@ typedef struct {
16244 u64 __aligned(8) counter;
16245 } atomic64_t;
16246
16247+#ifdef CONFIG_PAX_REFCOUNT
16248+typedef struct {
16249+ u64 __aligned(8) counter;
16250+} atomic64_unchecked_t;
16251+#else
16252+typedef atomic64_t atomic64_unchecked_t;
16253+#endif
16254+
16255 #define ATOMIC64_INIT(val) { (val) }
16256
16257 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
16258@@ -37,21 +45,31 @@ typedef struct {
16259 ATOMIC64_DECL_ONE(sym##_386)
16260
16261 ATOMIC64_DECL_ONE(add_386);
16262+ATOMIC64_DECL_ONE(add_unchecked_386);
16263 ATOMIC64_DECL_ONE(sub_386);
16264+ATOMIC64_DECL_ONE(sub_unchecked_386);
16265 ATOMIC64_DECL_ONE(inc_386);
16266+ATOMIC64_DECL_ONE(inc_unchecked_386);
16267 ATOMIC64_DECL_ONE(dec_386);
16268+ATOMIC64_DECL_ONE(dec_unchecked_386);
16269 #endif
16270
16271 #define alternative_atomic64(f, out, in...) \
16272 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
16273
16274 ATOMIC64_DECL(read);
16275+ATOMIC64_DECL(read_unchecked);
16276 ATOMIC64_DECL(set);
16277+ATOMIC64_DECL(set_unchecked);
16278 ATOMIC64_DECL(xchg);
16279 ATOMIC64_DECL(add_return);
16280+ATOMIC64_DECL(add_return_unchecked);
16281 ATOMIC64_DECL(sub_return);
16282+ATOMIC64_DECL(sub_return_unchecked);
16283 ATOMIC64_DECL(inc_return);
16284+ATOMIC64_DECL(inc_return_unchecked);
16285 ATOMIC64_DECL(dec_return);
16286+ATOMIC64_DECL(dec_return_unchecked);
16287 ATOMIC64_DECL(dec_if_positive);
16288 ATOMIC64_DECL(inc_not_zero);
16289 ATOMIC64_DECL(add_unless);
16290@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
16291 }
16292
16293 /**
16294+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
16295+ * @p: pointer to type atomic64_unchecked_t
16296+ * @o: expected value
16297+ * @n: new value
16298+ *
16299+ * Atomically sets @v to @n if it was equal to @o and returns
16300+ * the old value.
16301+ */
16302+
16303+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
16304+{
16305+ return cmpxchg64(&v->counter, o, n);
16306+}
16307+
16308+/**
16309 * atomic64_xchg - xchg atomic64 variable
16310 * @v: pointer to type atomic64_t
16311 * @n: value to assign
16312@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
16313 }
16314
16315 /**
16316+ * atomic64_set_unchecked - set atomic64 variable
16317+ * @v: pointer to type atomic64_unchecked_t
16318+ * @n: value to assign
16319+ *
16320+ * Atomically sets the value of @v to @n.
16321+ */
16322+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
16323+{
16324+ unsigned high = (unsigned)(i >> 32);
16325+ unsigned low = (unsigned)i;
16326+ alternative_atomic64(set, /* no output */,
16327+ "S" (v), "b" (low), "c" (high)
16328+ : "eax", "edx", "memory");
16329+}
16330+
16331+/**
16332 * atomic64_read - read atomic64 variable
16333 * @v: pointer to type atomic64_t
16334 *
16335@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
16336 }
16337
16338 /**
16339+ * atomic64_read_unchecked - read atomic64 variable
16340+ * @v: pointer to type atomic64_unchecked_t
16341+ *
16342+ * Atomically reads the value of @v and returns it.
16343+ */
16344+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
16345+{
16346+ long long r;
16347+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
16348+ return r;
16349+ }
16350+
16351+/**
16352 * atomic64_add_return - add and return
16353 * @i: integer value to add
16354 * @v: pointer to type atomic64_t
16355@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
16356 return i;
16357 }
16358
16359+/**
16360+ * atomic64_add_return_unchecked - add and return
16361+ * @i: integer value to add
16362+ * @v: pointer to type atomic64_unchecked_t
16363+ *
16364+ * Atomically adds @i to @v and returns @i + *@v
16365+ */
16366+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
16367+{
16368+ alternative_atomic64(add_return_unchecked,
16369+ ASM_OUTPUT2("+A" (i), "+c" (v)),
16370+ ASM_NO_INPUT_CLOBBER("memory"));
16371+ return i;
16372+}
16373+
16374 /*
16375 * Other variants with different arithmetic operators:
16376 */
16377@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
16378 return a;
16379 }
16380
16381+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
16382+{
16383+ long long a;
16384+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
16385+ "S" (v) : "memory", "ecx");
16386+ return a;
16387+}
16388+
16389 static inline long long atomic64_dec_return(atomic64_t *v)
16390 {
16391 long long a;
16392@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
16393 }
16394
16395 /**
16396+ * atomic64_add_unchecked - add integer to atomic64 variable
16397+ * @i: integer value to add
16398+ * @v: pointer to type atomic64_unchecked_t
16399+ *
16400+ * Atomically adds @i to @v.
16401+ */
16402+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
16403+{
16404+ __alternative_atomic64(add_unchecked, add_return_unchecked,
16405+ ASM_OUTPUT2("+A" (i), "+c" (v)),
16406+ ASM_NO_INPUT_CLOBBER("memory"));
16407+ return i;
16408+}
16409+
16410+/**
16411 * atomic64_sub - subtract the atomic64 variable
16412 * @i: integer value to subtract
16413 * @v: pointer to type atomic64_t
16414diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
16415index 46e9052..ae45136 100644
16416--- a/arch/x86/include/asm/atomic64_64.h
16417+++ b/arch/x86/include/asm/atomic64_64.h
16418@@ -18,7 +18,19 @@
16419 */
16420 static inline long atomic64_read(const atomic64_t *v)
16421 {
16422- return (*(volatile long *)&(v)->counter);
16423+ return (*(volatile const long *)&(v)->counter);
16424+}
16425+
16426+/**
16427+ * atomic64_read_unchecked - read atomic64 variable
16428+ * @v: pointer of type atomic64_unchecked_t
16429+ *
16430+ * Atomically reads the value of @v.
16431+ * Doesn't imply a read memory barrier.
16432+ */
16433+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
16434+{
16435+ return (*(volatile const long *)&(v)->counter);
16436 }
16437
16438 /**
16439@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
16440 }
16441
16442 /**
16443+ * atomic64_set_unchecked - set atomic64 variable
16444+ * @v: pointer to type atomic64_unchecked_t
16445+ * @i: required value
16446+ *
16447+ * Atomically sets the value of @v to @i.
16448+ */
16449+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
16450+{
16451+ v->counter = i;
16452+}
16453+
16454+/**
16455 * atomic64_add - add integer to atomic64 variable
16456 * @i: integer value to add
16457 * @v: pointer to type atomic64_t
16458@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
16459 */
16460 static inline void atomic64_add(long i, atomic64_t *v)
16461 {
16462+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
16463+
16464+#ifdef CONFIG_PAX_REFCOUNT
16465+ "jno 0f\n"
16466+ LOCK_PREFIX "subq %1,%0\n"
16467+ "int $4\n0:\n"
16468+ _ASM_EXTABLE(0b, 0b)
16469+#endif
16470+
16471+ : "=m" (v->counter)
16472+ : "er" (i), "m" (v->counter));
16473+}
16474+
16475+/**
16476+ * atomic64_add_unchecked - add integer to atomic64 variable
16477+ * @i: integer value to add
16478+ * @v: pointer to type atomic64_unchecked_t
16479+ *
16480+ * Atomically adds @i to @v.
16481+ */
16482+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
16483+{
16484 asm volatile(LOCK_PREFIX "addq %1,%0"
16485 : "=m" (v->counter)
16486 : "er" (i), "m" (v->counter));
16487@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
16488 */
16489 static inline void atomic64_sub(long i, atomic64_t *v)
16490 {
16491- asm volatile(LOCK_PREFIX "subq %1,%0"
16492+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
16493+
16494+#ifdef CONFIG_PAX_REFCOUNT
16495+ "jno 0f\n"
16496+ LOCK_PREFIX "addq %1,%0\n"
16497+ "int $4\n0:\n"
16498+ _ASM_EXTABLE(0b, 0b)
16499+#endif
16500+
16501+ : "=m" (v->counter)
16502+ : "er" (i), "m" (v->counter));
16503+}
16504+
16505+/**
16506+ * atomic64_sub_unchecked - subtract the atomic64 variable
16507+ * @i: integer value to subtract
16508+ * @v: pointer to type atomic64_unchecked_t
16509+ *
16510+ * Atomically subtracts @i from @v.
16511+ */
16512+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
16513+{
16514+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
16515 : "=m" (v->counter)
16516 : "er" (i), "m" (v->counter));
16517 }
16518@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
16519 */
16520 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16521 {
16522- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
16523+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
16524 }
16525
16526 /**
16527@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
16528 */
16529 static inline void atomic64_inc(atomic64_t *v)
16530 {
16531+ asm volatile(LOCK_PREFIX "incq %0\n"
16532+
16533+#ifdef CONFIG_PAX_REFCOUNT
16534+ "jno 0f\n"
16535+ LOCK_PREFIX "decq %0\n"
16536+ "int $4\n0:\n"
16537+ _ASM_EXTABLE(0b, 0b)
16538+#endif
16539+
16540+ : "=m" (v->counter)
16541+ : "m" (v->counter));
16542+}
16543+
16544+/**
16545+ * atomic64_inc_unchecked - increment atomic64 variable
16546+ * @v: pointer to type atomic64_unchecked_t
16547+ *
16548+ * Atomically increments @v by 1.
16549+ */
16550+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
16551+{
16552 asm volatile(LOCK_PREFIX "incq %0"
16553 : "=m" (v->counter)
16554 : "m" (v->counter));
16555@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
16556 */
16557 static inline void atomic64_dec(atomic64_t *v)
16558 {
16559- asm volatile(LOCK_PREFIX "decq %0"
16560+ asm volatile(LOCK_PREFIX "decq %0\n"
16561+
16562+#ifdef CONFIG_PAX_REFCOUNT
16563+ "jno 0f\n"
16564+ LOCK_PREFIX "incq %0\n"
16565+ "int $4\n0:\n"
16566+ _ASM_EXTABLE(0b, 0b)
16567+#endif
16568+
16569+ : "=m" (v->counter)
16570+ : "m" (v->counter));
16571+}
16572+
16573+/**
16574+ * atomic64_dec_unchecked - decrement atomic64 variable
16575+ * @v: pointer to type atomic64_t
16576+ *
16577+ * Atomically decrements @v by 1.
16578+ */
16579+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
16580+{
16581+ asm volatile(LOCK_PREFIX "decq %0\n"
16582 : "=m" (v->counter)
16583 : "m" (v->counter));
16584 }
16585@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
16586 */
16587 static inline int atomic64_dec_and_test(atomic64_t *v)
16588 {
16589- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
16590+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
16591 }
16592
16593 /**
16594@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
16595 */
16596 static inline int atomic64_inc_and_test(atomic64_t *v)
16597 {
16598- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
16599+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
16600 }
16601
16602 /**
16603@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
16604 */
16605 static inline int atomic64_add_negative(long i, atomic64_t *v)
16606 {
16607- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
16608+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
16609 }
16610
16611 /**
16612@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
16613 */
16614 static inline long atomic64_add_return(long i, atomic64_t *v)
16615 {
16616+ return i + xadd_check_overflow(&v->counter, i);
16617+}
16618+
16619+/**
16620+ * atomic64_add_return_unchecked - add and return
16621+ * @i: integer value to add
16622+ * @v: pointer to type atomic64_unchecked_t
16623+ *
16624+ * Atomically adds @i to @v and returns @i + @v
16625+ */
16626+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
16627+{
16628 return i + xadd(&v->counter, i);
16629 }
16630
16631@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
16632 }
16633
16634 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
16635+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
16636+{
16637+ return atomic64_add_return_unchecked(1, v);
16638+}
16639 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
16640
16641 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16642@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
16643 return cmpxchg(&v->counter, old, new);
16644 }
16645
16646+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
16647+{
16648+ return cmpxchg(&v->counter, old, new);
16649+}
16650+
16651 static inline long atomic64_xchg(atomic64_t *v, long new)
16652 {
16653 return xchg(&v->counter, new);
16654@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
16655 */
16656 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
16657 {
16658- long c, old;
16659+ long c, old, new;
16660 c = atomic64_read(v);
16661 for (;;) {
16662- if (unlikely(c == (u)))
16663+ if (unlikely(c == u))
16664 break;
16665- old = atomic64_cmpxchg((v), c, c + (a));
16666+
16667+ asm volatile("add %2,%0\n"
16668+
16669+#ifdef CONFIG_PAX_REFCOUNT
16670+ "jno 0f\n"
16671+ "sub %2,%0\n"
16672+ "int $4\n0:\n"
16673+ _ASM_EXTABLE(0b, 0b)
16674+#endif
16675+
16676+ : "=r" (new)
16677+ : "0" (c), "ir" (a));
16678+
16679+ old = atomic64_cmpxchg(v, c, new);
16680 if (likely(old == c))
16681 break;
16682 c = old;
16683 }
16684- return c != (u);
16685+ return c != u;
16686 }
16687
16688 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
16689diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
16690index 0f4460b..fa1ee19 100644
16691--- a/arch/x86/include/asm/barrier.h
16692+++ b/arch/x86/include/asm/barrier.h
16693@@ -107,7 +107,7 @@
16694 do { \
16695 compiletime_assert_atomic_type(*p); \
16696 smp_mb(); \
16697- ACCESS_ONCE(*p) = (v); \
16698+ ACCESS_ONCE_RW(*p) = (v); \
16699 } while (0)
16700
16701 #define smp_load_acquire(p) \
16702@@ -124,7 +124,7 @@ do { \
16703 do { \
16704 compiletime_assert_atomic_type(*p); \
16705 barrier(); \
16706- ACCESS_ONCE(*p) = (v); \
16707+ ACCESS_ONCE_RW(*p) = (v); \
16708 } while (0)
16709
16710 #define smp_load_acquire(p) \
16711diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
16712index cfe3b95..d01b118 100644
16713--- a/arch/x86/include/asm/bitops.h
16714+++ b/arch/x86/include/asm/bitops.h
16715@@ -50,7 +50,7 @@
16716 * a mask operation on a byte.
16717 */
16718 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
16719-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
16720+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
16721 #define CONST_MASK(nr) (1 << ((nr) & 7))
16722
16723 /**
16724@@ -203,7 +203,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
16725 */
16726 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
16727 {
16728- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16729+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
16730 }
16731
16732 /**
16733@@ -249,7 +249,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
16734 */
16735 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
16736 {
16737- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16738+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
16739 }
16740
16741 /**
16742@@ -302,7 +302,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
16743 */
16744 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
16745 {
16746- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16747+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
16748 }
16749
16750 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
16751@@ -343,7 +343,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
16752 *
16753 * Undefined if no bit exists, so code should check against 0 first.
16754 */
16755-static inline unsigned long __ffs(unsigned long word)
16756+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
16757 {
16758 asm("rep; bsf %1,%0"
16759 : "=r" (word)
16760@@ -357,7 +357,7 @@ static inline unsigned long __ffs(unsigned long word)
16761 *
16762 * Undefined if no zero exists, so code should check against ~0UL first.
16763 */
16764-static inline unsigned long ffz(unsigned long word)
16765+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
16766 {
16767 asm("rep; bsf %1,%0"
16768 : "=r" (word)
16769@@ -371,7 +371,7 @@ static inline unsigned long ffz(unsigned long word)
16770 *
16771 * Undefined if no set bit exists, so code should check against 0 first.
16772 */
16773-static inline unsigned long __fls(unsigned long word)
16774+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
16775 {
16776 asm("bsr %1,%0"
16777 : "=r" (word)
16778@@ -434,7 +434,7 @@ static inline int ffs(int x)
16779 * set bit if value is nonzero. The last (most significant) bit is
16780 * at position 32.
16781 */
16782-static inline int fls(int x)
16783+static inline int __intentional_overflow(-1) fls(int x)
16784 {
16785 int r;
16786
16787@@ -476,7 +476,7 @@ static inline int fls(int x)
16788 * at position 64.
16789 */
16790 #ifdef CONFIG_X86_64
16791-static __always_inline int fls64(__u64 x)
16792+static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
16793 {
16794 int bitpos = -1;
16795 /*
16796diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
16797index 4fa687a..60f2d39 100644
16798--- a/arch/x86/include/asm/boot.h
16799+++ b/arch/x86/include/asm/boot.h
16800@@ -6,10 +6,15 @@
16801 #include <uapi/asm/boot.h>
16802
16803 /* Physical address where kernel should be loaded. */
16804-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16805+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
16806 + (CONFIG_PHYSICAL_ALIGN - 1)) \
16807 & ~(CONFIG_PHYSICAL_ALIGN - 1))
16808
16809+#ifndef __ASSEMBLY__
16810+extern unsigned char __LOAD_PHYSICAL_ADDR[];
16811+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
16812+#endif
16813+
16814 /* Minimum kernel alignment, as a power of two */
16815 #ifdef CONFIG_X86_64
16816 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
16817diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
16818index 48f99f1..d78ebf9 100644
16819--- a/arch/x86/include/asm/cache.h
16820+++ b/arch/x86/include/asm/cache.h
16821@@ -5,12 +5,13 @@
16822
16823 /* L1 cache line size */
16824 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
16825-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
16826+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
16827
16828 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
16829+#define __read_only __attribute__((__section__(".data..read_only")))
16830
16831 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
16832-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
16833+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
16834
16835 #ifdef CONFIG_X86_VSMP
16836 #ifdef CONFIG_SMP
16837diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
16838index 9863ee3..4a1f8e1 100644
16839--- a/arch/x86/include/asm/cacheflush.h
16840+++ b/arch/x86/include/asm/cacheflush.h
16841@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
16842 unsigned long pg_flags = pg->flags & _PGMT_MASK;
16843
16844 if (pg_flags == _PGMT_DEFAULT)
16845- return -1;
16846+ return ~0UL;
16847 else if (pg_flags == _PGMT_WC)
16848 return _PAGE_CACHE_WC;
16849 else if (pg_flags == _PGMT_UC_MINUS)
16850diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
16851index cb4c73b..c473c29 100644
16852--- a/arch/x86/include/asm/calling.h
16853+++ b/arch/x86/include/asm/calling.h
16854@@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
16855 #define RSP 152
16856 #define SS 160
16857
16858-#define ARGOFFSET R11
16859-#define SWFRAME ORIG_RAX
16860+#define ARGOFFSET R15
16861
16862 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
16863- subq $9*8+\addskip, %rsp
16864- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
16865- movq_cfi rdi, 8*8
16866- movq_cfi rsi, 7*8
16867- movq_cfi rdx, 6*8
16868+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
16869+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
16870+ movq_cfi rdi, RDI
16871+ movq_cfi rsi, RSI
16872+ movq_cfi rdx, RDX
16873
16874 .if \save_rcx
16875- movq_cfi rcx, 5*8
16876+ movq_cfi rcx, RCX
16877 .endif
16878
16879- movq_cfi rax, 4*8
16880+ movq_cfi rax, RAX
16881
16882 .if \save_r891011
16883- movq_cfi r8, 3*8
16884- movq_cfi r9, 2*8
16885- movq_cfi r10, 1*8
16886- movq_cfi r11, 0*8
16887+ movq_cfi r8, R8
16888+ movq_cfi r9, R9
16889+ movq_cfi r10, R10
16890+ movq_cfi r11, R11
16891 .endif
16892
16893+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16894+ movq_cfi r12, R12
16895+#endif
16896+
16897 .endm
16898
16899-#define ARG_SKIP (9*8)
16900+#define ARG_SKIP ORIG_RAX
16901
16902 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
16903 rstor_r8910=1, rstor_rdx=1
16904+
16905+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16906+ movq_cfi_restore R12, r12
16907+#endif
16908+
16909 .if \rstor_r11
16910- movq_cfi_restore 0*8, r11
16911+ movq_cfi_restore R11, r11
16912 .endif
16913
16914 .if \rstor_r8910
16915- movq_cfi_restore 1*8, r10
16916- movq_cfi_restore 2*8, r9
16917- movq_cfi_restore 3*8, r8
16918+ movq_cfi_restore R10, r10
16919+ movq_cfi_restore R9, r9
16920+ movq_cfi_restore R8, r8
16921 .endif
16922
16923 .if \rstor_rax
16924- movq_cfi_restore 4*8, rax
16925+ movq_cfi_restore RAX, rax
16926 .endif
16927
16928 .if \rstor_rcx
16929- movq_cfi_restore 5*8, rcx
16930+ movq_cfi_restore RCX, rcx
16931 .endif
16932
16933 .if \rstor_rdx
16934- movq_cfi_restore 6*8, rdx
16935+ movq_cfi_restore RDX, rdx
16936 .endif
16937
16938- movq_cfi_restore 7*8, rsi
16939- movq_cfi_restore 8*8, rdi
16940+ movq_cfi_restore RSI, rsi
16941+ movq_cfi_restore RDI, rdi
16942
16943- .if ARG_SKIP+\addskip > 0
16944- addq $ARG_SKIP+\addskip, %rsp
16945- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
16946+ .if ORIG_RAX+\addskip > 0
16947+ addq $ORIG_RAX+\addskip, %rsp
16948+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
16949 .endif
16950 .endm
16951
16952- .macro LOAD_ARGS offset, skiprax=0
16953- movq \offset(%rsp), %r11
16954- movq \offset+8(%rsp), %r10
16955- movq \offset+16(%rsp), %r9
16956- movq \offset+24(%rsp), %r8
16957- movq \offset+40(%rsp), %rcx
16958- movq \offset+48(%rsp), %rdx
16959- movq \offset+56(%rsp), %rsi
16960- movq \offset+64(%rsp), %rdi
16961+ .macro LOAD_ARGS skiprax=0
16962+ movq R11(%rsp), %r11
16963+ movq R10(%rsp), %r10
16964+ movq R9(%rsp), %r9
16965+ movq R8(%rsp), %r8
16966+ movq RCX(%rsp), %rcx
16967+ movq RDX(%rsp), %rdx
16968+ movq RSI(%rsp), %rsi
16969+ movq RDI(%rsp), %rdi
16970 .if \skiprax
16971 .else
16972- movq \offset+72(%rsp), %rax
16973+ movq RAX(%rsp), %rax
16974 .endif
16975 .endm
16976
16977-#define REST_SKIP (6*8)
16978-
16979 .macro SAVE_REST
16980- subq $REST_SKIP, %rsp
16981- CFI_ADJUST_CFA_OFFSET REST_SKIP
16982- movq_cfi rbx, 5*8
16983- movq_cfi rbp, 4*8
16984- movq_cfi r12, 3*8
16985- movq_cfi r13, 2*8
16986- movq_cfi r14, 1*8
16987- movq_cfi r15, 0*8
16988+ movq_cfi rbx, RBX
16989+ movq_cfi rbp, RBP
16990+
16991+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16992+ movq_cfi r12, R12
16993+#endif
16994+
16995+ movq_cfi r13, R13
16996+ movq_cfi r14, R14
16997+ movq_cfi r15, R15
16998 .endm
16999
17000 .macro RESTORE_REST
17001- movq_cfi_restore 0*8, r15
17002- movq_cfi_restore 1*8, r14
17003- movq_cfi_restore 2*8, r13
17004- movq_cfi_restore 3*8, r12
17005- movq_cfi_restore 4*8, rbp
17006- movq_cfi_restore 5*8, rbx
17007- addq $REST_SKIP, %rsp
17008- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
17009+ movq_cfi_restore R15, r15
17010+ movq_cfi_restore R14, r14
17011+ movq_cfi_restore R13, r13
17012+
17013+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
17014+ movq_cfi_restore R12, r12
17015+#endif
17016+
17017+ movq_cfi_restore RBP, rbp
17018+ movq_cfi_restore RBX, rbx
17019 .endm
17020
17021 .macro SAVE_ALL
17022diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
17023index f50de69..2b0a458 100644
17024--- a/arch/x86/include/asm/checksum_32.h
17025+++ b/arch/x86/include/asm/checksum_32.h
17026@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
17027 int len, __wsum sum,
17028 int *src_err_ptr, int *dst_err_ptr);
17029
17030+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
17031+ int len, __wsum sum,
17032+ int *src_err_ptr, int *dst_err_ptr);
17033+
17034+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
17035+ int len, __wsum sum,
17036+ int *src_err_ptr, int *dst_err_ptr);
17037+
17038 /*
17039 * Note: when you get a NULL pointer exception here this means someone
17040 * passed in an incorrect kernel address to one of these functions.
17041@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
17042
17043 might_sleep();
17044 stac();
17045- ret = csum_partial_copy_generic((__force void *)src, dst,
17046+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
17047 len, sum, err_ptr, NULL);
17048 clac();
17049
17050@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
17051 might_sleep();
17052 if (access_ok(VERIFY_WRITE, dst, len)) {
17053 stac();
17054- ret = csum_partial_copy_generic(src, (__force void *)dst,
17055+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
17056 len, sum, NULL, err_ptr);
17057 clac();
17058 return ret;
17059diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
17060index 99c105d7..2f667ac 100644
17061--- a/arch/x86/include/asm/cmpxchg.h
17062+++ b/arch/x86/include/asm/cmpxchg.h
17063@@ -16,8 +16,12 @@ extern void __cmpxchg_wrong_size(void)
17064 __compiletime_error("Bad argument size for cmpxchg");
17065 extern void __xadd_wrong_size(void)
17066 __compiletime_error("Bad argument size for xadd");
17067+extern void __xadd_check_overflow_wrong_size(void)
17068+ __compiletime_error("Bad argument size for xadd_check_overflow");
17069 extern void __add_wrong_size(void)
17070 __compiletime_error("Bad argument size for add");
17071+extern void __add_check_overflow_wrong_size(void)
17072+ __compiletime_error("Bad argument size for add_check_overflow");
17073
17074 /*
17075 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
17076@@ -69,6 +73,38 @@ extern void __add_wrong_size(void)
17077 __ret; \
17078 })
17079
17080+#ifdef CONFIG_PAX_REFCOUNT
17081+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
17082+ ({ \
17083+ __typeof__ (*(ptr)) __ret = (arg); \
17084+ switch (sizeof(*(ptr))) { \
17085+ case __X86_CASE_L: \
17086+ asm volatile (lock #op "l %0, %1\n" \
17087+ "jno 0f\n" \
17088+ "mov %0,%1\n" \
17089+ "int $4\n0:\n" \
17090+ _ASM_EXTABLE(0b, 0b) \
17091+ : "+r" (__ret), "+m" (*(ptr)) \
17092+ : : "memory", "cc"); \
17093+ break; \
17094+ case __X86_CASE_Q: \
17095+ asm volatile (lock #op "q %q0, %1\n" \
17096+ "jno 0f\n" \
17097+ "mov %0,%1\n" \
17098+ "int $4\n0:\n" \
17099+ _ASM_EXTABLE(0b, 0b) \
17100+ : "+r" (__ret), "+m" (*(ptr)) \
17101+ : : "memory", "cc"); \
17102+ break; \
17103+ default: \
17104+ __ ## op ## _check_overflow_wrong_size(); \
17105+ } \
17106+ __ret; \
17107+ })
17108+#else
17109+#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
17110+#endif
17111+
17112 /*
17113 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
17114 * Since this is generally used to protect other memory information, we
17115@@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
17116 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
17117 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
17118
17119+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
17120+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
17121+
17122 #define __add(ptr, inc, lock) \
17123 ({ \
17124 __typeof__ (*(ptr)) __ret = (inc); \
17125diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
17126index 59c6c40..5e0b22c 100644
17127--- a/arch/x86/include/asm/compat.h
17128+++ b/arch/x86/include/asm/compat.h
17129@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
17130 typedef u32 compat_uint_t;
17131 typedef u32 compat_ulong_t;
17132 typedef u64 __attribute__((aligned(4))) compat_u64;
17133-typedef u32 compat_uptr_t;
17134+typedef u32 __user compat_uptr_t;
17135
17136 struct compat_timespec {
17137 compat_time_t tv_sec;
17138diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
17139index bb9b258..5fad1bf 100644
17140--- a/arch/x86/include/asm/cpufeature.h
17141+++ b/arch/x86/include/asm/cpufeature.h
17142@@ -203,14 +203,14 @@
17143 #define X86_FEATURE_PAUSEFILTER ( 8*32+13) /* AMD filtered pause intercept */
17144 #define X86_FEATURE_PFTHRESHOLD ( 8*32+14) /* AMD pause filter threshold */
17145
17146-
17147+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
17148 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
17149 #define X86_FEATURE_FSGSBASE ( 9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
17150 #define X86_FEATURE_TSC_ADJUST ( 9*32+ 1) /* TSC adjustment MSR 0x3b */
17151 #define X86_FEATURE_BMI1 ( 9*32+ 3) /* 1st group bit manipulation extensions */
17152 #define X86_FEATURE_HLE ( 9*32+ 4) /* Hardware Lock Elision */
17153 #define X86_FEATURE_AVX2 ( 9*32+ 5) /* AVX2 instructions */
17154-#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Protection */
17155+#define X86_FEATURE_SMEP ( 9*32+ 7) /* Supervisor Mode Execution Prevention */
17156 #define X86_FEATURE_BMI2 ( 9*32+ 8) /* 2nd group bit manipulation extensions */
17157 #define X86_FEATURE_ERMS ( 9*32+ 9) /* Enhanced REP MOVSB/STOSB */
17158 #define X86_FEATURE_INVPCID ( 9*32+10) /* Invalidate Processor Context ID */
17159@@ -370,6 +370,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
17160 #undef cpu_has_centaur_mcr
17161 #define cpu_has_centaur_mcr 0
17162
17163+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
17164 #endif /* CONFIG_X86_64 */
17165
17166 #if __GNUC__ >= 4
17167@@ -422,7 +423,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
17168
17169 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
17170 t_warn:
17171- warn_pre_alternatives();
17172+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
17173+ warn_pre_alternatives();
17174 return false;
17175 #endif
17176
17177@@ -442,7 +444,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
17178 ".section .discard,\"aw\",@progbits\n"
17179 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
17180 ".previous\n"
17181- ".section .altinstr_replacement,\"ax\"\n"
17182+ ".section .altinstr_replacement,\"a\"\n"
17183 "3: movb $1,%0\n"
17184 "4:\n"
17185 ".previous\n"
17186@@ -479,7 +481,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
17187 " .byte 2b - 1b\n" /* src len */
17188 " .byte 4f - 3f\n" /* repl len */
17189 ".previous\n"
17190- ".section .altinstr_replacement,\"ax\"\n"
17191+ ".section .altinstr_replacement,\"a\"\n"
17192 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
17193 "4:\n"
17194 ".previous\n"
17195@@ -512,7 +514,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
17196 ".section .discard,\"aw\",@progbits\n"
17197 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
17198 ".previous\n"
17199- ".section .altinstr_replacement,\"ax\"\n"
17200+ ".section .altinstr_replacement,\"a\"\n"
17201 "3: movb $0,%0\n"
17202 "4:\n"
17203 ".previous\n"
17204@@ -526,7 +528,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
17205 ".section .discard,\"aw\",@progbits\n"
17206 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
17207 ".previous\n"
17208- ".section .altinstr_replacement,\"ax\"\n"
17209+ ".section .altinstr_replacement,\"a\"\n"
17210 "5: movb $1,%0\n"
17211 "6:\n"
17212 ".previous\n"
17213diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
17214index 50d033a..37deb26 100644
17215--- a/arch/x86/include/asm/desc.h
17216+++ b/arch/x86/include/asm/desc.h
17217@@ -4,6 +4,7 @@
17218 #include <asm/desc_defs.h>
17219 #include <asm/ldt.h>
17220 #include <asm/mmu.h>
17221+#include <asm/pgtable.h>
17222
17223 #include <linux/smp.h>
17224 #include <linux/percpu.h>
17225@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
17226
17227 desc->type = (info->read_exec_only ^ 1) << 1;
17228 desc->type |= info->contents << 2;
17229+ desc->type |= info->seg_not_present ^ 1;
17230
17231 desc->s = 1;
17232 desc->dpl = 0x3;
17233@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
17234 }
17235
17236 extern struct desc_ptr idt_descr;
17237-extern gate_desc idt_table[];
17238-extern struct desc_ptr debug_idt_descr;
17239-extern gate_desc debug_idt_table[];
17240-
17241-struct gdt_page {
17242- struct desc_struct gdt[GDT_ENTRIES];
17243-} __attribute__((aligned(PAGE_SIZE)));
17244-
17245-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
17246+extern gate_desc idt_table[IDT_ENTRIES];
17247+extern const struct desc_ptr debug_idt_descr;
17248+extern gate_desc debug_idt_table[IDT_ENTRIES];
17249
17250+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
17251 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
17252 {
17253- return per_cpu(gdt_page, cpu).gdt;
17254+ return cpu_gdt_table[cpu];
17255 }
17256
17257 #ifdef CONFIG_X86_64
17258@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
17259 unsigned long base, unsigned dpl, unsigned flags,
17260 unsigned short seg)
17261 {
17262- gate->a = (seg << 16) | (base & 0xffff);
17263- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
17264+ gate->gate.offset_low = base;
17265+ gate->gate.seg = seg;
17266+ gate->gate.reserved = 0;
17267+ gate->gate.type = type;
17268+ gate->gate.s = 0;
17269+ gate->gate.dpl = dpl;
17270+ gate->gate.p = 1;
17271+ gate->gate.offset_high = base >> 16;
17272 }
17273
17274 #endif
17275@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
17276
17277 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
17278 {
17279+ pax_open_kernel();
17280 memcpy(&idt[entry], gate, sizeof(*gate));
17281+ pax_close_kernel();
17282 }
17283
17284 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
17285 {
17286+ pax_open_kernel();
17287 memcpy(&ldt[entry], desc, 8);
17288+ pax_close_kernel();
17289 }
17290
17291 static inline void
17292@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
17293 default: size = sizeof(*gdt); break;
17294 }
17295
17296+ pax_open_kernel();
17297 memcpy(&gdt[entry], desc, size);
17298+ pax_close_kernel();
17299 }
17300
17301 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
17302@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
17303
17304 static inline void native_load_tr_desc(void)
17305 {
17306+ pax_open_kernel();
17307 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
17308+ pax_close_kernel();
17309 }
17310
17311 static inline void native_load_gdt(const struct desc_ptr *dtr)
17312@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
17313 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
17314 unsigned int i;
17315
17316+ pax_open_kernel();
17317 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
17318 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
17319+ pax_close_kernel();
17320 }
17321
17322 #define _LDT_empty(info) \
17323@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
17324 preempt_enable();
17325 }
17326
17327-static inline unsigned long get_desc_base(const struct desc_struct *desc)
17328+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
17329 {
17330 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
17331 }
17332@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
17333 }
17334
17335 #ifdef CONFIG_X86_64
17336-static inline void set_nmi_gate(int gate, void *addr)
17337+static inline void set_nmi_gate(int gate, const void *addr)
17338 {
17339 gate_desc s;
17340
17341@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
17342 #endif
17343
17344 #ifdef CONFIG_TRACING
17345-extern struct desc_ptr trace_idt_descr;
17346-extern gate_desc trace_idt_table[];
17347+extern const struct desc_ptr trace_idt_descr;
17348+extern gate_desc trace_idt_table[IDT_ENTRIES];
17349 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
17350 {
17351 write_idt_entry(trace_idt_table, entry, gate);
17352 }
17353
17354-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
17355+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
17356 unsigned dpl, unsigned ist, unsigned seg)
17357 {
17358 gate_desc s;
17359@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
17360 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
17361 #endif
17362
17363-static inline void _set_gate(int gate, unsigned type, void *addr,
17364+static inline void _set_gate(int gate, unsigned type, const void *addr,
17365 unsigned dpl, unsigned ist, unsigned seg)
17366 {
17367 gate_desc s;
17368@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
17369 #define set_intr_gate(n, addr) \
17370 do { \
17371 BUG_ON((unsigned)n > 0xFF); \
17372- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
17373+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
17374 __KERNEL_CS); \
17375- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
17376+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
17377 0, 0, __KERNEL_CS); \
17378 } while (0)
17379
17380@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
17381 /*
17382 * This routine sets up an interrupt gate at directory privilege level 3.
17383 */
17384-static inline void set_system_intr_gate(unsigned int n, void *addr)
17385+static inline void set_system_intr_gate(unsigned int n, const void *addr)
17386 {
17387 BUG_ON((unsigned)n > 0xFF);
17388 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
17389 }
17390
17391-static inline void set_system_trap_gate(unsigned int n, void *addr)
17392+static inline void set_system_trap_gate(unsigned int n, const void *addr)
17393 {
17394 BUG_ON((unsigned)n > 0xFF);
17395 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
17396 }
17397
17398-static inline void set_trap_gate(unsigned int n, void *addr)
17399+static inline void set_trap_gate(unsigned int n, const void *addr)
17400 {
17401 BUG_ON((unsigned)n > 0xFF);
17402 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
17403@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
17404 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
17405 {
17406 BUG_ON((unsigned)n > 0xFF);
17407- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
17408+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
17409 }
17410
17411-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
17412+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
17413 {
17414 BUG_ON((unsigned)n > 0xFF);
17415 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
17416 }
17417
17418-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
17419+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
17420 {
17421 BUG_ON((unsigned)n > 0xFF);
17422 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
17423@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
17424 else
17425 load_idt((const struct desc_ptr *)&idt_descr);
17426 }
17427+
17428+#ifdef CONFIG_X86_32
17429+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
17430+{
17431+ struct desc_struct d;
17432+
17433+ if (likely(limit))
17434+ limit = (limit - 1UL) >> PAGE_SHIFT;
17435+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
17436+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
17437+}
17438+#endif
17439+
17440 #endif /* _ASM_X86_DESC_H */
17441diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
17442index 278441f..b95a174 100644
17443--- a/arch/x86/include/asm/desc_defs.h
17444+++ b/arch/x86/include/asm/desc_defs.h
17445@@ -31,6 +31,12 @@ struct desc_struct {
17446 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
17447 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
17448 };
17449+ struct {
17450+ u16 offset_low;
17451+ u16 seg;
17452+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
17453+ unsigned offset_high: 16;
17454+ } gate;
17455 };
17456 } __attribute__((packed));
17457
17458diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
17459index ced283a..ffe04cc 100644
17460--- a/arch/x86/include/asm/div64.h
17461+++ b/arch/x86/include/asm/div64.h
17462@@ -39,7 +39,7 @@
17463 __mod; \
17464 })
17465
17466-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
17467+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
17468 {
17469 union {
17470 u64 v64;
17471diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
17472index ca3347a..1a5082a 100644
17473--- a/arch/x86/include/asm/elf.h
17474+++ b/arch/x86/include/asm/elf.h
17475@@ -75,9 +75,6 @@ typedef struct user_fxsr_struct elf_fpxregset_t;
17476
17477 #include <asm/vdso.h>
17478
17479-#ifdef CONFIG_X86_64
17480-extern unsigned int vdso64_enabled;
17481-#endif
17482 #if defined(CONFIG_X86_32) || defined(CONFIG_COMPAT)
17483 extern unsigned int vdso32_enabled;
17484 #endif
17485@@ -249,7 +246,25 @@ extern int force_personality32;
17486 the loader. We need to make sure that it is out of the way of the program
17487 that it will "exec", and that there is sufficient room for the brk. */
17488
17489+#ifdef CONFIG_PAX_SEGMEXEC
17490+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
17491+#else
17492 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
17493+#endif
17494+
17495+#ifdef CONFIG_PAX_ASLR
17496+#ifdef CONFIG_X86_32
17497+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
17498+
17499+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17500+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
17501+#else
17502+#define PAX_ELF_ET_DYN_BASE 0x400000UL
17503+
17504+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17505+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
17506+#endif
17507+#endif
17508
17509 /* This yields a mask that user programs can use to figure out what
17510 instruction set this CPU supports. This could be done in user space,
17511@@ -298,17 +313,13 @@ do { \
17512
17513 #define ARCH_DLINFO \
17514 do { \
17515- if (vdso64_enabled) \
17516- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17517- (unsigned long __force)current->mm->context.vdso); \
17518+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17519 } while (0)
17520
17521 /* As a historical oddity, the x32 and x86_64 vDSOs are controlled together. */
17522 #define ARCH_DLINFO_X32 \
17523 do { \
17524- if (vdso64_enabled) \
17525- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
17526- (unsigned long __force)current->mm->context.vdso); \
17527+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
17528 } while (0)
17529
17530 #define AT_SYSINFO 32
17531@@ -323,10 +334,10 @@ else \
17532
17533 #endif /* !CONFIG_X86_32 */
17534
17535-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
17536+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
17537
17538 #define VDSO_ENTRY \
17539- ((unsigned long)current->mm->context.vdso + \
17540+ (current->mm->context.vdso + \
17541 selected_vdso32->sym___kernel_vsyscall)
17542
17543 struct linux_binprm;
17544@@ -338,9 +349,6 @@ extern int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
17545 int uses_interp);
17546 #define compat_arch_setup_additional_pages compat_arch_setup_additional_pages
17547
17548-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
17549-#define arch_randomize_brk arch_randomize_brk
17550-
17551 /*
17552 * True on X86_32 or when emulating IA32 on X86_64
17553 */
17554diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
17555index 77a99ac..39ff7f5 100644
17556--- a/arch/x86/include/asm/emergency-restart.h
17557+++ b/arch/x86/include/asm/emergency-restart.h
17558@@ -1,6 +1,6 @@
17559 #ifndef _ASM_X86_EMERGENCY_RESTART_H
17560 #define _ASM_X86_EMERGENCY_RESTART_H
17561
17562-extern void machine_emergency_restart(void);
17563+extern void machine_emergency_restart(void) __noreturn;
17564
17565 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
17566diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
17567index 1c7eefe..d0e4702 100644
17568--- a/arch/x86/include/asm/floppy.h
17569+++ b/arch/x86/include/asm/floppy.h
17570@@ -229,18 +229,18 @@ static struct fd_routine_l {
17571 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
17572 } fd_routine[] = {
17573 {
17574- request_dma,
17575- free_dma,
17576- get_dma_residue,
17577- dma_mem_alloc,
17578- hard_dma_setup
17579+ ._request_dma = request_dma,
17580+ ._free_dma = free_dma,
17581+ ._get_dma_residue = get_dma_residue,
17582+ ._dma_mem_alloc = dma_mem_alloc,
17583+ ._dma_setup = hard_dma_setup
17584 },
17585 {
17586- vdma_request_dma,
17587- vdma_nop,
17588- vdma_get_dma_residue,
17589- vdma_mem_alloc,
17590- vdma_dma_setup
17591+ ._request_dma = vdma_request_dma,
17592+ ._free_dma = vdma_nop,
17593+ ._get_dma_residue = vdma_get_dma_residue,
17594+ ._dma_mem_alloc = vdma_mem_alloc,
17595+ ._dma_setup = vdma_dma_setup
17596 }
17597 };
17598
17599diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
17600index 412ecec..c1ea43a 100644
17601--- a/arch/x86/include/asm/fpu-internal.h
17602+++ b/arch/x86/include/asm/fpu-internal.h
17603@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17604 #define user_insn(insn, output, input...) \
17605 ({ \
17606 int err; \
17607+ pax_open_userland(); \
17608 asm volatile(ASM_STAC "\n" \
17609- "1:" #insn "\n\t" \
17610+ "1:" \
17611+ __copyuser_seg \
17612+ #insn "\n\t" \
17613 "2: " ASM_CLAC "\n" \
17614 ".section .fixup,\"ax\"\n" \
17615 "3: movl $-1,%[err]\n" \
17616@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
17617 _ASM_EXTABLE(1b, 3b) \
17618 : [err] "=r" (err), output \
17619 : "0"(0), input); \
17620+ pax_close_userland(); \
17621 err; \
17622 })
17623
17624@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
17625 "fnclex\n\t"
17626 "emms\n\t"
17627 "fildl %P[addr]" /* set F?P to defined value */
17628- : : [addr] "m" (tsk->thread.fpu.has_fpu));
17629+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
17630 }
17631
17632 return fpu_restore_checking(&tsk->thread.fpu);
17633diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
17634index b4c1f54..e290c08 100644
17635--- a/arch/x86/include/asm/futex.h
17636+++ b/arch/x86/include/asm/futex.h
17637@@ -12,6 +12,7 @@
17638 #include <asm/smap.h>
17639
17640 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
17641+ typecheck(u32 __user *, uaddr); \
17642 asm volatile("\t" ASM_STAC "\n" \
17643 "1:\t" insn "\n" \
17644 "2:\t" ASM_CLAC "\n" \
17645@@ -20,15 +21,16 @@
17646 "\tjmp\t2b\n" \
17647 "\t.previous\n" \
17648 _ASM_EXTABLE(1b, 3b) \
17649- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
17650+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
17651 : "i" (-EFAULT), "0" (oparg), "1" (0))
17652
17653 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
17654+ typecheck(u32 __user *, uaddr); \
17655 asm volatile("\t" ASM_STAC "\n" \
17656 "1:\tmovl %2, %0\n" \
17657 "\tmovl\t%0, %3\n" \
17658 "\t" insn "\n" \
17659- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
17660+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
17661 "\tjnz\t1b\n" \
17662 "3:\t" ASM_CLAC "\n" \
17663 "\t.section .fixup,\"ax\"\n" \
17664@@ -38,7 +40,7 @@
17665 _ASM_EXTABLE(1b, 4b) \
17666 _ASM_EXTABLE(2b, 4b) \
17667 : "=&a" (oldval), "=&r" (ret), \
17668- "+m" (*uaddr), "=&r" (tem) \
17669+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
17670 : "r" (oparg), "i" (-EFAULT), "1" (0))
17671
17672 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17673@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17674
17675 pagefault_disable();
17676
17677+ pax_open_userland();
17678 switch (op) {
17679 case FUTEX_OP_SET:
17680- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
17681+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
17682 break;
17683 case FUTEX_OP_ADD:
17684- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
17685+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
17686 uaddr, oparg);
17687 break;
17688 case FUTEX_OP_OR:
17689@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
17690 default:
17691 ret = -ENOSYS;
17692 }
17693+ pax_close_userland();
17694
17695 pagefault_enable();
17696
17697diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
17698index 4615906..788c817 100644
17699--- a/arch/x86/include/asm/hw_irq.h
17700+++ b/arch/x86/include/asm/hw_irq.h
17701@@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
17702 extern void enable_IO_APIC(void);
17703
17704 /* Statistics */
17705-extern atomic_t irq_err_count;
17706-extern atomic_t irq_mis_count;
17707+extern atomic_unchecked_t irq_err_count;
17708+extern atomic_unchecked_t irq_mis_count;
17709
17710 /* EISA */
17711 extern void eisa_set_level_irq(unsigned int irq);
17712diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
17713index ccffa53..3c90c87 100644
17714--- a/arch/x86/include/asm/i8259.h
17715+++ b/arch/x86/include/asm/i8259.h
17716@@ -62,7 +62,7 @@ struct legacy_pic {
17717 void (*init)(int auto_eoi);
17718 int (*irq_pending)(unsigned int irq);
17719 void (*make_irq)(unsigned int irq);
17720-};
17721+} __do_const;
17722
17723 extern struct legacy_pic *legacy_pic;
17724 extern struct legacy_pic null_legacy_pic;
17725diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
17726index b8237d8..3e8864e 100644
17727--- a/arch/x86/include/asm/io.h
17728+++ b/arch/x86/include/asm/io.h
17729@@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
17730 "m" (*(volatile type __force *)addr) barrier); }
17731
17732 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
17733-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
17734-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
17735+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
17736+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
17737
17738 build_mmio_read(__readb, "b", unsigned char, "=q", )
17739-build_mmio_read(__readw, "w", unsigned short, "=r", )
17740-build_mmio_read(__readl, "l", unsigned int, "=r", )
17741+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
17742+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
17743
17744 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
17745 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
17746@@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
17747 * this function
17748 */
17749
17750-static inline phys_addr_t virt_to_phys(volatile void *address)
17751+static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
17752 {
17753 return __pa(address);
17754 }
17755@@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
17756 return ioremap_nocache(offset, size);
17757 }
17758
17759-extern void iounmap(volatile void __iomem *addr);
17760+extern void iounmap(const volatile void __iomem *addr);
17761
17762 extern void set_iounmap_nonlazy(void);
17763
17764@@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
17765
17766 #include <linux/vmalloc.h>
17767
17768+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
17769+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
17770+{
17771+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17772+}
17773+
17774+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
17775+{
17776+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
17777+}
17778+
17779 /*
17780 * Convert a virtual cached pointer to an uncached pointer
17781 */
17782diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
17783index 0a8b519..80e7d5b 100644
17784--- a/arch/x86/include/asm/irqflags.h
17785+++ b/arch/x86/include/asm/irqflags.h
17786@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
17787 sti; \
17788 sysexit
17789
17790+#define GET_CR0_INTO_RDI mov %cr0, %rdi
17791+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
17792+#define GET_CR3_INTO_RDI mov %cr3, %rdi
17793+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
17794+
17795 #else
17796 #define INTERRUPT_RETURN iret
17797 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
17798diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
17799index 53cdfb2..d1369e6 100644
17800--- a/arch/x86/include/asm/kprobes.h
17801+++ b/arch/x86/include/asm/kprobes.h
17802@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
17803 #define RELATIVEJUMP_SIZE 5
17804 #define RELATIVECALL_OPCODE 0xe8
17805 #define RELATIVE_ADDR_SIZE 4
17806-#define MAX_STACK_SIZE 64
17807-#define MIN_STACK_SIZE(ADDR) \
17808- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
17809- THREAD_SIZE - (unsigned long)(ADDR))) \
17810- ? (MAX_STACK_SIZE) \
17811- : (((unsigned long)current_thread_info()) + \
17812- THREAD_SIZE - (unsigned long)(ADDR)))
17813+#define MAX_STACK_SIZE 64UL
17814+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
17815
17816 #define flush_insn_slot(p) do { } while (0)
17817
17818diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
17819index 4ad6560..75c7bdd 100644
17820--- a/arch/x86/include/asm/local.h
17821+++ b/arch/x86/include/asm/local.h
17822@@ -10,33 +10,97 @@ typedef struct {
17823 atomic_long_t a;
17824 } local_t;
17825
17826+typedef struct {
17827+ atomic_long_unchecked_t a;
17828+} local_unchecked_t;
17829+
17830 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
17831
17832 #define local_read(l) atomic_long_read(&(l)->a)
17833+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
17834 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
17835+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
17836
17837 static inline void local_inc(local_t *l)
17838 {
17839- asm volatile(_ASM_INC "%0"
17840+ asm volatile(_ASM_INC "%0\n"
17841+
17842+#ifdef CONFIG_PAX_REFCOUNT
17843+ "jno 0f\n"
17844+ _ASM_DEC "%0\n"
17845+ "int $4\n0:\n"
17846+ _ASM_EXTABLE(0b, 0b)
17847+#endif
17848+
17849+ : "+m" (l->a.counter));
17850+}
17851+
17852+static inline void local_inc_unchecked(local_unchecked_t *l)
17853+{
17854+ asm volatile(_ASM_INC "%0\n"
17855 : "+m" (l->a.counter));
17856 }
17857
17858 static inline void local_dec(local_t *l)
17859 {
17860- asm volatile(_ASM_DEC "%0"
17861+ asm volatile(_ASM_DEC "%0\n"
17862+
17863+#ifdef CONFIG_PAX_REFCOUNT
17864+ "jno 0f\n"
17865+ _ASM_INC "%0\n"
17866+ "int $4\n0:\n"
17867+ _ASM_EXTABLE(0b, 0b)
17868+#endif
17869+
17870+ : "+m" (l->a.counter));
17871+}
17872+
17873+static inline void local_dec_unchecked(local_unchecked_t *l)
17874+{
17875+ asm volatile(_ASM_DEC "%0\n"
17876 : "+m" (l->a.counter));
17877 }
17878
17879 static inline void local_add(long i, local_t *l)
17880 {
17881- asm volatile(_ASM_ADD "%1,%0"
17882+ asm volatile(_ASM_ADD "%1,%0\n"
17883+
17884+#ifdef CONFIG_PAX_REFCOUNT
17885+ "jno 0f\n"
17886+ _ASM_SUB "%1,%0\n"
17887+ "int $4\n0:\n"
17888+ _ASM_EXTABLE(0b, 0b)
17889+#endif
17890+
17891+ : "+m" (l->a.counter)
17892+ : "ir" (i));
17893+}
17894+
17895+static inline void local_add_unchecked(long i, local_unchecked_t *l)
17896+{
17897+ asm volatile(_ASM_ADD "%1,%0\n"
17898 : "+m" (l->a.counter)
17899 : "ir" (i));
17900 }
17901
17902 static inline void local_sub(long i, local_t *l)
17903 {
17904- asm volatile(_ASM_SUB "%1,%0"
17905+ asm volatile(_ASM_SUB "%1,%0\n"
17906+
17907+#ifdef CONFIG_PAX_REFCOUNT
17908+ "jno 0f\n"
17909+ _ASM_ADD "%1,%0\n"
17910+ "int $4\n0:\n"
17911+ _ASM_EXTABLE(0b, 0b)
17912+#endif
17913+
17914+ : "+m" (l->a.counter)
17915+ : "ir" (i));
17916+}
17917+
17918+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
17919+{
17920+ asm volatile(_ASM_SUB "%1,%0\n"
17921 : "+m" (l->a.counter)
17922 : "ir" (i));
17923 }
17924@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
17925 */
17926 static inline int local_sub_and_test(long i, local_t *l)
17927 {
17928- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
17929+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
17930 }
17931
17932 /**
17933@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
17934 */
17935 static inline int local_dec_and_test(local_t *l)
17936 {
17937- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
17938+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
17939 }
17940
17941 /**
17942@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
17943 */
17944 static inline int local_inc_and_test(local_t *l)
17945 {
17946- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
17947+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
17948 }
17949
17950 /**
17951@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
17952 */
17953 static inline int local_add_negative(long i, local_t *l)
17954 {
17955- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
17956+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
17957 }
17958
17959 /**
17960@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
17961 static inline long local_add_return(long i, local_t *l)
17962 {
17963 long __i = i;
17964+ asm volatile(_ASM_XADD "%0, %1\n"
17965+
17966+#ifdef CONFIG_PAX_REFCOUNT
17967+ "jno 0f\n"
17968+ _ASM_MOV "%0,%1\n"
17969+ "int $4\n0:\n"
17970+ _ASM_EXTABLE(0b, 0b)
17971+#endif
17972+
17973+ : "+r" (i), "+m" (l->a.counter)
17974+ : : "memory");
17975+ return i + __i;
17976+}
17977+
17978+/**
17979+ * local_add_return_unchecked - add and return
17980+ * @i: integer value to add
17981+ * @l: pointer to type local_unchecked_t
17982+ *
17983+ * Atomically adds @i to @l and returns @i + @l
17984+ */
17985+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17986+{
17987+ long __i = i;
17988 asm volatile(_ASM_XADD "%0, %1;"
17989 : "+r" (i), "+m" (l->a.counter)
17990 : : "memory");
17991@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17992
17993 #define local_cmpxchg(l, o, n) \
17994 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17995+#define local_cmpxchg_unchecked(l, o, n) \
17996+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
17997 /* Always has a lock prefix */
17998 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17999
18000diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
18001new file mode 100644
18002index 0000000..2bfd3ba
18003--- /dev/null
18004+++ b/arch/x86/include/asm/mman.h
18005@@ -0,0 +1,15 @@
18006+#ifndef _X86_MMAN_H
18007+#define _X86_MMAN_H
18008+
18009+#include <uapi/asm/mman.h>
18010+
18011+#ifdef __KERNEL__
18012+#ifndef __ASSEMBLY__
18013+#ifdef CONFIG_X86_32
18014+#define arch_mmap_check i386_mmap_check
18015+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
18016+#endif
18017+#endif
18018+#endif
18019+
18020+#endif /* X86_MMAN_H */
18021diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
18022index 876e74e..e20bfb1 100644
18023--- a/arch/x86/include/asm/mmu.h
18024+++ b/arch/x86/include/asm/mmu.h
18025@@ -9,7 +9,7 @@
18026 * we put the segment information here.
18027 */
18028 typedef struct {
18029- void *ldt;
18030+ struct desc_struct *ldt;
18031 int size;
18032
18033 #ifdef CONFIG_X86_64
18034@@ -18,7 +18,19 @@ typedef struct {
18035 #endif
18036
18037 struct mutex lock;
18038- void __user *vdso;
18039+ unsigned long vdso;
18040+
18041+#ifdef CONFIG_X86_32
18042+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18043+ unsigned long user_cs_base;
18044+ unsigned long user_cs_limit;
18045+
18046+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18047+ cpumask_t cpu_user_cs_mask;
18048+#endif
18049+
18050+#endif
18051+#endif
18052 } mm_context_t;
18053
18054 #ifdef CONFIG_SMP
18055diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
18056index 166af2a..648c200 100644
18057--- a/arch/x86/include/asm/mmu_context.h
18058+++ b/arch/x86/include/asm/mmu_context.h
18059@@ -28,6 +28,20 @@ void destroy_context(struct mm_struct *mm);
18060
18061 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
18062 {
18063+
18064+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18065+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
18066+ unsigned int i;
18067+ pgd_t *pgd;
18068+
18069+ pax_open_kernel();
18070+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
18071+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
18072+ set_pgd_batched(pgd+i, native_make_pgd(0));
18073+ pax_close_kernel();
18074+ }
18075+#endif
18076+
18077 #ifdef CONFIG_SMP
18078 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
18079 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
18080@@ -38,16 +52,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
18081 struct task_struct *tsk)
18082 {
18083 unsigned cpu = smp_processor_id();
18084+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18085+ int tlbstate = TLBSTATE_OK;
18086+#endif
18087
18088 if (likely(prev != next)) {
18089 #ifdef CONFIG_SMP
18090+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18091+ tlbstate = this_cpu_read(cpu_tlbstate.state);
18092+#endif
18093 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
18094 this_cpu_write(cpu_tlbstate.active_mm, next);
18095 #endif
18096 cpumask_set_cpu(cpu, mm_cpumask(next));
18097
18098 /* Re-load page tables */
18099+#ifdef CONFIG_PAX_PER_CPU_PGD
18100+ pax_open_kernel();
18101+
18102+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18103+ if (static_cpu_has(X86_FEATURE_PCID))
18104+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
18105+ else
18106+#endif
18107+
18108+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
18109+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
18110+ pax_close_kernel();
18111+ 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));
18112+
18113+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18114+ if (static_cpu_has(X86_FEATURE_PCID)) {
18115+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18116+ u64 descriptor[2];
18117+ descriptor[0] = PCID_USER;
18118+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18119+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
18120+ descriptor[0] = PCID_KERNEL;
18121+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18122+ }
18123+ } else {
18124+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18125+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
18126+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18127+ else
18128+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18129+ }
18130+ } else
18131+#endif
18132+
18133+ load_cr3(get_cpu_pgd(cpu, kernel));
18134+#else
18135 load_cr3(next->pgd);
18136+#endif
18137 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
18138
18139 /* Stop flush ipis for the previous mm */
18140@@ -56,9 +113,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
18141 /* Load the LDT, if the LDT is different: */
18142 if (unlikely(prev->context.ldt != next->context.ldt))
18143 load_LDT_nolock(&next->context);
18144+
18145+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18146+ if (!(__supported_pte_mask & _PAGE_NX)) {
18147+ smp_mb__before_atomic();
18148+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
18149+ smp_mb__after_atomic();
18150+ cpu_set(cpu, next->context.cpu_user_cs_mask);
18151+ }
18152+#endif
18153+
18154+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18155+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
18156+ prev->context.user_cs_limit != next->context.user_cs_limit))
18157+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
18158+#ifdef CONFIG_SMP
18159+ else if (unlikely(tlbstate != TLBSTATE_OK))
18160+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
18161+#endif
18162+#endif
18163+
18164 }
18165+ else {
18166+
18167+#ifdef CONFIG_PAX_PER_CPU_PGD
18168+ pax_open_kernel();
18169+
18170+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18171+ if (static_cpu_has(X86_FEATURE_PCID))
18172+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
18173+ else
18174+#endif
18175+
18176+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
18177+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
18178+ pax_close_kernel();
18179+ 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));
18180+
18181+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18182+ if (static_cpu_has(X86_FEATURE_PCID)) {
18183+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
18184+ u64 descriptor[2];
18185+ descriptor[0] = PCID_USER;
18186+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18187+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
18188+ descriptor[0] = PCID_KERNEL;
18189+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
18190+ }
18191+ } else {
18192+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18193+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
18194+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18195+ else
18196+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18197+ }
18198+ } else
18199+#endif
18200+
18201+ load_cr3(get_cpu_pgd(cpu, kernel));
18202+#endif
18203+
18204 #ifdef CONFIG_SMP
18205- else {
18206 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
18207 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
18208
18209@@ -75,12 +190,29 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
18210 * tlb flush IPI delivery. We must reload CR3
18211 * to make sure to use no freed page tables.
18212 */
18213+
18214+#ifndef CONFIG_PAX_PER_CPU_PGD
18215 load_cr3(next->pgd);
18216 trace_tlb_flush(TLB_FLUSH_ON_TASK_SWITCH, TLB_FLUSH_ALL);
18217+#endif
18218+
18219 load_LDT_nolock(&next->context);
18220+
18221+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
18222+ if (!(__supported_pte_mask & _PAGE_NX))
18223+ cpu_set(cpu, next->context.cpu_user_cs_mask);
18224+#endif
18225+
18226+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
18227+#ifdef CONFIG_PAX_PAGEEXEC
18228+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
18229+#endif
18230+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
18231+#endif
18232+
18233 }
18234+#endif
18235 }
18236-#endif
18237 }
18238
18239 #define activate_mm(prev, next) \
18240diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
18241index e3b7819..b257c64 100644
18242--- a/arch/x86/include/asm/module.h
18243+++ b/arch/x86/include/asm/module.h
18244@@ -5,6 +5,7 @@
18245
18246 #ifdef CONFIG_X86_64
18247 /* X86_64 does not define MODULE_PROC_FAMILY */
18248+#define MODULE_PROC_FAMILY ""
18249 #elif defined CONFIG_M486
18250 #define MODULE_PROC_FAMILY "486 "
18251 #elif defined CONFIG_M586
18252@@ -57,8 +58,20 @@
18253 #error unknown processor family
18254 #endif
18255
18256-#ifdef CONFIG_X86_32
18257-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
18258+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
18259+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
18260+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
18261+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
18262+#else
18263+#define MODULE_PAX_KERNEXEC ""
18264 #endif
18265
18266+#ifdef CONFIG_PAX_MEMORY_UDEREF
18267+#define MODULE_PAX_UDEREF "UDEREF "
18268+#else
18269+#define MODULE_PAX_UDEREF ""
18270+#endif
18271+
18272+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
18273+
18274 #endif /* _ASM_X86_MODULE_H */
18275diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
18276index 5f2fc44..106caa6 100644
18277--- a/arch/x86/include/asm/nmi.h
18278+++ b/arch/x86/include/asm/nmi.h
18279@@ -36,26 +36,35 @@ enum {
18280
18281 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
18282
18283+struct nmiaction;
18284+
18285+struct nmiwork {
18286+ const struct nmiaction *action;
18287+ u64 max_duration;
18288+ struct irq_work irq_work;
18289+};
18290+
18291 struct nmiaction {
18292 struct list_head list;
18293 nmi_handler_t handler;
18294- u64 max_duration;
18295- struct irq_work irq_work;
18296 unsigned long flags;
18297 const char *name;
18298-};
18299+ struct nmiwork *work;
18300+} __do_const;
18301
18302 #define register_nmi_handler(t, fn, fg, n, init...) \
18303 ({ \
18304- static struct nmiaction init fn##_na = { \
18305+ static struct nmiwork fn##_nw; \
18306+ static const struct nmiaction init fn##_na = { \
18307 .handler = (fn), \
18308 .name = (n), \
18309 .flags = (fg), \
18310+ .work = &fn##_nw, \
18311 }; \
18312 __register_nmi_handler((t), &fn##_na); \
18313 })
18314
18315-int __register_nmi_handler(unsigned int, struct nmiaction *);
18316+int __register_nmi_handler(unsigned int, const struct nmiaction *);
18317
18318 void unregister_nmi_handler(unsigned int, const char *);
18319
18320diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
18321index 802dde3..9183e68 100644
18322--- a/arch/x86/include/asm/page.h
18323+++ b/arch/x86/include/asm/page.h
18324@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
18325 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
18326
18327 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
18328+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
18329
18330 #define __boot_va(x) __va(x)
18331 #define __boot_pa(x) __pa(x)
18332@@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
18333 * virt_to_page(kaddr) returns a valid pointer if and only if
18334 * virt_addr_valid(kaddr) returns true.
18335 */
18336-#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
18337 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
18338 extern bool __virt_addr_valid(unsigned long kaddr);
18339 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
18340
18341+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
18342+#define virt_to_page(kaddr) \
18343+ ({ \
18344+ const void *__kaddr = (const void *)(kaddr); \
18345+ BUG_ON(!virt_addr_valid(__kaddr)); \
18346+ pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
18347+ })
18348+#else
18349+#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
18350+#endif
18351+
18352 #endif /* __ASSEMBLY__ */
18353
18354 #include <asm-generic/memory_model.h>
18355diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
18356index f408caf..4a0455e 100644
18357--- a/arch/x86/include/asm/page_64.h
18358+++ b/arch/x86/include/asm/page_64.h
18359@@ -7,9 +7,9 @@
18360
18361 /* duplicated to the one in bootmem.h */
18362 extern unsigned long max_pfn;
18363-extern unsigned long phys_base;
18364+extern const unsigned long phys_base;
18365
18366-static inline unsigned long __phys_addr_nodebug(unsigned long x)
18367+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
18368 {
18369 unsigned long y = x - __START_KERNEL_map;
18370
18371diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
18372index cd6e1610..70f4418 100644
18373--- a/arch/x86/include/asm/paravirt.h
18374+++ b/arch/x86/include/asm/paravirt.h
18375@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
18376 return (pmd_t) { ret };
18377 }
18378
18379-static inline pmdval_t pmd_val(pmd_t pmd)
18380+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
18381 {
18382 pmdval_t ret;
18383
18384@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
18385 val);
18386 }
18387
18388+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18389+{
18390+ pgdval_t val = native_pgd_val(pgd);
18391+
18392+ if (sizeof(pgdval_t) > sizeof(long))
18393+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
18394+ val, (u64)val >> 32);
18395+ else
18396+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
18397+ val);
18398+}
18399+
18400 static inline void pgd_clear(pgd_t *pgdp)
18401 {
18402 set_pgd(pgdp, __pgd(0));
18403@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
18404 pv_mmu_ops.set_fixmap(idx, phys, flags);
18405 }
18406
18407+#ifdef CONFIG_PAX_KERNEXEC
18408+static inline unsigned long pax_open_kernel(void)
18409+{
18410+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
18411+}
18412+
18413+static inline unsigned long pax_close_kernel(void)
18414+{
18415+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
18416+}
18417+#else
18418+static inline unsigned long pax_open_kernel(void) { return 0; }
18419+static inline unsigned long pax_close_kernel(void) { return 0; }
18420+#endif
18421+
18422 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
18423
18424 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
18425@@ -906,7 +933,7 @@ extern void default_banner(void);
18426
18427 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
18428 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
18429-#define PARA_INDIRECT(addr) *%cs:addr
18430+#define PARA_INDIRECT(addr) *%ss:addr
18431 #endif
18432
18433 #define INTERRUPT_RETURN \
18434@@ -981,6 +1008,21 @@ extern void default_banner(void);
18435 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
18436 CLBR_NONE, \
18437 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
18438+
18439+#define GET_CR0_INTO_RDI \
18440+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
18441+ mov %rax,%rdi
18442+
18443+#define SET_RDI_INTO_CR0 \
18444+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18445+
18446+#define GET_CR3_INTO_RDI \
18447+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
18448+ mov %rax,%rdi
18449+
18450+#define SET_RDI_INTO_CR3 \
18451+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
18452+
18453 #endif /* CONFIG_X86_32 */
18454
18455 #endif /* __ASSEMBLY__ */
18456diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
18457index 7549b8b..f0edfda 100644
18458--- a/arch/x86/include/asm/paravirt_types.h
18459+++ b/arch/x86/include/asm/paravirt_types.h
18460@@ -84,7 +84,7 @@ struct pv_init_ops {
18461 */
18462 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
18463 unsigned long addr, unsigned len);
18464-};
18465+} __no_const __no_randomize_layout;
18466
18467
18468 struct pv_lazy_ops {
18469@@ -92,13 +92,13 @@ struct pv_lazy_ops {
18470 void (*enter)(void);
18471 void (*leave)(void);
18472 void (*flush)(void);
18473-};
18474+} __no_randomize_layout;
18475
18476 struct pv_time_ops {
18477 unsigned long long (*sched_clock)(void);
18478 unsigned long long (*steal_clock)(int cpu);
18479 unsigned long (*get_tsc_khz)(void);
18480-};
18481+} __no_const __no_randomize_layout;
18482
18483 struct pv_cpu_ops {
18484 /* hooks for various privileged instructions */
18485@@ -192,7 +192,7 @@ struct pv_cpu_ops {
18486
18487 void (*start_context_switch)(struct task_struct *prev);
18488 void (*end_context_switch)(struct task_struct *next);
18489-};
18490+} __no_const __no_randomize_layout;
18491
18492 struct pv_irq_ops {
18493 /*
18494@@ -215,7 +215,7 @@ struct pv_irq_ops {
18495 #ifdef CONFIG_X86_64
18496 void (*adjust_exception_frame)(void);
18497 #endif
18498-};
18499+} __no_randomize_layout;
18500
18501 struct pv_apic_ops {
18502 #ifdef CONFIG_X86_LOCAL_APIC
18503@@ -223,7 +223,7 @@ struct pv_apic_ops {
18504 unsigned long start_eip,
18505 unsigned long start_esp);
18506 #endif
18507-};
18508+} __no_const __no_randomize_layout;
18509
18510 struct pv_mmu_ops {
18511 unsigned long (*read_cr2)(void);
18512@@ -313,6 +313,7 @@ struct pv_mmu_ops {
18513 struct paravirt_callee_save make_pud;
18514
18515 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
18516+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
18517 #endif /* PAGETABLE_LEVELS == 4 */
18518 #endif /* PAGETABLE_LEVELS >= 3 */
18519
18520@@ -324,7 +325,13 @@ struct pv_mmu_ops {
18521 an mfn. We can tell which is which from the index. */
18522 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
18523 phys_addr_t phys, pgprot_t flags);
18524-};
18525+
18526+#ifdef CONFIG_PAX_KERNEXEC
18527+ unsigned long (*pax_open_kernel)(void);
18528+ unsigned long (*pax_close_kernel)(void);
18529+#endif
18530+
18531+} __no_randomize_layout;
18532
18533 struct arch_spinlock;
18534 #ifdef CONFIG_SMP
18535@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
18536 struct pv_lock_ops {
18537 struct paravirt_callee_save lock_spinning;
18538 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
18539-};
18540+} __no_randomize_layout;
18541
18542 /* This contains all the paravirt structures: we get a convenient
18543 * number for each function using the offset which we use to indicate
18544- * what to patch. */
18545+ * what to patch.
18546+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
18547+ */
18548+
18549 struct paravirt_patch_template {
18550 struct pv_init_ops pv_init_ops;
18551 struct pv_time_ops pv_time_ops;
18552@@ -349,7 +359,7 @@ struct paravirt_patch_template {
18553 struct pv_apic_ops pv_apic_ops;
18554 struct pv_mmu_ops pv_mmu_ops;
18555 struct pv_lock_ops pv_lock_ops;
18556-};
18557+} __no_randomize_layout;
18558
18559 extern struct pv_info pv_info;
18560 extern struct pv_init_ops pv_init_ops;
18561diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
18562index c4412e9..90e88c5 100644
18563--- a/arch/x86/include/asm/pgalloc.h
18564+++ b/arch/x86/include/asm/pgalloc.h
18565@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
18566 pmd_t *pmd, pte_t *pte)
18567 {
18568 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18569+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
18570+}
18571+
18572+static inline void pmd_populate_user(struct mm_struct *mm,
18573+ pmd_t *pmd, pte_t *pte)
18574+{
18575+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
18576 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
18577 }
18578
18579@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
18580
18581 #ifdef CONFIG_X86_PAE
18582 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
18583+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
18584+{
18585+ pud_populate(mm, pudp, pmd);
18586+}
18587 #else /* !CONFIG_X86_PAE */
18588 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18589 {
18590 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18591 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
18592 }
18593+
18594+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
18595+{
18596+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
18597+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
18598+}
18599 #endif /* CONFIG_X86_PAE */
18600
18601 #if PAGETABLE_LEVELS > 3
18602@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18603 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
18604 }
18605
18606+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
18607+{
18608+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
18609+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
18610+}
18611+
18612 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
18613 {
18614 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
18615diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
18616index 206a87f..1623b06 100644
18617--- a/arch/x86/include/asm/pgtable-2level.h
18618+++ b/arch/x86/include/asm/pgtable-2level.h
18619@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
18620
18621 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18622 {
18623+ pax_open_kernel();
18624 *pmdp = pmd;
18625+ pax_close_kernel();
18626 }
18627
18628 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18629diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
18630index 81bb91b..9392125 100644
18631--- a/arch/x86/include/asm/pgtable-3level.h
18632+++ b/arch/x86/include/asm/pgtable-3level.h
18633@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18634
18635 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18636 {
18637+ pax_open_kernel();
18638 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
18639+ pax_close_kernel();
18640 }
18641
18642 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18643 {
18644+ pax_open_kernel();
18645 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
18646+ pax_close_kernel();
18647 }
18648
18649 /*
18650diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
18651index aa97a07..5c53c32 100644
18652--- a/arch/x86/include/asm/pgtable.h
18653+++ b/arch/x86/include/asm/pgtable.h
18654@@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18655
18656 #ifndef __PAGETABLE_PUD_FOLDED
18657 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
18658+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
18659 #define pgd_clear(pgd) native_pgd_clear(pgd)
18660 #endif
18661
18662@@ -83,12 +84,53 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
18663
18664 #define arch_end_context_switch(prev) do {} while(0)
18665
18666+#define pax_open_kernel() native_pax_open_kernel()
18667+#define pax_close_kernel() native_pax_close_kernel()
18668 #endif /* CONFIG_PARAVIRT */
18669
18670+#define __HAVE_ARCH_PAX_OPEN_KERNEL
18671+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
18672+
18673+#ifdef CONFIG_PAX_KERNEXEC
18674+static inline unsigned long native_pax_open_kernel(void)
18675+{
18676+ unsigned long cr0;
18677+
18678+ preempt_disable();
18679+ barrier();
18680+ cr0 = read_cr0() ^ X86_CR0_WP;
18681+ BUG_ON(cr0 & X86_CR0_WP);
18682+ write_cr0(cr0);
18683+ barrier();
18684+ return cr0 ^ X86_CR0_WP;
18685+}
18686+
18687+static inline unsigned long native_pax_close_kernel(void)
18688+{
18689+ unsigned long cr0;
18690+
18691+ barrier();
18692+ cr0 = read_cr0() ^ X86_CR0_WP;
18693+ BUG_ON(!(cr0 & X86_CR0_WP));
18694+ write_cr0(cr0);
18695+ barrier();
18696+ preempt_enable_no_resched();
18697+ return cr0 ^ X86_CR0_WP;
18698+}
18699+#else
18700+static inline unsigned long native_pax_open_kernel(void) { return 0; }
18701+static inline unsigned long native_pax_close_kernel(void) { return 0; }
18702+#endif
18703+
18704 /*
18705 * The following only work if pte_present() is true.
18706 * Undefined behaviour if not..
18707 */
18708+static inline int pte_user(pte_t pte)
18709+{
18710+ return pte_val(pte) & _PAGE_USER;
18711+}
18712+
18713 static inline int pte_dirty(pte_t pte)
18714 {
18715 return pte_flags(pte) & _PAGE_DIRTY;
18716@@ -155,6 +197,11 @@ static inline unsigned long pud_pfn(pud_t pud)
18717 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
18718 }
18719
18720+static inline unsigned long pgd_pfn(pgd_t pgd)
18721+{
18722+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
18723+}
18724+
18725 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
18726
18727 static inline int pmd_large(pmd_t pte)
18728@@ -208,9 +255,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
18729 return pte_clear_flags(pte, _PAGE_RW);
18730 }
18731
18732+static inline pte_t pte_mkread(pte_t pte)
18733+{
18734+ return __pte(pte_val(pte) | _PAGE_USER);
18735+}
18736+
18737 static inline pte_t pte_mkexec(pte_t pte)
18738 {
18739- return pte_clear_flags(pte, _PAGE_NX);
18740+#ifdef CONFIG_X86_PAE
18741+ if (__supported_pte_mask & _PAGE_NX)
18742+ return pte_clear_flags(pte, _PAGE_NX);
18743+ else
18744+#endif
18745+ return pte_set_flags(pte, _PAGE_USER);
18746+}
18747+
18748+static inline pte_t pte_exprotect(pte_t pte)
18749+{
18750+#ifdef CONFIG_X86_PAE
18751+ if (__supported_pte_mask & _PAGE_NX)
18752+ return pte_set_flags(pte, _PAGE_NX);
18753+ else
18754+#endif
18755+ return pte_clear_flags(pte, _PAGE_USER);
18756 }
18757
18758 static inline pte_t pte_mkdirty(pte_t pte)
18759@@ -440,6 +507,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
18760 #endif
18761
18762 #ifndef __ASSEMBLY__
18763+
18764+#ifdef CONFIG_PAX_PER_CPU_PGD
18765+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
18766+enum cpu_pgd_type {kernel = 0, user = 1};
18767+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
18768+{
18769+ return cpu_pgd[cpu][type];
18770+}
18771+#endif
18772+
18773 #include <linux/mm_types.h>
18774 #include <linux/mmdebug.h>
18775 #include <linux/log2.h>
18776@@ -586,7 +663,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
18777 * Currently stuck as a macro due to indirect forward reference to
18778 * linux/mmzone.h's __section_mem_map_addr() definition:
18779 */
18780-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
18781+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
18782
18783 /* Find an entry in the second-level page table.. */
18784 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
18785@@ -626,7 +703,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
18786 * Currently stuck as a macro due to indirect forward reference to
18787 * linux/mmzone.h's __section_mem_map_addr() definition:
18788 */
18789-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
18790+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
18791
18792 /* to find an entry in a page-table-directory. */
18793 static inline unsigned long pud_index(unsigned long address)
18794@@ -641,7 +718,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
18795
18796 static inline int pgd_bad(pgd_t pgd)
18797 {
18798- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
18799+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
18800 }
18801
18802 static inline int pgd_none(pgd_t pgd)
18803@@ -664,7 +741,12 @@ static inline int pgd_none(pgd_t pgd)
18804 * pgd_offset() returns a (pgd_t *)
18805 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
18806 */
18807-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
18808+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
18809+
18810+#ifdef CONFIG_PAX_PER_CPU_PGD
18811+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
18812+#endif
18813+
18814 /*
18815 * a shortcut which implies the use of the kernel's pgd, instead
18816 * of a process's
18817@@ -675,6 +757,23 @@ static inline int pgd_none(pgd_t pgd)
18818 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
18819 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
18820
18821+#ifdef CONFIG_X86_32
18822+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
18823+#else
18824+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
18825+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
18826+
18827+#ifdef CONFIG_PAX_MEMORY_UDEREF
18828+#ifdef __ASSEMBLY__
18829+#define pax_user_shadow_base pax_user_shadow_base(%rip)
18830+#else
18831+extern unsigned long pax_user_shadow_base;
18832+extern pgdval_t clone_pgd_mask;
18833+#endif
18834+#endif
18835+
18836+#endif
18837+
18838 #ifndef __ASSEMBLY__
18839
18840 extern int direct_gbpages;
18841@@ -841,11 +940,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
18842 * dst and src can be on the same page, but the range must not overlap,
18843 * and must not cross a page boundary.
18844 */
18845-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
18846+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
18847 {
18848- memcpy(dst, src, count * sizeof(pgd_t));
18849+ pax_open_kernel();
18850+ while (count--)
18851+ *dst++ = *src++;
18852+ pax_close_kernel();
18853 }
18854
18855+#ifdef CONFIG_PAX_PER_CPU_PGD
18856+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
18857+#endif
18858+
18859+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18860+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
18861+#else
18862+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
18863+#endif
18864+
18865 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
18866 static inline int page_level_shift(enum pg_level level)
18867 {
18868diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
18869index 9ee3221..b979c6b 100644
18870--- a/arch/x86/include/asm/pgtable_32.h
18871+++ b/arch/x86/include/asm/pgtable_32.h
18872@@ -25,9 +25,6 @@
18873 struct mm_struct;
18874 struct vm_area_struct;
18875
18876-extern pgd_t swapper_pg_dir[1024];
18877-extern pgd_t initial_page_table[1024];
18878-
18879 static inline void pgtable_cache_init(void) { }
18880 static inline void check_pgt_cache(void) { }
18881 void paging_init(void);
18882@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18883 # include <asm/pgtable-2level.h>
18884 #endif
18885
18886+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
18887+extern pgd_t initial_page_table[PTRS_PER_PGD];
18888+#ifdef CONFIG_X86_PAE
18889+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
18890+#endif
18891+
18892 #if defined(CONFIG_HIGHPTE)
18893 #define pte_offset_map(dir, address) \
18894 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
18895@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
18896 /* Clear a kernel PTE and flush it from the TLB */
18897 #define kpte_clear_flush(ptep, vaddr) \
18898 do { \
18899+ pax_open_kernel(); \
18900 pte_clear(&init_mm, (vaddr), (ptep)); \
18901+ pax_close_kernel(); \
18902 __flush_tlb_one((vaddr)); \
18903 } while (0)
18904
18905 #endif /* !__ASSEMBLY__ */
18906
18907+#define HAVE_ARCH_UNMAPPED_AREA
18908+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
18909+
18910 /*
18911 * kern_addr_valid() is (1) for FLATMEM and (0) for
18912 * SPARSEMEM and DISCONTIGMEM
18913diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
18914index ed5903b..c7fe163 100644
18915--- a/arch/x86/include/asm/pgtable_32_types.h
18916+++ b/arch/x86/include/asm/pgtable_32_types.h
18917@@ -8,7 +8,7 @@
18918 */
18919 #ifdef CONFIG_X86_PAE
18920 # include <asm/pgtable-3level_types.h>
18921-# define PMD_SIZE (1UL << PMD_SHIFT)
18922+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
18923 # define PMD_MASK (~(PMD_SIZE - 1))
18924 #else
18925 # include <asm/pgtable-2level_types.h>
18926@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
18927 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
18928 #endif
18929
18930+#ifdef CONFIG_PAX_KERNEXEC
18931+#ifndef __ASSEMBLY__
18932+extern unsigned char MODULES_EXEC_VADDR[];
18933+extern unsigned char MODULES_EXEC_END[];
18934+#endif
18935+#include <asm/boot.h>
18936+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
18937+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
18938+#else
18939+#define ktla_ktva(addr) (addr)
18940+#define ktva_ktla(addr) (addr)
18941+#endif
18942+
18943 #define MODULES_VADDR VMALLOC_START
18944 #define MODULES_END VMALLOC_END
18945 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
18946diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
18947index 3874693..d7906ac 100644
18948--- a/arch/x86/include/asm/pgtable_64.h
18949+++ b/arch/x86/include/asm/pgtable_64.h
18950@@ -16,11 +16,16 @@
18951
18952 extern pud_t level3_kernel_pgt[512];
18953 extern pud_t level3_ident_pgt[512];
18954+extern pud_t level3_vmalloc_start_pgt[512];
18955+extern pud_t level3_vmalloc_end_pgt[512];
18956+extern pud_t level3_vmemmap_pgt[512];
18957+extern pud_t level2_vmemmap_pgt[512];
18958 extern pmd_t level2_kernel_pgt[512];
18959 extern pmd_t level2_fixmap_pgt[512];
18960-extern pmd_t level2_ident_pgt[512];
18961+extern pmd_t level2_ident_pgt[512*2];
18962 extern pte_t level1_fixmap_pgt[512];
18963-extern pgd_t init_level4_pgt[];
18964+extern pte_t level1_vsyscall_pgt[512];
18965+extern pgd_t init_level4_pgt[512];
18966
18967 #define swapper_pg_dir init_level4_pgt
18968
18969@@ -62,7 +67,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
18970
18971 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
18972 {
18973+ pax_open_kernel();
18974 *pmdp = pmd;
18975+ pax_close_kernel();
18976 }
18977
18978 static inline void native_pmd_clear(pmd_t *pmd)
18979@@ -98,7 +105,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18980
18981 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18982 {
18983+ pax_open_kernel();
18984 *pudp = pud;
18985+ pax_close_kernel();
18986 }
18987
18988 static inline void native_pud_clear(pud_t *pud)
18989@@ -108,6 +117,13 @@ static inline void native_pud_clear(pud_t *pud)
18990
18991 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18992 {
18993+ pax_open_kernel();
18994+ *pgdp = pgd;
18995+ pax_close_kernel();
18996+}
18997+
18998+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18999+{
19000 *pgdp = pgd;
19001 }
19002
19003diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
19004index 7166e25..baaa6fe 100644
19005--- a/arch/x86/include/asm/pgtable_64_types.h
19006+++ b/arch/x86/include/asm/pgtable_64_types.h
19007@@ -61,9 +61,14 @@ typedef struct { pteval_t pte; } pte_t;
19008 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
19009 #define MODULES_END _AC(0xffffffffff000000, UL)
19010 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
19011+#define MODULES_EXEC_VADDR MODULES_VADDR
19012+#define MODULES_EXEC_END MODULES_END
19013 #define ESPFIX_PGD_ENTRY _AC(-2, UL)
19014 #define ESPFIX_BASE_ADDR (ESPFIX_PGD_ENTRY << PGDIR_SHIFT)
19015
19016+#define ktla_ktva(addr) (addr)
19017+#define ktva_ktla(addr) (addr)
19018+
19019 #define EARLY_DYNAMIC_PAGE_TABLES 64
19020
19021 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
19022diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
19023index f216963..6bd7c21 100644
19024--- a/arch/x86/include/asm/pgtable_types.h
19025+++ b/arch/x86/include/asm/pgtable_types.h
19026@@ -111,8 +111,10 @@
19027
19028 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
19029 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
19030-#else
19031+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
19032 #define _PAGE_NX (_AT(pteval_t, 0))
19033+#else
19034+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
19035 #endif
19036
19037 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
19038@@ -151,6 +153,9 @@
19039 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
19040 _PAGE_ACCESSED)
19041
19042+#define PAGE_READONLY_NOEXEC PAGE_READONLY
19043+#define PAGE_SHARED_NOEXEC PAGE_SHARED
19044+
19045 #define __PAGE_KERNEL_EXEC \
19046 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
19047 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
19048@@ -161,7 +166,7 @@
19049 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
19050 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
19051 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
19052-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
19053+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
19054 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
19055 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
19056 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
19057@@ -218,7 +223,7 @@
19058 #ifdef CONFIG_X86_64
19059 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
19060 #else
19061-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
19062+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
19063 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
19064 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
19065 #endif
19066@@ -257,7 +262,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
19067 {
19068 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
19069 }
19070+#endif
19071
19072+#if PAGETABLE_LEVELS == 3
19073+#include <asm-generic/pgtable-nopud.h>
19074+#endif
19075+
19076+#if PAGETABLE_LEVELS == 2
19077+#include <asm-generic/pgtable-nopmd.h>
19078+#endif
19079+
19080+#ifndef __ASSEMBLY__
19081 #if PAGETABLE_LEVELS > 3
19082 typedef struct { pudval_t pud; } pud_t;
19083
19084@@ -271,8 +286,6 @@ static inline pudval_t native_pud_val(pud_t pud)
19085 return pud.pud;
19086 }
19087 #else
19088-#include <asm-generic/pgtable-nopud.h>
19089-
19090 static inline pudval_t native_pud_val(pud_t pud)
19091 {
19092 return native_pgd_val(pud.pgd);
19093@@ -292,8 +305,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
19094 return pmd.pmd;
19095 }
19096 #else
19097-#include <asm-generic/pgtable-nopmd.h>
19098-
19099 static inline pmdval_t native_pmd_val(pmd_t pmd)
19100 {
19101 return native_pgd_val(pmd.pud.pgd);
19102@@ -333,7 +344,6 @@ typedef struct page *pgtable_t;
19103
19104 extern pteval_t __supported_pte_mask;
19105 extern void set_nx(void);
19106-extern int nx_enabled;
19107
19108 #define pgprot_writecombine pgprot_writecombine
19109 extern pgprot_t pgprot_writecombine(pgprot_t prot);
19110diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
19111index 7024c12..71c46b9 100644
19112--- a/arch/x86/include/asm/preempt.h
19113+++ b/arch/x86/include/asm/preempt.h
19114@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
19115 */
19116 static __always_inline bool __preempt_count_dec_and_test(void)
19117 {
19118- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
19119+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
19120 }
19121
19122 /*
19123diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
19124index eb71ec7..f06532a 100644
19125--- a/arch/x86/include/asm/processor.h
19126+++ b/arch/x86/include/asm/processor.h
19127@@ -127,7 +127,7 @@ struct cpuinfo_x86 {
19128 /* Index into per_cpu list: */
19129 u16 cpu_index;
19130 u32 microcode;
19131-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
19132+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
19133
19134 #define X86_VENDOR_INTEL 0
19135 #define X86_VENDOR_CYRIX 1
19136@@ -198,9 +198,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
19137 : "memory");
19138 }
19139
19140+/* invpcid (%rdx),%rax */
19141+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
19142+
19143+#define INVPCID_SINGLE_ADDRESS 0UL
19144+#define INVPCID_SINGLE_CONTEXT 1UL
19145+#define INVPCID_ALL_GLOBAL 2UL
19146+#define INVPCID_ALL_NONGLOBAL 3UL
19147+
19148+#define PCID_KERNEL 0UL
19149+#define PCID_USER 1UL
19150+#define PCID_NOFLUSH (1UL << 63)
19151+
19152 static inline void load_cr3(pgd_t *pgdir)
19153 {
19154- write_cr3(__pa(pgdir));
19155+ write_cr3(__pa(pgdir) | PCID_KERNEL);
19156 }
19157
19158 #ifdef CONFIG_X86_32
19159@@ -282,7 +294,7 @@ struct tss_struct {
19160
19161 } ____cacheline_aligned;
19162
19163-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
19164+extern struct tss_struct init_tss[NR_CPUS];
19165
19166 /*
19167 * Save the original ist values for checking stack pointers during debugging
19168@@ -478,6 +490,7 @@ struct thread_struct {
19169 unsigned short ds;
19170 unsigned short fsindex;
19171 unsigned short gsindex;
19172+ unsigned short ss;
19173 #endif
19174 #ifdef CONFIG_X86_32
19175 unsigned long ip;
19176@@ -587,29 +600,8 @@ static inline void load_sp0(struct tss_struct *tss,
19177 extern unsigned long mmu_cr4_features;
19178 extern u32 *trampoline_cr4_features;
19179
19180-static inline void set_in_cr4(unsigned long mask)
19181-{
19182- unsigned long cr4;
19183-
19184- mmu_cr4_features |= mask;
19185- if (trampoline_cr4_features)
19186- *trampoline_cr4_features = mmu_cr4_features;
19187- cr4 = read_cr4();
19188- cr4 |= mask;
19189- write_cr4(cr4);
19190-}
19191-
19192-static inline void clear_in_cr4(unsigned long mask)
19193-{
19194- unsigned long cr4;
19195-
19196- mmu_cr4_features &= ~mask;
19197- if (trampoline_cr4_features)
19198- *trampoline_cr4_features = mmu_cr4_features;
19199- cr4 = read_cr4();
19200- cr4 &= ~mask;
19201- write_cr4(cr4);
19202-}
19203+extern void set_in_cr4(unsigned long mask);
19204+extern void clear_in_cr4(unsigned long mask);
19205
19206 typedef struct {
19207 unsigned long seg;
19208@@ -837,11 +829,18 @@ static inline void spin_lock_prefetch(const void *x)
19209 */
19210 #define TASK_SIZE PAGE_OFFSET
19211 #define TASK_SIZE_MAX TASK_SIZE
19212+
19213+#ifdef CONFIG_PAX_SEGMEXEC
19214+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
19215+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
19216+#else
19217 #define STACK_TOP TASK_SIZE
19218-#define STACK_TOP_MAX STACK_TOP
19219+#endif
19220+
19221+#define STACK_TOP_MAX TASK_SIZE
19222
19223 #define INIT_THREAD { \
19224- .sp0 = sizeof(init_stack) + (long)&init_stack, \
19225+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
19226 .vm86_info = NULL, \
19227 .sysenter_cs = __KERNEL_CS, \
19228 .io_bitmap_ptr = NULL, \
19229@@ -855,7 +854,7 @@ static inline void spin_lock_prefetch(const void *x)
19230 */
19231 #define INIT_TSS { \
19232 .x86_tss = { \
19233- .sp0 = sizeof(init_stack) + (long)&init_stack, \
19234+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
19235 .ss0 = __KERNEL_DS, \
19236 .ss1 = __KERNEL_CS, \
19237 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
19238@@ -866,11 +865,7 @@ static inline void spin_lock_prefetch(const void *x)
19239 extern unsigned long thread_saved_pc(struct task_struct *tsk);
19240
19241 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
19242-#define KSTK_TOP(info) \
19243-({ \
19244- unsigned long *__ptr = (unsigned long *)(info); \
19245- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
19246-})
19247+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
19248
19249 /*
19250 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
19251@@ -885,7 +880,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
19252 #define task_pt_regs(task) \
19253 ({ \
19254 struct pt_regs *__regs__; \
19255- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
19256+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
19257 __regs__ - 1; \
19258 })
19259
19260@@ -895,13 +890,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
19261 /*
19262 * User space process size. 47bits minus one guard page.
19263 */
19264-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
19265+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
19266
19267 /* This decides where the kernel will search for a free chunk of vm
19268 * space during mmap's.
19269 */
19270 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
19271- 0xc0000000 : 0xFFFFe000)
19272+ 0xc0000000 : 0xFFFFf000)
19273
19274 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
19275 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
19276@@ -912,11 +907,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
19277 #define STACK_TOP_MAX TASK_SIZE_MAX
19278
19279 #define INIT_THREAD { \
19280- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
19281+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
19282 }
19283
19284 #define INIT_TSS { \
19285- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
19286+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
19287 }
19288
19289 /*
19290@@ -944,6 +939,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
19291 */
19292 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
19293
19294+#ifdef CONFIG_PAX_SEGMEXEC
19295+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
19296+#endif
19297+
19298 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
19299
19300 /* Get/set a process' ability to use the timestamp counter instruction */
19301@@ -970,7 +969,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
19302 return 0;
19303 }
19304
19305-extern unsigned long arch_align_stack(unsigned long sp);
19306+#define arch_align_stack(x) ((x) & ~0xfUL)
19307 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
19308
19309 void default_idle(void);
19310@@ -980,6 +979,6 @@ bool xen_set_default_idle(void);
19311 #define xen_set_default_idle 0
19312 #endif
19313
19314-void stop_this_cpu(void *dummy);
19315+void stop_this_cpu(void *dummy) __noreturn;
19316 void df_debug(struct pt_regs *regs, long error_code);
19317 #endif /* _ASM_X86_PROCESSOR_H */
19318diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
19319index 6205f0c..688a3a9 100644
19320--- a/arch/x86/include/asm/ptrace.h
19321+++ b/arch/x86/include/asm/ptrace.h
19322@@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
19323 }
19324
19325 /*
19326- * user_mode_vm(regs) determines whether a register set came from user mode.
19327+ * user_mode(regs) determines whether a register set came from user mode.
19328 * This is true if V8086 mode was enabled OR if the register set was from
19329 * protected mode with RPL-3 CS value. This tricky test checks that with
19330 * one comparison. Many places in the kernel can bypass this full check
19331- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
19332+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
19333+ * be used.
19334 */
19335-static inline int user_mode(struct pt_regs *regs)
19336+static inline int user_mode_novm(struct pt_regs *regs)
19337 {
19338 #ifdef CONFIG_X86_32
19339 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
19340 #else
19341- return !!(regs->cs & 3);
19342+ return !!(regs->cs & SEGMENT_RPL_MASK);
19343 #endif
19344 }
19345
19346-static inline int user_mode_vm(struct pt_regs *regs)
19347+static inline int user_mode(struct pt_regs *regs)
19348 {
19349 #ifdef CONFIG_X86_32
19350 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
19351 USER_RPL;
19352 #else
19353- return user_mode(regs);
19354+ return user_mode_novm(regs);
19355 #endif
19356 }
19357
19358@@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
19359 #ifdef CONFIG_X86_64
19360 static inline bool user_64bit_mode(struct pt_regs *regs)
19361 {
19362+ unsigned long cs = regs->cs & 0xffff;
19363 #ifndef CONFIG_PARAVIRT
19364 /*
19365 * On non-paravirt systems, this is the only long mode CPL 3
19366 * selector. We do not allow long mode selectors in the LDT.
19367 */
19368- return regs->cs == __USER_CS;
19369+ return cs == __USER_CS;
19370 #else
19371 /* Headers are too twisted for this to go in paravirt.h. */
19372- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
19373+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
19374 #endif
19375 }
19376
19377@@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
19378 * Traps from the kernel do not save sp and ss.
19379 * Use the helper function to retrieve sp.
19380 */
19381- if (offset == offsetof(struct pt_regs, sp) &&
19382- regs->cs == __KERNEL_CS)
19383- return kernel_stack_pointer(regs);
19384+ if (offset == offsetof(struct pt_regs, sp)) {
19385+ unsigned long cs = regs->cs & 0xffff;
19386+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
19387+ return kernel_stack_pointer(regs);
19388+ }
19389 #endif
19390 return *(unsigned long *)((unsigned long)regs + offset);
19391 }
19392diff --git a/arch/x86/include/asm/qrwlock.h b/arch/x86/include/asm/qrwlock.h
19393index ae0e241..e80b10b 100644
19394--- a/arch/x86/include/asm/qrwlock.h
19395+++ b/arch/x86/include/asm/qrwlock.h
19396@@ -7,8 +7,8 @@
19397 #define queue_write_unlock queue_write_unlock
19398 static inline void queue_write_unlock(struct qrwlock *lock)
19399 {
19400- barrier();
19401- ACCESS_ONCE(*(u8 *)&lock->cnts) = 0;
19402+ barrier();
19403+ ACCESS_ONCE_RW(*(u8 *)&lock->cnts) = 0;
19404 }
19405 #endif
19406
19407diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
19408index 9c6b890..5305f53 100644
19409--- a/arch/x86/include/asm/realmode.h
19410+++ b/arch/x86/include/asm/realmode.h
19411@@ -22,16 +22,14 @@ struct real_mode_header {
19412 #endif
19413 /* APM/BIOS reboot */
19414 u32 machine_real_restart_asm;
19415-#ifdef CONFIG_X86_64
19416 u32 machine_real_restart_seg;
19417-#endif
19418 };
19419
19420 /* This must match data at trampoline_32/64.S */
19421 struct trampoline_header {
19422 #ifdef CONFIG_X86_32
19423 u32 start;
19424- u16 gdt_pad;
19425+ u16 boot_cs;
19426 u16 gdt_limit;
19427 u32 gdt_base;
19428 #else
19429diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
19430index a82c4f1..ac45053 100644
19431--- a/arch/x86/include/asm/reboot.h
19432+++ b/arch/x86/include/asm/reboot.h
19433@@ -6,13 +6,13 @@
19434 struct pt_regs;
19435
19436 struct machine_ops {
19437- void (*restart)(char *cmd);
19438- void (*halt)(void);
19439- void (*power_off)(void);
19440+ void (* __noreturn restart)(char *cmd);
19441+ void (* __noreturn halt)(void);
19442+ void (* __noreturn power_off)(void);
19443 void (*shutdown)(void);
19444 void (*crash_shutdown)(struct pt_regs *);
19445- void (*emergency_restart)(void);
19446-};
19447+ void (* __noreturn emergency_restart)(void);
19448+} __no_const;
19449
19450 extern struct machine_ops machine_ops;
19451
19452diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
19453index 8f7866a..e442f20 100644
19454--- a/arch/x86/include/asm/rmwcc.h
19455+++ b/arch/x86/include/asm/rmwcc.h
19456@@ -3,7 +3,34 @@
19457
19458 #ifdef CC_HAVE_ASM_GOTO
19459
19460-#define __GEN_RMWcc(fullop, var, cc, ...) \
19461+#ifdef CONFIG_PAX_REFCOUNT
19462+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19463+do { \
19464+ asm_volatile_goto (fullop \
19465+ ";jno 0f\n" \
19466+ fullantiop \
19467+ ";int $4\n0:\n" \
19468+ _ASM_EXTABLE(0b, 0b) \
19469+ ";j" cc " %l[cc_label]" \
19470+ : : "m" (var), ## __VA_ARGS__ \
19471+ : "memory" : cc_label); \
19472+ return 0; \
19473+cc_label: \
19474+ return 1; \
19475+} while (0)
19476+#else
19477+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19478+do { \
19479+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
19480+ : : "m" (var), ## __VA_ARGS__ \
19481+ : "memory" : cc_label); \
19482+ return 0; \
19483+cc_label: \
19484+ return 1; \
19485+} while (0)
19486+#endif
19487+
19488+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19489 do { \
19490 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
19491 : : "m" (var), ## __VA_ARGS__ \
19492@@ -13,15 +40,46 @@ cc_label: \
19493 return 1; \
19494 } while (0)
19495
19496-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19497- __GEN_RMWcc(op " " arg0, var, cc)
19498+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19499+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19500
19501-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19502- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
19503+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19504+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19505+
19506+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19507+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
19508+
19509+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19510+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
19511
19512 #else /* !CC_HAVE_ASM_GOTO */
19513
19514-#define __GEN_RMWcc(fullop, var, cc, ...) \
19515+#ifdef CONFIG_PAX_REFCOUNT
19516+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19517+do { \
19518+ char c; \
19519+ asm volatile (fullop \
19520+ ";jno 0f\n" \
19521+ fullantiop \
19522+ ";int $4\n0:\n" \
19523+ _ASM_EXTABLE(0b, 0b) \
19524+ "; set" cc " %1" \
19525+ : "+m" (var), "=qm" (c) \
19526+ : __VA_ARGS__ : "memory"); \
19527+ return c != 0; \
19528+} while (0)
19529+#else
19530+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
19531+do { \
19532+ char c; \
19533+ asm volatile (fullop "; set" cc " %1" \
19534+ : "+m" (var), "=qm" (c) \
19535+ : __VA_ARGS__ : "memory"); \
19536+ return c != 0; \
19537+} while (0)
19538+#endif
19539+
19540+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
19541 do { \
19542 char c; \
19543 asm volatile (fullop "; set" cc " %1" \
19544@@ -30,11 +88,17 @@ do { \
19545 return c != 0; \
19546 } while (0)
19547
19548-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
19549- __GEN_RMWcc(op " " arg0, var, cc)
19550+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
19551+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
19552+
19553+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
19554+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
19555+
19556+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
19557+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
19558
19559-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
19560- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
19561+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
19562+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
19563
19564 #endif /* CC_HAVE_ASM_GOTO */
19565
19566diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
19567index cad82c9..2e5c5c1 100644
19568--- a/arch/x86/include/asm/rwsem.h
19569+++ b/arch/x86/include/asm/rwsem.h
19570@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
19571 {
19572 asm volatile("# beginning down_read\n\t"
19573 LOCK_PREFIX _ASM_INC "(%1)\n\t"
19574+
19575+#ifdef CONFIG_PAX_REFCOUNT
19576+ "jno 0f\n"
19577+ LOCK_PREFIX _ASM_DEC "(%1)\n"
19578+ "int $4\n0:\n"
19579+ _ASM_EXTABLE(0b, 0b)
19580+#endif
19581+
19582 /* adds 0x00000001 */
19583 " jns 1f\n"
19584 " call call_rwsem_down_read_failed\n"
19585@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
19586 "1:\n\t"
19587 " mov %1,%2\n\t"
19588 " add %3,%2\n\t"
19589+
19590+#ifdef CONFIG_PAX_REFCOUNT
19591+ "jno 0f\n"
19592+ "sub %3,%2\n"
19593+ "int $4\n0:\n"
19594+ _ASM_EXTABLE(0b, 0b)
19595+#endif
19596+
19597 " jle 2f\n\t"
19598 LOCK_PREFIX " cmpxchg %2,%0\n\t"
19599 " jnz 1b\n\t"
19600@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
19601 long tmp;
19602 asm volatile("# beginning down_write\n\t"
19603 LOCK_PREFIX " xadd %1,(%2)\n\t"
19604+
19605+#ifdef CONFIG_PAX_REFCOUNT
19606+ "jno 0f\n"
19607+ "mov %1,(%2)\n"
19608+ "int $4\n0:\n"
19609+ _ASM_EXTABLE(0b, 0b)
19610+#endif
19611+
19612 /* adds 0xffff0001, returns the old value */
19613 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
19614 /* was the active mask 0 before? */
19615@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
19616 long tmp;
19617 asm volatile("# beginning __up_read\n\t"
19618 LOCK_PREFIX " xadd %1,(%2)\n\t"
19619+
19620+#ifdef CONFIG_PAX_REFCOUNT
19621+ "jno 0f\n"
19622+ "mov %1,(%2)\n"
19623+ "int $4\n0:\n"
19624+ _ASM_EXTABLE(0b, 0b)
19625+#endif
19626+
19627 /* subtracts 1, returns the old value */
19628 " jns 1f\n\t"
19629 " call call_rwsem_wake\n" /* expects old value in %edx */
19630@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
19631 long tmp;
19632 asm volatile("# beginning __up_write\n\t"
19633 LOCK_PREFIX " xadd %1,(%2)\n\t"
19634+
19635+#ifdef CONFIG_PAX_REFCOUNT
19636+ "jno 0f\n"
19637+ "mov %1,(%2)\n"
19638+ "int $4\n0:\n"
19639+ _ASM_EXTABLE(0b, 0b)
19640+#endif
19641+
19642 /* subtracts 0xffff0001, returns the old value */
19643 " jns 1f\n\t"
19644 " call call_rwsem_wake\n" /* expects old value in %edx */
19645@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19646 {
19647 asm volatile("# beginning __downgrade_write\n\t"
19648 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
19649+
19650+#ifdef CONFIG_PAX_REFCOUNT
19651+ "jno 0f\n"
19652+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
19653+ "int $4\n0:\n"
19654+ _ASM_EXTABLE(0b, 0b)
19655+#endif
19656+
19657 /*
19658 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
19659 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
19660@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
19661 */
19662 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19663 {
19664- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
19665+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
19666+
19667+#ifdef CONFIG_PAX_REFCOUNT
19668+ "jno 0f\n"
19669+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
19670+ "int $4\n0:\n"
19671+ _ASM_EXTABLE(0b, 0b)
19672+#endif
19673+
19674 : "+m" (sem->count)
19675 : "er" (delta));
19676 }
19677@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
19678 */
19679 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
19680 {
19681- return delta + xadd(&sem->count, delta);
19682+ return delta + xadd_check_overflow(&sem->count, delta);
19683 }
19684
19685 #endif /* __KERNEL__ */
19686diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
19687index 6f1c3a8..7744f19 100644
19688--- a/arch/x86/include/asm/segment.h
19689+++ b/arch/x86/include/asm/segment.h
19690@@ -64,10 +64,15 @@
19691 * 26 - ESPFIX small SS
19692 * 27 - per-cpu [ offset to per-cpu data area ]
19693 * 28 - stack_canary-20 [ for stack protector ]
19694- * 29 - unused
19695- * 30 - unused
19696+ * 29 - PCI BIOS CS
19697+ * 30 - PCI BIOS DS
19698 * 31 - TSS for double fault handler
19699 */
19700+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
19701+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
19702+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
19703+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
19704+
19705 #define GDT_ENTRY_TLS_MIN 6
19706 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
19707
19708@@ -79,6 +84,8 @@
19709
19710 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
19711
19712+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
19713+
19714 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
19715
19716 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
19717@@ -104,6 +111,12 @@
19718 #define __KERNEL_STACK_CANARY 0
19719 #endif
19720
19721+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
19722+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
19723+
19724+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
19725+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
19726+
19727 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
19728
19729 /*
19730@@ -141,7 +154,7 @@
19731 */
19732
19733 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
19734-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
19735+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
19736
19737
19738 #else
19739@@ -165,6 +178,8 @@
19740 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
19741 #define __USER32_DS __USER_DS
19742
19743+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
19744+
19745 #define GDT_ENTRY_TSS 8 /* needs two entries */
19746 #define GDT_ENTRY_LDT 10 /* needs two entries */
19747 #define GDT_ENTRY_TLS_MIN 12
19748@@ -173,6 +188,8 @@
19749 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
19750 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
19751
19752+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
19753+
19754 /* TLS indexes for 64bit - hardcoded in arch_prctl */
19755 #define FS_TLS 0
19756 #define GS_TLS 1
19757@@ -180,12 +197,14 @@
19758 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
19759 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
19760
19761-#define GDT_ENTRIES 16
19762+#define GDT_ENTRIES 17
19763
19764 #endif
19765
19766 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
19767+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
19768 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
19769+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
19770 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
19771 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
19772 #ifndef CONFIG_PARAVIRT
19773@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
19774 {
19775 unsigned long __limit;
19776 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
19777- return __limit + 1;
19778+ return __limit;
19779 }
19780
19781 #endif /* !__ASSEMBLY__ */
19782diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
19783index 8d3120f..352b440 100644
19784--- a/arch/x86/include/asm/smap.h
19785+++ b/arch/x86/include/asm/smap.h
19786@@ -25,11 +25,40 @@
19787
19788 #include <asm/alternative-asm.h>
19789
19790+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19791+#define ASM_PAX_OPEN_USERLAND \
19792+ 661: jmp 663f; \
19793+ .pushsection .altinstr_replacement, "a" ; \
19794+ 662: pushq %rax; nop; \
19795+ .popsection ; \
19796+ .pushsection .altinstructions, "a" ; \
19797+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19798+ .popsection ; \
19799+ call __pax_open_userland; \
19800+ popq %rax; \
19801+ 663:
19802+
19803+#define ASM_PAX_CLOSE_USERLAND \
19804+ 661: jmp 663f; \
19805+ .pushsection .altinstr_replacement, "a" ; \
19806+ 662: pushq %rax; nop; \
19807+ .popsection; \
19808+ .pushsection .altinstructions, "a" ; \
19809+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
19810+ .popsection; \
19811+ call __pax_close_userland; \
19812+ popq %rax; \
19813+ 663:
19814+#else
19815+#define ASM_PAX_OPEN_USERLAND
19816+#define ASM_PAX_CLOSE_USERLAND
19817+#endif
19818+
19819 #ifdef CONFIG_X86_SMAP
19820
19821 #define ASM_CLAC \
19822 661: ASM_NOP3 ; \
19823- .pushsection .altinstr_replacement, "ax" ; \
19824+ .pushsection .altinstr_replacement, "a" ; \
19825 662: __ASM_CLAC ; \
19826 .popsection ; \
19827 .pushsection .altinstructions, "a" ; \
19828@@ -38,7 +67,7 @@
19829
19830 #define ASM_STAC \
19831 661: ASM_NOP3 ; \
19832- .pushsection .altinstr_replacement, "ax" ; \
19833+ .pushsection .altinstr_replacement, "a" ; \
19834 662: __ASM_STAC ; \
19835 .popsection ; \
19836 .pushsection .altinstructions, "a" ; \
19837@@ -56,6 +85,37 @@
19838
19839 #include <asm/alternative.h>
19840
19841+#define __HAVE_ARCH_PAX_OPEN_USERLAND
19842+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
19843+
19844+extern void __pax_open_userland(void);
19845+static __always_inline unsigned long pax_open_userland(void)
19846+{
19847+
19848+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19849+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
19850+ :
19851+ : [open] "i" (__pax_open_userland)
19852+ : "memory", "rax");
19853+#endif
19854+
19855+ return 0;
19856+}
19857+
19858+extern void __pax_close_userland(void);
19859+static __always_inline unsigned long pax_close_userland(void)
19860+{
19861+
19862+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19863+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
19864+ :
19865+ : [close] "i" (__pax_close_userland)
19866+ : "memory", "rax");
19867+#endif
19868+
19869+ return 0;
19870+}
19871+
19872 #ifdef CONFIG_X86_SMAP
19873
19874 static __always_inline void clac(void)
19875diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
19876index 8cd27e0..7f05ec8 100644
19877--- a/arch/x86/include/asm/smp.h
19878+++ b/arch/x86/include/asm/smp.h
19879@@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
19880 /* cpus sharing the last level cache: */
19881 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
19882 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
19883-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
19884+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
19885
19886 static inline struct cpumask *cpu_sibling_mask(int cpu)
19887 {
19888@@ -78,7 +78,7 @@ struct smp_ops {
19889
19890 void (*send_call_func_ipi)(const struct cpumask *mask);
19891 void (*send_call_func_single_ipi)(int cpu);
19892-};
19893+} __no_const;
19894
19895 /* Globals due to paravirt */
19896 extern void set_cpu_sibling_map(int cpu);
19897@@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
19898 extern int safe_smp_processor_id(void);
19899
19900 #elif defined(CONFIG_X86_64_SMP)
19901-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19902-
19903-#define stack_smp_processor_id() \
19904-({ \
19905- struct thread_info *ti; \
19906- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
19907- ti->cpu; \
19908-})
19909+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
19910+#define stack_smp_processor_id() raw_smp_processor_id()
19911 #define safe_smp_processor_id() smp_processor_id()
19912
19913 #endif
19914diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
19915index 54f1c80..39362a5 100644
19916--- a/arch/x86/include/asm/spinlock.h
19917+++ b/arch/x86/include/asm/spinlock.h
19918@@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
19919 static inline void arch_read_lock(arch_rwlock_t *rw)
19920 {
19921 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
19922+
19923+#ifdef CONFIG_PAX_REFCOUNT
19924+ "jno 0f\n"
19925+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
19926+ "int $4\n0:\n"
19927+ _ASM_EXTABLE(0b, 0b)
19928+#endif
19929+
19930 "jns 1f\n"
19931 "call __read_lock_failed\n\t"
19932 "1:\n"
19933@@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
19934 static inline void arch_write_lock(arch_rwlock_t *rw)
19935 {
19936 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
19937+
19938+#ifdef CONFIG_PAX_REFCOUNT
19939+ "jno 0f\n"
19940+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
19941+ "int $4\n0:\n"
19942+ _ASM_EXTABLE(0b, 0b)
19943+#endif
19944+
19945 "jz 1f\n"
19946 "call __write_lock_failed\n\t"
19947 "1:\n"
19948@@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
19949
19950 static inline void arch_read_unlock(arch_rwlock_t *rw)
19951 {
19952- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
19953+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
19954+
19955+#ifdef CONFIG_PAX_REFCOUNT
19956+ "jno 0f\n"
19957+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
19958+ "int $4\n0:\n"
19959+ _ASM_EXTABLE(0b, 0b)
19960+#endif
19961+
19962 :"+m" (rw->lock) : : "memory");
19963 }
19964
19965 static inline void arch_write_unlock(arch_rwlock_t *rw)
19966 {
19967- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19968+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19969+
19970+#ifdef CONFIG_PAX_REFCOUNT
19971+ "jno 0f\n"
19972+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19973+ "int $4\n0:\n"
19974+ _ASM_EXTABLE(0b, 0b)
19975+#endif
19976+
19977 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19978 }
19979 #else
19980diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19981index 6a99859..03cb807 100644
19982--- a/arch/x86/include/asm/stackprotector.h
19983+++ b/arch/x86/include/asm/stackprotector.h
19984@@ -47,7 +47,7 @@
19985 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19986 */
19987 #define GDT_STACK_CANARY_INIT \
19988- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19989+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19990
19991 /*
19992 * Initialize the stackprotector canary value.
19993@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19994
19995 static inline void load_stack_canary_segment(void)
19996 {
19997-#ifdef CONFIG_X86_32
19998+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19999 asm volatile ("mov %0, %%gs" : : "r" (0));
20000 #endif
20001 }
20002diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
20003index 70bbe39..4ae2bd4 100644
20004--- a/arch/x86/include/asm/stacktrace.h
20005+++ b/arch/x86/include/asm/stacktrace.h
20006@@ -11,28 +11,20 @@
20007
20008 extern int kstack_depth_to_print;
20009
20010-struct thread_info;
20011+struct task_struct;
20012 struct stacktrace_ops;
20013
20014-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
20015- unsigned long *stack,
20016- unsigned long bp,
20017- const struct stacktrace_ops *ops,
20018- void *data,
20019- unsigned long *end,
20020- int *graph);
20021+typedef unsigned long walk_stack_t(struct task_struct *task,
20022+ void *stack_start,
20023+ unsigned long *stack,
20024+ unsigned long bp,
20025+ const struct stacktrace_ops *ops,
20026+ void *data,
20027+ unsigned long *end,
20028+ int *graph);
20029
20030-extern unsigned long
20031-print_context_stack(struct thread_info *tinfo,
20032- unsigned long *stack, unsigned long bp,
20033- const struct stacktrace_ops *ops, void *data,
20034- unsigned long *end, int *graph);
20035-
20036-extern unsigned long
20037-print_context_stack_bp(struct thread_info *tinfo,
20038- unsigned long *stack, unsigned long bp,
20039- const struct stacktrace_ops *ops, void *data,
20040- unsigned long *end, int *graph);
20041+extern walk_stack_t print_context_stack;
20042+extern walk_stack_t print_context_stack_bp;
20043
20044 /* Generic stack tracer with callbacks */
20045
20046@@ -40,7 +32,7 @@ struct stacktrace_ops {
20047 void (*address)(void *data, unsigned long address, int reliable);
20048 /* On negative return stop dumping */
20049 int (*stack)(void *data, char *name);
20050- walk_stack_t walk_stack;
20051+ walk_stack_t *walk_stack;
20052 };
20053
20054 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
20055diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
20056index d7f3b3b..3cc39f1 100644
20057--- a/arch/x86/include/asm/switch_to.h
20058+++ b/arch/x86/include/asm/switch_to.h
20059@@ -108,7 +108,7 @@ do { \
20060 "call __switch_to\n\t" \
20061 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
20062 __switch_canary \
20063- "movq %P[thread_info](%%rsi),%%r8\n\t" \
20064+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
20065 "movq %%rax,%%rdi\n\t" \
20066 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
20067 "jnz ret_from_fork\n\t" \
20068@@ -119,7 +119,7 @@ do { \
20069 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
20070 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
20071 [_tif_fork] "i" (_TIF_FORK), \
20072- [thread_info] "i" (offsetof(struct task_struct, stack)), \
20073+ [thread_info] "m" (current_tinfo), \
20074 [current_task] "m" (current_task) \
20075 __switch_canary_iparam \
20076 : "memory", "cc" __EXTRA_CLOBBER)
20077diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
20078index 8540538..4b0b5e9 100644
20079--- a/arch/x86/include/asm/thread_info.h
20080+++ b/arch/x86/include/asm/thread_info.h
20081@@ -24,7 +24,6 @@ struct exec_domain;
20082 #include <linux/atomic.h>
20083
20084 struct thread_info {
20085- struct task_struct *task; /* main task structure */
20086 struct exec_domain *exec_domain; /* execution domain */
20087 __u32 flags; /* low level flags */
20088 __u32 status; /* thread synchronous flags */
20089@@ -33,13 +32,13 @@ struct thread_info {
20090 mm_segment_t addr_limit;
20091 struct restart_block restart_block;
20092 void __user *sysenter_return;
20093+ unsigned long lowest_stack;
20094 unsigned int sig_on_uaccess_error:1;
20095 unsigned int uaccess_err:1; /* uaccess failed */
20096 };
20097
20098-#define INIT_THREAD_INFO(tsk) \
20099+#define INIT_THREAD_INFO \
20100 { \
20101- .task = &tsk, \
20102 .exec_domain = &default_exec_domain, \
20103 .flags = 0, \
20104 .cpu = 0, \
20105@@ -50,7 +49,7 @@ struct thread_info {
20106 }, \
20107 }
20108
20109-#define init_thread_info (init_thread_union.thread_info)
20110+#define init_thread_info (init_thread_union.stack)
20111 #define init_stack (init_thread_union.stack)
20112
20113 #else /* !__ASSEMBLY__ */
20114@@ -91,6 +90,7 @@ struct thread_info {
20115 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
20116 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
20117 #define TIF_X32 30 /* 32-bit native x86-64 binary */
20118+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
20119
20120 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
20121 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
20122@@ -115,17 +115,18 @@ struct thread_info {
20123 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
20124 #define _TIF_ADDR32 (1 << TIF_ADDR32)
20125 #define _TIF_X32 (1 << TIF_X32)
20126+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
20127
20128 /* work to do in syscall_trace_enter() */
20129 #define _TIF_WORK_SYSCALL_ENTRY \
20130 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
20131 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
20132- _TIF_NOHZ)
20133+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
20134
20135 /* work to do in syscall_trace_leave() */
20136 #define _TIF_WORK_SYSCALL_EXIT \
20137 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
20138- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
20139+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
20140
20141 /* work to do on interrupt/exception return */
20142 #define _TIF_WORK_MASK \
20143@@ -136,7 +137,7 @@ struct thread_info {
20144 /* work to do on any return to user space */
20145 #define _TIF_ALLWORK_MASK \
20146 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
20147- _TIF_NOHZ)
20148+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
20149
20150 /* Only used for 64 bit */
20151 #define _TIF_DO_NOTIFY_MASK \
20152@@ -151,7 +152,6 @@ struct thread_info {
20153 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
20154
20155 #define STACK_WARN (THREAD_SIZE/8)
20156-#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
20157
20158 /*
20159 * macros/functions for gaining access to the thread information structure
20160@@ -162,26 +162,18 @@ struct thread_info {
20161
20162 DECLARE_PER_CPU(unsigned long, kernel_stack);
20163
20164+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
20165+
20166 static inline struct thread_info *current_thread_info(void)
20167 {
20168- struct thread_info *ti;
20169- ti = (void *)(this_cpu_read_stable(kernel_stack) +
20170- KERNEL_STACK_OFFSET - THREAD_SIZE);
20171- return ti;
20172+ return this_cpu_read_stable(current_tinfo);
20173 }
20174
20175 #else /* !__ASSEMBLY__ */
20176
20177 /* how to get the thread information struct from ASM */
20178 #define GET_THREAD_INFO(reg) \
20179- _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
20180- _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
20181-
20182-/*
20183- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
20184- * a certain register (to be used in assembler memory operands).
20185- */
20186-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
20187+ _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
20188
20189 #endif
20190
20191@@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
20192 extern void arch_task_cache_init(void);
20193 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
20194 extern void arch_release_task_struct(struct task_struct *tsk);
20195+
20196+#define __HAVE_THREAD_FUNCTIONS
20197+#define task_thread_info(task) (&(task)->tinfo)
20198+#define task_stack_page(task) ((task)->stack)
20199+#define setup_thread_stack(p, org) do {} while (0)
20200+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
20201+
20202 #endif
20203 #endif /* _ASM_X86_THREAD_INFO_H */
20204diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
20205index 04905bf..1178cdf 100644
20206--- a/arch/x86/include/asm/tlbflush.h
20207+++ b/arch/x86/include/asm/tlbflush.h
20208@@ -17,18 +17,44 @@
20209
20210 static inline void __native_flush_tlb(void)
20211 {
20212+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
20213+ u64 descriptor[2];
20214+
20215+ descriptor[0] = PCID_KERNEL;
20216+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_NONGLOBAL) : "memory");
20217+ return;
20218+ }
20219+
20220+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20221+ if (static_cpu_has(X86_FEATURE_PCID)) {
20222+ unsigned int cpu = raw_get_cpu();
20223+
20224+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
20225+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
20226+ raw_put_cpu_no_resched();
20227+ return;
20228+ }
20229+#endif
20230+
20231 native_write_cr3(native_read_cr3());
20232 }
20233
20234 static inline void __native_flush_tlb_global_irq_disabled(void)
20235 {
20236- unsigned long cr4;
20237+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
20238+ u64 descriptor[2];
20239
20240- cr4 = native_read_cr4();
20241- /* clear PGE */
20242- native_write_cr4(cr4 & ~X86_CR4_PGE);
20243- /* write old PGE again and flush TLBs */
20244- native_write_cr4(cr4);
20245+ descriptor[0] = PCID_KERNEL;
20246+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
20247+ } else {
20248+ unsigned long cr4;
20249+
20250+ cr4 = native_read_cr4();
20251+ /* clear PGE */
20252+ native_write_cr4(cr4 & ~X86_CR4_PGE);
20253+ /* write old PGE again and flush TLBs */
20254+ native_write_cr4(cr4);
20255+ }
20256 }
20257
20258 static inline void __native_flush_tlb_global(void)
20259@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
20260
20261 static inline void __native_flush_tlb_single(unsigned long addr)
20262 {
20263+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
20264+ u64 descriptor[2];
20265+
20266+ descriptor[0] = PCID_KERNEL;
20267+ descriptor[1] = addr;
20268+
20269+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20270+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
20271+ if (addr < TASK_SIZE_MAX)
20272+ descriptor[1] += pax_user_shadow_base;
20273+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
20274+ }
20275+
20276+ descriptor[0] = PCID_USER;
20277+ descriptor[1] = addr;
20278+#endif
20279+
20280+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
20281+ return;
20282+ }
20283+
20284+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20285+ if (static_cpu_has(X86_FEATURE_PCID)) {
20286+ unsigned int cpu = raw_get_cpu();
20287+
20288+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
20289+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
20290+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
20291+ raw_put_cpu_no_resched();
20292+
20293+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
20294+ addr += pax_user_shadow_base;
20295+ }
20296+#endif
20297+
20298 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
20299 }
20300
20301diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
20302index 0d592e0..526f797 100644
20303--- a/arch/x86/include/asm/uaccess.h
20304+++ b/arch/x86/include/asm/uaccess.h
20305@@ -7,6 +7,7 @@
20306 #include <linux/compiler.h>
20307 #include <linux/thread_info.h>
20308 #include <linux/string.h>
20309+#include <linux/spinlock.h>
20310 #include <asm/asm.h>
20311 #include <asm/page.h>
20312 #include <asm/smap.h>
20313@@ -29,7 +30,12 @@
20314
20315 #define get_ds() (KERNEL_DS)
20316 #define get_fs() (current_thread_info()->addr_limit)
20317+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20318+void __set_fs(mm_segment_t x);
20319+void set_fs(mm_segment_t x);
20320+#else
20321 #define set_fs(x) (current_thread_info()->addr_limit = (x))
20322+#endif
20323
20324 #define segment_eq(a, b) ((a).seg == (b).seg)
20325
20326@@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
20327 * checks that the pointer is in the user space range - after calling
20328 * this function, memory access functions may still return -EFAULT.
20329 */
20330-#define access_ok(type, addr, size) \
20331- likely(!__range_not_ok(addr, size, user_addr_max()))
20332+extern int _cond_resched(void);
20333+#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
20334+#define access_ok(type, addr, size) \
20335+({ \
20336+ unsigned long __size = size; \
20337+ unsigned long __addr = (unsigned long)addr; \
20338+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
20339+ if (__ret_ao && __size) { \
20340+ unsigned long __addr_ao = __addr & PAGE_MASK; \
20341+ unsigned long __end_ao = __addr + __size - 1; \
20342+ if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
20343+ while (__addr_ao <= __end_ao) { \
20344+ char __c_ao; \
20345+ __addr_ao += PAGE_SIZE; \
20346+ if (__size > PAGE_SIZE) \
20347+ _cond_resched(); \
20348+ if (__get_user(__c_ao, (char __user *)__addr)) \
20349+ break; \
20350+ if (type != VERIFY_WRITE) { \
20351+ __addr = __addr_ao; \
20352+ continue; \
20353+ } \
20354+ if (__put_user(__c_ao, (char __user *)__addr)) \
20355+ break; \
20356+ __addr = __addr_ao; \
20357+ } \
20358+ } \
20359+ } \
20360+ __ret_ao; \
20361+})
20362
20363 /*
20364 * The exception table consists of pairs of addresses relative to the
20365@@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
20366 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
20367 __chk_user_ptr(ptr); \
20368 might_fault(); \
20369+ pax_open_userland(); \
20370 asm volatile("call __get_user_%P3" \
20371 : "=a" (__ret_gu), "=r" (__val_gu) \
20372 : "0" (ptr), "i" (sizeof(*(ptr)))); \
20373 (x) = (__typeof__(*(ptr))) __val_gu; \
20374+ pax_close_userland(); \
20375 __ret_gu; \
20376 })
20377
20378@@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
20379 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
20380 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
20381
20382-
20383+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20384+#define __copyuser_seg "gs;"
20385+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
20386+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
20387+#else
20388+#define __copyuser_seg
20389+#define __COPYUSER_SET_ES
20390+#define __COPYUSER_RESTORE_ES
20391+#endif
20392
20393 #ifdef CONFIG_X86_32
20394 #define __put_user_asm_u64(x, addr, err, errret) \
20395 asm volatile(ASM_STAC "\n" \
20396- "1: movl %%eax,0(%2)\n" \
20397- "2: movl %%edx,4(%2)\n" \
20398+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
20399+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
20400 "3: " ASM_CLAC "\n" \
20401 ".section .fixup,\"ax\"\n" \
20402 "4: movl %3,%0\n" \
20403@@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
20404
20405 #define __put_user_asm_ex_u64(x, addr) \
20406 asm volatile(ASM_STAC "\n" \
20407- "1: movl %%eax,0(%1)\n" \
20408- "2: movl %%edx,4(%1)\n" \
20409+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
20410+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
20411 "3: " ASM_CLAC "\n" \
20412 _ASM_EXTABLE_EX(1b, 2b) \
20413 _ASM_EXTABLE_EX(2b, 3b) \
20414@@ -257,7 +301,8 @@ extern void __put_user_8(void);
20415 __typeof__(*(ptr)) __pu_val; \
20416 __chk_user_ptr(ptr); \
20417 might_fault(); \
20418- __pu_val = x; \
20419+ __pu_val = (x); \
20420+ pax_open_userland(); \
20421 switch (sizeof(*(ptr))) { \
20422 case 1: \
20423 __put_user_x(1, __pu_val, ptr, __ret_pu); \
20424@@ -275,6 +320,7 @@ extern void __put_user_8(void);
20425 __put_user_x(X, __pu_val, ptr, __ret_pu); \
20426 break; \
20427 } \
20428+ pax_close_userland(); \
20429 __ret_pu; \
20430 })
20431
20432@@ -355,8 +401,10 @@ do { \
20433 } while (0)
20434
20435 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
20436+do { \
20437+ pax_open_userland(); \
20438 asm volatile(ASM_STAC "\n" \
20439- "1: mov"itype" %2,%"rtype"1\n" \
20440+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
20441 "2: " ASM_CLAC "\n" \
20442 ".section .fixup,\"ax\"\n" \
20443 "3: mov %3,%0\n" \
20444@@ -364,8 +412,10 @@ do { \
20445 " jmp 2b\n" \
20446 ".previous\n" \
20447 _ASM_EXTABLE(1b, 3b) \
20448- : "=r" (err), ltype(x) \
20449- : "m" (__m(addr)), "i" (errret), "0" (err))
20450+ : "=r" (err), ltype (x) \
20451+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
20452+ pax_close_userland(); \
20453+} while (0)
20454
20455 #define __get_user_size_ex(x, ptr, size) \
20456 do { \
20457@@ -389,7 +439,7 @@ do { \
20458 } while (0)
20459
20460 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
20461- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
20462+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
20463 "2:\n" \
20464 _ASM_EXTABLE_EX(1b, 2b) \
20465 : ltype(x) : "m" (__m(addr)))
20466@@ -406,13 +456,24 @@ do { \
20467 int __gu_err; \
20468 unsigned long __gu_val; \
20469 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
20470- (x) = (__force __typeof__(*(ptr)))__gu_val; \
20471+ (x) = (__typeof__(*(ptr)))__gu_val; \
20472 __gu_err; \
20473 })
20474
20475 /* FIXME: this hack is definitely wrong -AK */
20476 struct __large_struct { unsigned long buf[100]; };
20477-#define __m(x) (*(struct __large_struct __user *)(x))
20478+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20479+#define ____m(x) \
20480+({ \
20481+ unsigned long ____x = (unsigned long)(x); \
20482+ if (____x < pax_user_shadow_base) \
20483+ ____x += pax_user_shadow_base; \
20484+ (typeof(x))____x; \
20485+})
20486+#else
20487+#define ____m(x) (x)
20488+#endif
20489+#define __m(x) (*(struct __large_struct __user *)____m(x))
20490
20491 /*
20492 * Tell gcc we read from memory instead of writing: this is because
20493@@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
20494 * aliasing issues.
20495 */
20496 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
20497+do { \
20498+ pax_open_userland(); \
20499 asm volatile(ASM_STAC "\n" \
20500- "1: mov"itype" %"rtype"1,%2\n" \
20501+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
20502 "2: " ASM_CLAC "\n" \
20503 ".section .fixup,\"ax\"\n" \
20504 "3: mov %3,%0\n" \
20505@@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
20506 ".previous\n" \
20507 _ASM_EXTABLE(1b, 3b) \
20508 : "=r"(err) \
20509- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
20510+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
20511+ pax_close_userland(); \
20512+} while (0)
20513
20514 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
20515- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
20516+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
20517 "2:\n" \
20518 _ASM_EXTABLE_EX(1b, 2b) \
20519 : : ltype(x), "m" (__m(addr)))
20520@@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
20521 */
20522 #define uaccess_try do { \
20523 current_thread_info()->uaccess_err = 0; \
20524+ pax_open_userland(); \
20525 stac(); \
20526 barrier();
20527
20528 #define uaccess_catch(err) \
20529 clac(); \
20530+ pax_close_userland(); \
20531 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
20532 } while (0)
20533
20534@@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
20535 * On error, the variable @x is set to zero.
20536 */
20537
20538+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20539+#define __get_user(x, ptr) get_user((x), (ptr))
20540+#else
20541 #define __get_user(x, ptr) \
20542 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
20543+#endif
20544
20545 /**
20546 * __put_user: - Write a simple value into user space, with less checking.
20547@@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
20548 * Returns zero on success, or -EFAULT on error.
20549 */
20550
20551+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
20552+#define __put_user(x, ptr) put_user((x), (ptr))
20553+#else
20554 #define __put_user(x, ptr) \
20555 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
20556+#endif
20557
20558 #define __get_user_unaligned __get_user
20559 #define __put_user_unaligned __put_user
20560@@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
20561 #define get_user_ex(x, ptr) do { \
20562 unsigned long __gue_val; \
20563 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
20564- (x) = (__force __typeof__(*(ptr)))__gue_val; \
20565+ (x) = (__typeof__(*(ptr)))__gue_val; \
20566 } while (0)
20567
20568 #define put_user_try uaccess_try
20569@@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
20570 __typeof__(ptr) __uval = (uval); \
20571 __typeof__(*(ptr)) __old = (old); \
20572 __typeof__(*(ptr)) __new = (new); \
20573+ pax_open_userland(); \
20574 switch (size) { \
20575 case 1: \
20576 { \
20577 asm volatile("\t" ASM_STAC "\n" \
20578- "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
20579+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
20580 "2:\t" ASM_CLAC "\n" \
20581 "\t.section .fixup, \"ax\"\n" \
20582 "3:\tmov %3, %0\n" \
20583 "\tjmp 2b\n" \
20584 "\t.previous\n" \
20585 _ASM_EXTABLE(1b, 3b) \
20586- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20587+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20588 : "i" (-EFAULT), "q" (__new), "1" (__old) \
20589 : "memory" \
20590 ); \
20591@@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
20592 case 2: \
20593 { \
20594 asm volatile("\t" ASM_STAC "\n" \
20595- "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
20596+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
20597 "2:\t" ASM_CLAC "\n" \
20598 "\t.section .fixup, \"ax\"\n" \
20599 "3:\tmov %3, %0\n" \
20600 "\tjmp 2b\n" \
20601 "\t.previous\n" \
20602 _ASM_EXTABLE(1b, 3b) \
20603- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20604+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20605 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20606 : "memory" \
20607 ); \
20608@@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
20609 case 4: \
20610 { \
20611 asm volatile("\t" ASM_STAC "\n" \
20612- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
20613+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
20614 "2:\t" ASM_CLAC "\n" \
20615 "\t.section .fixup, \"ax\"\n" \
20616 "3:\tmov %3, %0\n" \
20617 "\tjmp 2b\n" \
20618 "\t.previous\n" \
20619 _ASM_EXTABLE(1b, 3b) \
20620- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20621+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20622 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20623 : "memory" \
20624 ); \
20625@@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
20626 __cmpxchg_wrong_size(); \
20627 \
20628 asm volatile("\t" ASM_STAC "\n" \
20629- "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
20630+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
20631 "2:\t" ASM_CLAC "\n" \
20632 "\t.section .fixup, \"ax\"\n" \
20633 "3:\tmov %3, %0\n" \
20634 "\tjmp 2b\n" \
20635 "\t.previous\n" \
20636 _ASM_EXTABLE(1b, 3b) \
20637- : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
20638+ : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
20639 : "i" (-EFAULT), "r" (__new), "1" (__old) \
20640 : "memory" \
20641 ); \
20642@@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
20643 default: \
20644 __cmpxchg_wrong_size(); \
20645 } \
20646+ pax_close_userland(); \
20647 *__uval = __old; \
20648 __ret; \
20649 })
20650@@ -636,17 +713,6 @@ extern struct movsl_mask {
20651
20652 #define ARCH_HAS_NOCACHE_UACCESS 1
20653
20654-#ifdef CONFIG_X86_32
20655-# include <asm/uaccess_32.h>
20656-#else
20657-# include <asm/uaccess_64.h>
20658-#endif
20659-
20660-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
20661- unsigned n);
20662-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20663- unsigned n);
20664-
20665 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
20666 # define copy_user_diag __compiletime_error
20667 #else
20668@@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
20669 extern void copy_user_diag("copy_from_user() buffer size is too small")
20670 copy_from_user_overflow(void);
20671 extern void copy_user_diag("copy_to_user() buffer size is too small")
20672-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20673+copy_to_user_overflow(void);
20674
20675 #undef copy_user_diag
20676
20677@@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
20678
20679 extern void
20680 __compiletime_warning("copy_to_user() buffer size is not provably correct")
20681-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
20682+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
20683 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
20684
20685 #else
20686@@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
20687
20688 #endif
20689
20690+#ifdef CONFIG_X86_32
20691+# include <asm/uaccess_32.h>
20692+#else
20693+# include <asm/uaccess_64.h>
20694+#endif
20695+
20696 static inline unsigned long __must_check
20697 copy_from_user(void *to, const void __user *from, unsigned long n)
20698 {
20699- int sz = __compiletime_object_size(to);
20700+ size_t sz = __compiletime_object_size(to);
20701
20702 might_fault();
20703
20704@@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20705 * case, and do only runtime checking for non-constant sizes.
20706 */
20707
20708- if (likely(sz < 0 || sz >= n))
20709- n = _copy_from_user(to, from, n);
20710- else if(__builtin_constant_p(n))
20711- copy_from_user_overflow();
20712- else
20713- __copy_from_user_overflow(sz, n);
20714+ if (likely(sz != (size_t)-1 && sz < n)) {
20715+ if(__builtin_constant_p(n))
20716+ copy_from_user_overflow();
20717+ else
20718+ __copy_from_user_overflow(sz, n);
20719+ } else if (access_ok(VERIFY_READ, from, n))
20720+ n = __copy_from_user(to, from, n);
20721+ else if ((long)n > 0)
20722+ memset(to, 0, n);
20723
20724 return n;
20725 }
20726@@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
20727 static inline unsigned long __must_check
20728 copy_to_user(void __user *to, const void *from, unsigned long n)
20729 {
20730- int sz = __compiletime_object_size(from);
20731+ size_t sz = __compiletime_object_size(from);
20732
20733 might_fault();
20734
20735 /* See the comment in copy_from_user() above. */
20736- if (likely(sz < 0 || sz >= n))
20737- n = _copy_to_user(to, from, n);
20738- else if(__builtin_constant_p(n))
20739- copy_to_user_overflow();
20740- else
20741- __copy_to_user_overflow(sz, n);
20742+ if (likely(sz != (size_t)-1 && sz < n)) {
20743+ if(__builtin_constant_p(n))
20744+ copy_to_user_overflow();
20745+ else
20746+ __copy_to_user_overflow(sz, n);
20747+ } else if (access_ok(VERIFY_WRITE, to, n))
20748+ n = __copy_to_user(to, from, n);
20749
20750 return n;
20751 }
20752diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
20753index 3c03a5d..1071638 100644
20754--- a/arch/x86/include/asm/uaccess_32.h
20755+++ b/arch/x86/include/asm/uaccess_32.h
20756@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
20757 static __always_inline unsigned long __must_check
20758 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
20759 {
20760+ if ((long)n < 0)
20761+ return n;
20762+
20763+ check_object_size(from, n, true);
20764+
20765 if (__builtin_constant_p(n)) {
20766 unsigned long ret;
20767
20768@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
20769 __copy_to_user(void __user *to, const void *from, unsigned long n)
20770 {
20771 might_fault();
20772+
20773 return __copy_to_user_inatomic(to, from, n);
20774 }
20775
20776 static __always_inline unsigned long
20777 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
20778 {
20779+ if ((long)n < 0)
20780+ return n;
20781+
20782 /* Avoid zeroing the tail if the copy fails..
20783 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
20784 * but as the zeroing behaviour is only significant when n is not
20785@@ -137,6 +146,12 @@ static __always_inline unsigned long
20786 __copy_from_user(void *to, const void __user *from, unsigned long n)
20787 {
20788 might_fault();
20789+
20790+ if ((long)n < 0)
20791+ return n;
20792+
20793+ check_object_size(to, n, false);
20794+
20795 if (__builtin_constant_p(n)) {
20796 unsigned long ret;
20797
20798@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
20799 const void __user *from, unsigned long n)
20800 {
20801 might_fault();
20802+
20803+ if ((long)n < 0)
20804+ return n;
20805+
20806 if (__builtin_constant_p(n)) {
20807 unsigned long ret;
20808
20809@@ -181,7 +200,10 @@ static __always_inline unsigned long
20810 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
20811 unsigned long n)
20812 {
20813- return __copy_from_user_ll_nocache_nozero(to, from, n);
20814+ if ((long)n < 0)
20815+ return n;
20816+
20817+ return __copy_from_user_ll_nocache_nozero(to, from, n);
20818 }
20819
20820 #endif /* _ASM_X86_UACCESS_32_H */
20821diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
20822index 12a26b9..206c200 100644
20823--- a/arch/x86/include/asm/uaccess_64.h
20824+++ b/arch/x86/include/asm/uaccess_64.h
20825@@ -10,6 +10,9 @@
20826 #include <asm/alternative.h>
20827 #include <asm/cpufeature.h>
20828 #include <asm/page.h>
20829+#include <asm/pgtable.h>
20830+
20831+#define set_fs(x) (current_thread_info()->addr_limit = (x))
20832
20833 /*
20834 * Copy To/From Userspace
20835@@ -17,14 +20,14 @@
20836
20837 /* Handles exceptions in both to and from, but doesn't do access_ok */
20838 __must_check unsigned long
20839-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
20840+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
20841 __must_check unsigned long
20842-copy_user_generic_string(void *to, const void *from, unsigned len);
20843+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
20844 __must_check unsigned long
20845-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
20846+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
20847
20848 static __always_inline __must_check unsigned long
20849-copy_user_generic(void *to, const void *from, unsigned len)
20850+copy_user_generic(void *to, const void *from, unsigned long len)
20851 {
20852 unsigned ret;
20853
20854@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
20855 }
20856
20857 __must_check unsigned long
20858-copy_in_user(void __user *to, const void __user *from, unsigned len);
20859+copy_in_user(void __user *to, const void __user *from, unsigned long len);
20860
20861 static __always_inline __must_check
20862-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
20863+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
20864 {
20865- int ret = 0;
20866+ size_t sz = __compiletime_object_size(dst);
20867+ unsigned ret = 0;
20868+
20869+ if (size > INT_MAX)
20870+ return size;
20871+
20872+ check_object_size(dst, size, false);
20873+
20874+#ifdef CONFIG_PAX_MEMORY_UDEREF
20875+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20876+ return size;
20877+#endif
20878+
20879+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20880+ if(__builtin_constant_p(size))
20881+ copy_from_user_overflow();
20882+ else
20883+ __copy_from_user_overflow(sz, size);
20884+ return size;
20885+ }
20886
20887 if (!__builtin_constant_p(size))
20888- return copy_user_generic(dst, (__force void *)src, size);
20889+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20890 switch (size) {
20891- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
20892+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
20893 ret, "b", "b", "=q", 1);
20894 return ret;
20895- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
20896+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
20897 ret, "w", "w", "=r", 2);
20898 return ret;
20899- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
20900+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
20901 ret, "l", "k", "=r", 4);
20902 return ret;
20903- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
20904+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20905 ret, "q", "", "=r", 8);
20906 return ret;
20907 case 10:
20908- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20909+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20910 ret, "q", "", "=r", 10);
20911 if (unlikely(ret))
20912 return ret;
20913 __get_user_asm(*(u16 *)(8 + (char *)dst),
20914- (u16 __user *)(8 + (char __user *)src),
20915+ (const u16 __user *)(8 + (const char __user *)src),
20916 ret, "w", "w", "=r", 2);
20917 return ret;
20918 case 16:
20919- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
20920+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
20921 ret, "q", "", "=r", 16);
20922 if (unlikely(ret))
20923 return ret;
20924 __get_user_asm(*(u64 *)(8 + (char *)dst),
20925- (u64 __user *)(8 + (char __user *)src),
20926+ (const u64 __user *)(8 + (const char __user *)src),
20927 ret, "q", "", "=r", 8);
20928 return ret;
20929 default:
20930- return copy_user_generic(dst, (__force void *)src, size);
20931+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
20932 }
20933 }
20934
20935 static __always_inline __must_check
20936-int __copy_from_user(void *dst, const void __user *src, unsigned size)
20937+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
20938 {
20939 might_fault();
20940 return __copy_from_user_nocheck(dst, src, size);
20941 }
20942
20943 static __always_inline __must_check
20944-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
20945+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
20946 {
20947- int ret = 0;
20948+ size_t sz = __compiletime_object_size(src);
20949+ unsigned ret = 0;
20950+
20951+ if (size > INT_MAX)
20952+ return size;
20953+
20954+ check_object_size(src, size, true);
20955+
20956+#ifdef CONFIG_PAX_MEMORY_UDEREF
20957+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20958+ return size;
20959+#endif
20960+
20961+ if (unlikely(sz != (size_t)-1 && sz < size)) {
20962+ if(__builtin_constant_p(size))
20963+ copy_to_user_overflow();
20964+ else
20965+ __copy_to_user_overflow(sz, size);
20966+ return size;
20967+ }
20968
20969 if (!__builtin_constant_p(size))
20970- return copy_user_generic((__force void *)dst, src, size);
20971+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20972 switch (size) {
20973- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20974+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20975 ret, "b", "b", "iq", 1);
20976 return ret;
20977- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20978+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20979 ret, "w", "w", "ir", 2);
20980 return ret;
20981- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20982+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20983 ret, "l", "k", "ir", 4);
20984 return ret;
20985- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20986+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20987 ret, "q", "", "er", 8);
20988 return ret;
20989 case 10:
20990- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20991+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20992 ret, "q", "", "er", 10);
20993 if (unlikely(ret))
20994 return ret;
20995 asm("":::"memory");
20996- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20997+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20998 ret, "w", "w", "ir", 2);
20999 return ret;
21000 case 16:
21001- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
21002+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
21003 ret, "q", "", "er", 16);
21004 if (unlikely(ret))
21005 return ret;
21006 asm("":::"memory");
21007- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
21008+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
21009 ret, "q", "", "er", 8);
21010 return ret;
21011 default:
21012- return copy_user_generic((__force void *)dst, src, size);
21013+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
21014 }
21015 }
21016
21017 static __always_inline __must_check
21018-int __copy_to_user(void __user *dst, const void *src, unsigned size)
21019+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
21020 {
21021 might_fault();
21022 return __copy_to_user_nocheck(dst, src, size);
21023 }
21024
21025 static __always_inline __must_check
21026-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21027+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21028 {
21029- int ret = 0;
21030+ unsigned ret = 0;
21031
21032 might_fault();
21033+
21034+ if (size > INT_MAX)
21035+ return size;
21036+
21037+#ifdef CONFIG_PAX_MEMORY_UDEREF
21038+ if (!access_ok_noprefault(VERIFY_READ, src, size))
21039+ return size;
21040+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
21041+ return size;
21042+#endif
21043+
21044 if (!__builtin_constant_p(size))
21045- return copy_user_generic((__force void *)dst,
21046- (__force void *)src, size);
21047+ return copy_user_generic((__force_kernel void *)____m(dst),
21048+ (__force_kernel const void *)____m(src), size);
21049 switch (size) {
21050 case 1: {
21051 u8 tmp;
21052- __get_user_asm(tmp, (u8 __user *)src,
21053+ __get_user_asm(tmp, (const u8 __user *)src,
21054 ret, "b", "b", "=q", 1);
21055 if (likely(!ret))
21056 __put_user_asm(tmp, (u8 __user *)dst,
21057@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21058 }
21059 case 2: {
21060 u16 tmp;
21061- __get_user_asm(tmp, (u16 __user *)src,
21062+ __get_user_asm(tmp, (const u16 __user *)src,
21063 ret, "w", "w", "=r", 2);
21064 if (likely(!ret))
21065 __put_user_asm(tmp, (u16 __user *)dst,
21066@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21067
21068 case 4: {
21069 u32 tmp;
21070- __get_user_asm(tmp, (u32 __user *)src,
21071+ __get_user_asm(tmp, (const u32 __user *)src,
21072 ret, "l", "k", "=r", 4);
21073 if (likely(!ret))
21074 __put_user_asm(tmp, (u32 __user *)dst,
21075@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21076 }
21077 case 8: {
21078 u64 tmp;
21079- __get_user_asm(tmp, (u64 __user *)src,
21080+ __get_user_asm(tmp, (const u64 __user *)src,
21081 ret, "q", "", "=r", 8);
21082 if (likely(!ret))
21083 __put_user_asm(tmp, (u64 __user *)dst,
21084@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
21085 return ret;
21086 }
21087 default:
21088- return copy_user_generic((__force void *)dst,
21089- (__force void *)src, size);
21090+ return copy_user_generic((__force_kernel void *)____m(dst),
21091+ (__force_kernel const void *)____m(src), size);
21092 }
21093 }
21094
21095-static __must_check __always_inline int
21096-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
21097+static __must_check __always_inline unsigned long
21098+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
21099 {
21100 return __copy_from_user_nocheck(dst, src, size);
21101 }
21102
21103-static __must_check __always_inline int
21104-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
21105+static __must_check __always_inline unsigned long
21106+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
21107 {
21108 return __copy_to_user_nocheck(dst, src, size);
21109 }
21110
21111-extern long __copy_user_nocache(void *dst, const void __user *src,
21112- unsigned size, int zerorest);
21113+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
21114+ unsigned long size, int zerorest);
21115
21116-static inline int
21117-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
21118+static inline unsigned long
21119+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
21120 {
21121 might_fault();
21122+
21123+ if (size > INT_MAX)
21124+ return size;
21125+
21126+#ifdef CONFIG_PAX_MEMORY_UDEREF
21127+ if (!access_ok_noprefault(VERIFY_READ, src, size))
21128+ return size;
21129+#endif
21130+
21131 return __copy_user_nocache(dst, src, size, 1);
21132 }
21133
21134-static inline int
21135+static inline unsigned long
21136 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
21137- unsigned size)
21138+ unsigned long size)
21139 {
21140+ if (size > INT_MAX)
21141+ return size;
21142+
21143+#ifdef CONFIG_PAX_MEMORY_UDEREF
21144+ if (!access_ok_noprefault(VERIFY_READ, src, size))
21145+ return size;
21146+#endif
21147+
21148 return __copy_user_nocache(dst, src, size, 0);
21149 }
21150
21151 unsigned long
21152-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
21153+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
21154
21155 #endif /* _ASM_X86_UACCESS_64_H */
21156diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
21157index 5b238981..77fdd78 100644
21158--- a/arch/x86/include/asm/word-at-a-time.h
21159+++ b/arch/x86/include/asm/word-at-a-time.h
21160@@ -11,7 +11,7 @@
21161 * and shift, for example.
21162 */
21163 struct word_at_a_time {
21164- const unsigned long one_bits, high_bits;
21165+ unsigned long one_bits, high_bits;
21166 };
21167
21168 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
21169diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
21170index e45e4da..44e8572 100644
21171--- a/arch/x86/include/asm/x86_init.h
21172+++ b/arch/x86/include/asm/x86_init.h
21173@@ -129,7 +129,7 @@ struct x86_init_ops {
21174 struct x86_init_timers timers;
21175 struct x86_init_iommu iommu;
21176 struct x86_init_pci pci;
21177-};
21178+} __no_const;
21179
21180 /**
21181 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
21182@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
21183 void (*setup_percpu_clockev)(void);
21184 void (*early_percpu_clock_init)(void);
21185 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
21186-};
21187+} __no_const;
21188
21189 struct timespec;
21190
21191@@ -168,7 +168,7 @@ struct x86_platform_ops {
21192 void (*save_sched_clock_state)(void);
21193 void (*restore_sched_clock_state)(void);
21194 void (*apic_post_init)(void);
21195-};
21196+} __no_const;
21197
21198 struct pci_dev;
21199 struct msi_msg;
21200@@ -185,7 +185,7 @@ struct x86_msi_ops {
21201 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
21202 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
21203 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
21204-};
21205+} __no_const;
21206
21207 struct IO_APIC_route_entry;
21208 struct io_apic_irq_attr;
21209@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
21210 unsigned int destination, int vector,
21211 struct io_apic_irq_attr *attr);
21212 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
21213-};
21214+} __no_const;
21215
21216 extern struct x86_init_ops x86_init;
21217 extern struct x86_cpuinit_ops x86_cpuinit;
21218diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
21219index c949923..c22bfa4 100644
21220--- a/arch/x86/include/asm/xen/page.h
21221+++ b/arch/x86/include/asm/xen/page.h
21222@@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
21223 extern struct page *m2p_find_override(unsigned long mfn);
21224 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
21225
21226-static inline unsigned long pfn_to_mfn(unsigned long pfn)
21227+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
21228 {
21229 unsigned long mfn;
21230
21231diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
21232index 7e7a79a..0824666 100644
21233--- a/arch/x86/include/asm/xsave.h
21234+++ b/arch/x86/include/asm/xsave.h
21235@@ -228,12 +228,16 @@ static inline int xsave_user(struct xsave_struct __user *buf)
21236 if (unlikely(err))
21237 return -EFAULT;
21238
21239+ pax_open_userland();
21240 __asm__ __volatile__(ASM_STAC "\n"
21241- "1:"XSAVE"\n"
21242+ "1:"
21243+ __copyuser_seg
21244+ XSAVE"\n"
21245 "2: " ASM_CLAC "\n"
21246 xstate_fault
21247 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
21248 : "memory");
21249+ pax_close_userland();
21250 return err;
21251 }
21252
21253@@ -243,16 +247,20 @@ static inline int xsave_user(struct xsave_struct __user *buf)
21254 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
21255 {
21256 int err = 0;
21257- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
21258+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
21259 u32 lmask = mask;
21260 u32 hmask = mask >> 32;
21261
21262+ pax_open_userland();
21263 __asm__ __volatile__(ASM_STAC "\n"
21264- "1:"XRSTOR"\n"
21265+ "1:"
21266+ __copyuser_seg
21267+ XRSTOR"\n"
21268 "2: " ASM_CLAC "\n"
21269 xstate_fault
21270 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
21271 : "memory"); /* memory required? */
21272+ pax_close_userland();
21273 return err;
21274 }
21275
21276diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
21277index bbae024..e1528f9 100644
21278--- a/arch/x86/include/uapi/asm/e820.h
21279+++ b/arch/x86/include/uapi/asm/e820.h
21280@@ -63,7 +63,7 @@ struct e820map {
21281 #define ISA_START_ADDRESS 0xa0000
21282 #define ISA_END_ADDRESS 0x100000
21283
21284-#define BIOS_BEGIN 0x000a0000
21285+#define BIOS_BEGIN 0x000c0000
21286 #define BIOS_END 0x00100000
21287
21288 #define BIOS_ROM_BASE 0xffe00000
21289diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
21290index 7b0a55a..ad115bf 100644
21291--- a/arch/x86/include/uapi/asm/ptrace-abi.h
21292+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
21293@@ -49,7 +49,6 @@
21294 #define EFLAGS 144
21295 #define RSP 152
21296 #define SS 160
21297-#define ARGOFFSET R11
21298 #endif /* __ASSEMBLY__ */
21299
21300 /* top of stack page */
21301diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
21302index ada2e2d..ca69e16 100644
21303--- a/arch/x86/kernel/Makefile
21304+++ b/arch/x86/kernel/Makefile
21305@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
21306 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
21307 obj-$(CONFIG_IRQ_WORK) += irq_work.o
21308 obj-y += probe_roms.o
21309-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
21310+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
21311 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
21312 obj-$(CONFIG_X86_64) += mcount_64.o
21313 obj-y += syscall_$(BITS).o vsyscall_gtod.o
21314diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
21315index a142e77..6222cdd 100644
21316--- a/arch/x86/kernel/acpi/boot.c
21317+++ b/arch/x86/kernel/acpi/boot.c
21318@@ -1276,7 +1276,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
21319 * If your system is blacklisted here, but you find that acpi=force
21320 * works for you, please contact linux-acpi@vger.kernel.org
21321 */
21322-static struct dmi_system_id __initdata acpi_dmi_table[] = {
21323+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
21324 /*
21325 * Boxes that need ACPI disabled
21326 */
21327@@ -1351,7 +1351,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
21328 };
21329
21330 /* second table for DMI checks that should run after early-quirks */
21331-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
21332+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
21333 /*
21334 * HP laptops which use a DSDT reporting as HP/SB400/10000,
21335 * which includes some code which overrides all temperature
21336diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
21337index 3136820..e2c6577 100644
21338--- a/arch/x86/kernel/acpi/sleep.c
21339+++ b/arch/x86/kernel/acpi/sleep.c
21340@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
21341 #else /* CONFIG_64BIT */
21342 #ifdef CONFIG_SMP
21343 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
21344+
21345+ pax_open_kernel();
21346 early_gdt_descr.address =
21347 (unsigned long)get_cpu_gdt_table(smp_processor_id());
21348+ pax_close_kernel();
21349+
21350 initial_gs = per_cpu_offset(smp_processor_id());
21351 #endif
21352 initial_code = (unsigned long)wakeup_long64;
21353diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
21354index 665c6b7..eae4d56 100644
21355--- a/arch/x86/kernel/acpi/wakeup_32.S
21356+++ b/arch/x86/kernel/acpi/wakeup_32.S
21357@@ -29,13 +29,11 @@ wakeup_pmode_return:
21358 # and restore the stack ... but you need gdt for this to work
21359 movl saved_context_esp, %esp
21360
21361- movl %cs:saved_magic, %eax
21362- cmpl $0x12345678, %eax
21363+ cmpl $0x12345678, saved_magic
21364 jne bogus_magic
21365
21366 # jump to place where we left off
21367- movl saved_eip, %eax
21368- jmp *%eax
21369+ jmp *(saved_eip)
21370
21371 bogus_magic:
21372 jmp bogus_magic
21373diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
21374index 703130f..27a155d 100644
21375--- a/arch/x86/kernel/alternative.c
21376+++ b/arch/x86/kernel/alternative.c
21377@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
21378 */
21379 for (a = start; a < end; a++) {
21380 instr = (u8 *)&a->instr_offset + a->instr_offset;
21381+
21382+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21383+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21384+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
21385+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21386+#endif
21387+
21388 replacement = (u8 *)&a->repl_offset + a->repl_offset;
21389 BUG_ON(a->replacementlen > a->instrlen);
21390 BUG_ON(a->instrlen > sizeof(insnbuf));
21391@@ -284,6 +291,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
21392 add_nops(insnbuf + a->replacementlen,
21393 a->instrlen - a->replacementlen);
21394
21395+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21396+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
21397+ instr = ktva_ktla(instr);
21398+#endif
21399+
21400 text_poke_early(instr, insnbuf, a->instrlen);
21401 }
21402 }
21403@@ -299,10 +311,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
21404 for (poff = start; poff < end; poff++) {
21405 u8 *ptr = (u8 *)poff + *poff;
21406
21407+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21408+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21409+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
21410+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21411+#endif
21412+
21413 if (!*poff || ptr < text || ptr >= text_end)
21414 continue;
21415 /* turn DS segment override prefix into lock prefix */
21416- if (*ptr == 0x3e)
21417+ if (*ktla_ktva(ptr) == 0x3e)
21418 text_poke(ptr, ((unsigned char []){0xf0}), 1);
21419 }
21420 mutex_unlock(&text_mutex);
21421@@ -317,10 +335,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
21422 for (poff = start; poff < end; poff++) {
21423 u8 *ptr = (u8 *)poff + *poff;
21424
21425+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21426+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21427+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
21428+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
21429+#endif
21430+
21431 if (!*poff || ptr < text || ptr >= text_end)
21432 continue;
21433 /* turn lock prefix into DS segment override prefix */
21434- if (*ptr == 0xf0)
21435+ if (*ktla_ktva(ptr) == 0xf0)
21436 text_poke(ptr, ((unsigned char []){0x3E}), 1);
21437 }
21438 mutex_unlock(&text_mutex);
21439@@ -457,7 +481,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
21440
21441 BUG_ON(p->len > MAX_PATCH_LEN);
21442 /* prep the buffer with the original instructions */
21443- memcpy(insnbuf, p->instr, p->len);
21444+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
21445 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
21446 (unsigned long)p->instr, p->len);
21447
21448@@ -504,7 +528,7 @@ void __init alternative_instructions(void)
21449 if (!uniproc_patched || num_possible_cpus() == 1)
21450 free_init_pages("SMP alternatives",
21451 (unsigned long)__smp_locks,
21452- (unsigned long)__smp_locks_end);
21453+ PAGE_ALIGN((unsigned long)__smp_locks_end));
21454 #endif
21455
21456 apply_paravirt(__parainstructions, __parainstructions_end);
21457@@ -524,13 +548,17 @@ void __init alternative_instructions(void)
21458 * instructions. And on the local CPU you need to be protected again NMI or MCE
21459 * handlers seeing an inconsistent instruction while you patch.
21460 */
21461-void *__init_or_module text_poke_early(void *addr, const void *opcode,
21462+void *__kprobes text_poke_early(void *addr, const void *opcode,
21463 size_t len)
21464 {
21465 unsigned long flags;
21466 local_irq_save(flags);
21467- memcpy(addr, opcode, len);
21468+
21469+ pax_open_kernel();
21470+ memcpy(ktla_ktva(addr), opcode, len);
21471 sync_core();
21472+ pax_close_kernel();
21473+
21474 local_irq_restore(flags);
21475 /* Could also do a CLFLUSH here to speed up CPU recovery; but
21476 that causes hangs on some VIA CPUs. */
21477@@ -552,36 +580,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
21478 */
21479 void *text_poke(void *addr, const void *opcode, size_t len)
21480 {
21481- unsigned long flags;
21482- char *vaddr;
21483+ unsigned char *vaddr = ktla_ktva(addr);
21484 struct page *pages[2];
21485- int i;
21486+ size_t i;
21487
21488 if (!core_kernel_text((unsigned long)addr)) {
21489- pages[0] = vmalloc_to_page(addr);
21490- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
21491+ pages[0] = vmalloc_to_page(vaddr);
21492+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
21493 } else {
21494- pages[0] = virt_to_page(addr);
21495+ pages[0] = virt_to_page(vaddr);
21496 WARN_ON(!PageReserved(pages[0]));
21497- pages[1] = virt_to_page(addr + PAGE_SIZE);
21498+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
21499 }
21500 BUG_ON(!pages[0]);
21501- local_irq_save(flags);
21502- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
21503- if (pages[1])
21504- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
21505- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
21506- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
21507- clear_fixmap(FIX_TEXT_POKE0);
21508- if (pages[1])
21509- clear_fixmap(FIX_TEXT_POKE1);
21510- local_flush_tlb();
21511- sync_core();
21512- /* Could also do a CLFLUSH here to speed up CPU recovery; but
21513- that causes hangs on some VIA CPUs. */
21514+ text_poke_early(addr, opcode, len);
21515 for (i = 0; i < len; i++)
21516- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
21517- local_irq_restore(flags);
21518+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
21519 return addr;
21520 }
21521
21522@@ -601,7 +615,7 @@ int poke_int3_handler(struct pt_regs *regs)
21523 if (likely(!bp_patching_in_progress))
21524 return 0;
21525
21526- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
21527+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
21528 return 0;
21529
21530 /* set up the specified breakpoint handler */
21531@@ -635,7 +649,7 @@ int poke_int3_handler(struct pt_regs *regs)
21532 */
21533 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
21534 {
21535- unsigned char int3 = 0xcc;
21536+ const unsigned char int3 = 0xcc;
21537
21538 bp_int3_handler = handler;
21539 bp_int3_addr = (u8 *)addr + sizeof(int3);
21540diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
21541index 24b5894..6d9701b 100644
21542--- a/arch/x86/kernel/apic/apic.c
21543+++ b/arch/x86/kernel/apic/apic.c
21544@@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
21545 /*
21546 * Debug level, exported for io_apic.c
21547 */
21548-unsigned int apic_verbosity;
21549+int apic_verbosity;
21550
21551 int pic_mode;
21552
21553@@ -1989,7 +1989,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
21554 apic_write(APIC_ESR, 0);
21555 v = apic_read(APIC_ESR);
21556 ack_APIC_irq();
21557- atomic_inc(&irq_err_count);
21558+ atomic_inc_unchecked(&irq_err_count);
21559
21560 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
21561 smp_processor_id(), v);
21562diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
21563index de918c4..32eed23 100644
21564--- a/arch/x86/kernel/apic/apic_flat_64.c
21565+++ b/arch/x86/kernel/apic/apic_flat_64.c
21566@@ -154,7 +154,7 @@ static int flat_probe(void)
21567 return 1;
21568 }
21569
21570-static struct apic apic_flat = {
21571+static struct apic apic_flat __read_only = {
21572 .name = "flat",
21573 .probe = flat_probe,
21574 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
21575@@ -260,7 +260,7 @@ static int physflat_probe(void)
21576 return 0;
21577 }
21578
21579-static struct apic apic_physflat = {
21580+static struct apic apic_physflat __read_only = {
21581
21582 .name = "physical flat",
21583 .probe = physflat_probe,
21584diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
21585index b205cdb..d8503ff 100644
21586--- a/arch/x86/kernel/apic/apic_noop.c
21587+++ b/arch/x86/kernel/apic/apic_noop.c
21588@@ -108,7 +108,7 @@ static void noop_apic_write(u32 reg, u32 v)
21589 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
21590 }
21591
21592-struct apic apic_noop = {
21593+struct apic apic_noop __read_only = {
21594 .name = "noop",
21595 .probe = noop_probe,
21596 .acpi_madt_oem_check = NULL,
21597diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
21598index c4a8d63..fe893ac 100644
21599--- a/arch/x86/kernel/apic/bigsmp_32.c
21600+++ b/arch/x86/kernel/apic/bigsmp_32.c
21601@@ -147,7 +147,7 @@ static int probe_bigsmp(void)
21602 return dmi_bigsmp;
21603 }
21604
21605-static struct apic apic_bigsmp = {
21606+static struct apic apic_bigsmp __read_only = {
21607
21608 .name = "bigsmp",
21609 .probe = probe_bigsmp,
21610diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
21611index 337ce5a..c8d98b4 100644
21612--- a/arch/x86/kernel/apic/io_apic.c
21613+++ b/arch/x86/kernel/apic/io_apic.c
21614@@ -1230,7 +1230,7 @@ out:
21615 }
21616 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
21617
21618-void lock_vector_lock(void)
21619+void lock_vector_lock(void) __acquires(vector_lock)
21620 {
21621 /* Used to the online set of cpus does not change
21622 * during assign_irq_vector.
21623@@ -1238,7 +1238,7 @@ void lock_vector_lock(void)
21624 raw_spin_lock(&vector_lock);
21625 }
21626
21627-void unlock_vector_lock(void)
21628+void unlock_vector_lock(void) __releases(vector_lock)
21629 {
21630 raw_spin_unlock(&vector_lock);
21631 }
21632@@ -2465,7 +2465,7 @@ static void ack_apic_edge(struct irq_data *data)
21633 ack_APIC_irq();
21634 }
21635
21636-atomic_t irq_mis_count;
21637+atomic_unchecked_t irq_mis_count;
21638
21639 #ifdef CONFIG_GENERIC_PENDING_IRQ
21640 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
21641@@ -2606,7 +2606,7 @@ static void ack_apic_level(struct irq_data *data)
21642 * at the cpu.
21643 */
21644 if (!(v & (1 << (i & 0x1f)))) {
21645- atomic_inc(&irq_mis_count);
21646+ atomic_inc_unchecked(&irq_mis_count);
21647
21648 eoi_ioapic_irq(irq, cfg);
21649 }
21650diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
21651index bda4886..f9c7195 100644
21652--- a/arch/x86/kernel/apic/probe_32.c
21653+++ b/arch/x86/kernel/apic/probe_32.c
21654@@ -72,7 +72,7 @@ static int probe_default(void)
21655 return 1;
21656 }
21657
21658-static struct apic apic_default = {
21659+static struct apic apic_default __read_only = {
21660
21661 .name = "default",
21662 .probe = probe_default,
21663diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
21664index 6ce600f..cb44af8 100644
21665--- a/arch/x86/kernel/apic/x2apic_cluster.c
21666+++ b/arch/x86/kernel/apic/x2apic_cluster.c
21667@@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
21668 return notifier_from_errno(err);
21669 }
21670
21671-static struct notifier_block __refdata x2apic_cpu_notifier = {
21672+static struct notifier_block x2apic_cpu_notifier = {
21673 .notifier_call = update_clusterinfo,
21674 };
21675
21676@@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
21677 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
21678 }
21679
21680-static struct apic apic_x2apic_cluster = {
21681+static struct apic apic_x2apic_cluster __read_only = {
21682
21683 .name = "cluster x2apic",
21684 .probe = x2apic_cluster_probe,
21685diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
21686index 6fae733..5ca17af 100644
21687--- a/arch/x86/kernel/apic/x2apic_phys.c
21688+++ b/arch/x86/kernel/apic/x2apic_phys.c
21689@@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
21690 return apic == &apic_x2apic_phys;
21691 }
21692
21693-static struct apic apic_x2apic_phys = {
21694+static struct apic apic_x2apic_phys __read_only = {
21695
21696 .name = "physical x2apic",
21697 .probe = x2apic_phys_probe,
21698diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
21699index 004f017..8fbc8b5 100644
21700--- a/arch/x86/kernel/apic/x2apic_uv_x.c
21701+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
21702@@ -350,7 +350,7 @@ static int uv_probe(void)
21703 return apic == &apic_x2apic_uv_x;
21704 }
21705
21706-static struct apic __refdata apic_x2apic_uv_x = {
21707+static struct apic apic_x2apic_uv_x __read_only = {
21708
21709 .name = "UV large system",
21710 .probe = uv_probe,
21711diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
21712index 5848744..56cb598 100644
21713--- a/arch/x86/kernel/apm_32.c
21714+++ b/arch/x86/kernel/apm_32.c
21715@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
21716 * This is for buggy BIOS's that refer to (real mode) segment 0x40
21717 * even though they are called in protected mode.
21718 */
21719-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
21720+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
21721 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
21722
21723 static const char driver_version[] = "1.16ac"; /* no spaces */
21724@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
21725 BUG_ON(cpu != 0);
21726 gdt = get_cpu_gdt_table(cpu);
21727 save_desc_40 = gdt[0x40 / 8];
21728+
21729+ pax_open_kernel();
21730 gdt[0x40 / 8] = bad_bios_desc;
21731+ pax_close_kernel();
21732
21733 apm_irq_save(flags);
21734 APM_DO_SAVE_SEGS;
21735@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
21736 &call->esi);
21737 APM_DO_RESTORE_SEGS;
21738 apm_irq_restore(flags);
21739+
21740+ pax_open_kernel();
21741 gdt[0x40 / 8] = save_desc_40;
21742+ pax_close_kernel();
21743+
21744 put_cpu();
21745
21746 return call->eax & 0xff;
21747@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
21748 BUG_ON(cpu != 0);
21749 gdt = get_cpu_gdt_table(cpu);
21750 save_desc_40 = gdt[0x40 / 8];
21751+
21752+ pax_open_kernel();
21753 gdt[0x40 / 8] = bad_bios_desc;
21754+ pax_close_kernel();
21755
21756 apm_irq_save(flags);
21757 APM_DO_SAVE_SEGS;
21758@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
21759 &call->eax);
21760 APM_DO_RESTORE_SEGS;
21761 apm_irq_restore(flags);
21762+
21763+ pax_open_kernel();
21764 gdt[0x40 / 8] = save_desc_40;
21765+ pax_close_kernel();
21766+
21767 put_cpu();
21768 return error;
21769 }
21770@@ -2350,12 +2364,15 @@ static int __init apm_init(void)
21771 * code to that CPU.
21772 */
21773 gdt = get_cpu_gdt_table(0);
21774+
21775+ pax_open_kernel();
21776 set_desc_base(&gdt[APM_CS >> 3],
21777 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
21778 set_desc_base(&gdt[APM_CS_16 >> 3],
21779 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
21780 set_desc_base(&gdt[APM_DS >> 3],
21781 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
21782+ pax_close_kernel();
21783
21784 proc_create("apm", 0, NULL, &apm_file_ops);
21785
21786diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
21787index 9f6b934..cf5ffb3 100644
21788--- a/arch/x86/kernel/asm-offsets.c
21789+++ b/arch/x86/kernel/asm-offsets.c
21790@@ -32,6 +32,8 @@ void common(void) {
21791 OFFSET(TI_flags, thread_info, flags);
21792 OFFSET(TI_status, thread_info, status);
21793 OFFSET(TI_addr_limit, thread_info, addr_limit);
21794+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
21795+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
21796
21797 BLANK();
21798 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
21799@@ -52,8 +54,26 @@ void common(void) {
21800 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
21801 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
21802 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
21803+
21804+#ifdef CONFIG_PAX_KERNEXEC
21805+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
21806 #endif
21807
21808+#ifdef CONFIG_PAX_MEMORY_UDEREF
21809+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
21810+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
21811+#ifdef CONFIG_X86_64
21812+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
21813+#endif
21814+#endif
21815+
21816+#endif
21817+
21818+ BLANK();
21819+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
21820+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
21821+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
21822+
21823 #ifdef CONFIG_XEN
21824 BLANK();
21825 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
21826diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
21827index e7c798b..2b2019b 100644
21828--- a/arch/x86/kernel/asm-offsets_64.c
21829+++ b/arch/x86/kernel/asm-offsets_64.c
21830@@ -77,6 +77,7 @@ int main(void)
21831 BLANK();
21832 #undef ENTRY
21833
21834+ DEFINE(TSS_size, sizeof(struct tss_struct));
21835 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
21836 BLANK();
21837
21838diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
21839index 7fd54f0..0691410 100644
21840--- a/arch/x86/kernel/cpu/Makefile
21841+++ b/arch/x86/kernel/cpu/Makefile
21842@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
21843 CFLAGS_REMOVE_perf_event.o = -pg
21844 endif
21845
21846-# Make sure load_percpu_segment has no stackprotector
21847-nostackp := $(call cc-option, -fno-stack-protector)
21848-CFLAGS_common.o := $(nostackp)
21849-
21850 obj-y := intel_cacheinfo.o scattered.o topology.o
21851 obj-y += proc.o capflags.o powerflags.o common.o
21852 obj-y += rdrand.o
21853diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
21854index 60e5497..8efbd2f 100644
21855--- a/arch/x86/kernel/cpu/amd.c
21856+++ b/arch/x86/kernel/cpu/amd.c
21857@@ -711,7 +711,7 @@ static void init_amd(struct cpuinfo_x86 *c)
21858 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
21859 {
21860 /* AMD errata T13 (order #21922) */
21861- if ((c->x86 == 6)) {
21862+ if (c->x86 == 6) {
21863 /* Duron Rev A0 */
21864 if (c->x86_model == 3 && c->x86_mask == 0)
21865 size = 64;
21866diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
21867index 3126558..a1028f6 100644
21868--- a/arch/x86/kernel/cpu/common.c
21869+++ b/arch/x86/kernel/cpu/common.c
21870@@ -90,60 +90,6 @@ static const struct cpu_dev default_cpu = {
21871
21872 static const struct cpu_dev *this_cpu = &default_cpu;
21873
21874-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
21875-#ifdef CONFIG_X86_64
21876- /*
21877- * We need valid kernel segments for data and code in long mode too
21878- * IRET will check the segment types kkeil 2000/10/28
21879- * Also sysret mandates a special GDT layout
21880- *
21881- * TLS descriptors are currently at a different place compared to i386.
21882- * Hopefully nobody expects them at a fixed place (Wine?)
21883- */
21884- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
21885- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
21886- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
21887- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
21888- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
21889- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
21890-#else
21891- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
21892- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21893- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
21894- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
21895- /*
21896- * Segments used for calling PnP BIOS have byte granularity.
21897- * They code segments and data segments have fixed 64k limits,
21898- * the transfer segment sizes are set at run time.
21899- */
21900- /* 32-bit code */
21901- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21902- /* 16-bit code */
21903- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21904- /* 16-bit data */
21905- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
21906- /* 16-bit data */
21907- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
21908- /* 16-bit data */
21909- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
21910- /*
21911- * The APM segments have byte granularity and their bases
21912- * are set at run time. All have 64k limits.
21913- */
21914- /* 32-bit code */
21915- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
21916- /* 16-bit code */
21917- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
21918- /* data */
21919- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
21920-
21921- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21922- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
21923- GDT_STACK_CANARY_INIT
21924-#endif
21925-} };
21926-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
21927-
21928 static int __init x86_xsave_setup(char *s)
21929 {
21930 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
21931@@ -303,6 +249,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
21932 }
21933 }
21934
21935+#ifdef CONFIG_X86_64
21936+static __init int setup_disable_pcid(char *arg)
21937+{
21938+ setup_clear_cpu_cap(X86_FEATURE_PCID);
21939+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
21940+
21941+#ifdef CONFIG_PAX_MEMORY_UDEREF
21942+ if (clone_pgd_mask != ~(pgdval_t)0UL)
21943+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21944+#endif
21945+
21946+ return 1;
21947+}
21948+__setup("nopcid", setup_disable_pcid);
21949+
21950+static void setup_pcid(struct cpuinfo_x86 *c)
21951+{
21952+ if (!cpu_has(c, X86_FEATURE_PCID)) {
21953+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
21954+
21955+#ifdef CONFIG_PAX_MEMORY_UDEREF
21956+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
21957+ pax_open_kernel();
21958+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
21959+ pax_close_kernel();
21960+ printk("PAX: slow and weak UDEREF enabled\n");
21961+ } else
21962+ printk("PAX: UDEREF disabled\n");
21963+#endif
21964+
21965+ return;
21966+ }
21967+
21968+ printk("PAX: PCID detected\n");
21969+ set_in_cr4(X86_CR4_PCIDE);
21970+
21971+#ifdef CONFIG_PAX_MEMORY_UDEREF
21972+ pax_open_kernel();
21973+ clone_pgd_mask = ~(pgdval_t)0UL;
21974+ pax_close_kernel();
21975+ if (pax_user_shadow_base)
21976+ printk("PAX: weak UDEREF enabled\n");
21977+ else {
21978+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21979+ printk("PAX: strong UDEREF enabled\n");
21980+ }
21981+#endif
21982+
21983+ if (cpu_has(c, X86_FEATURE_INVPCID))
21984+ printk("PAX: INVPCID detected\n");
21985+}
21986+#endif
21987+
21988 /*
21989 * Some CPU features depend on higher CPUID levels, which may not always
21990 * be available due to CPUID level capping or broken virtualization
21991@@ -403,7 +402,7 @@ void switch_to_new_gdt(int cpu)
21992 {
21993 struct desc_ptr gdt_descr;
21994
21995- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21996+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21997 gdt_descr.size = GDT_SIZE - 1;
21998 load_gdt(&gdt_descr);
21999 /* Reload the per-cpu base */
22000@@ -893,6 +892,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
22001 setup_smep(c);
22002 setup_smap(c);
22003
22004+#ifdef CONFIG_X86_64
22005+ setup_pcid(c);
22006+#endif
22007+
22008 /*
22009 * The vendor-specific functions might have changed features.
22010 * Now we do "generic changes."
22011@@ -901,6 +904,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
22012 /* Filter out anything that depends on CPUID levels we don't have */
22013 filter_cpuid_features(c, true);
22014
22015+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22016+ setup_clear_cpu_cap(X86_FEATURE_SEP);
22017+#endif
22018+
22019 /* If the model name is still unset, do table lookup. */
22020 if (!c->x86_model_id[0]) {
22021 const char *p;
22022@@ -981,7 +988,7 @@ static void syscall32_cpu_init(void)
22023 void enable_sep_cpu(void)
22024 {
22025 int cpu = get_cpu();
22026- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22027+ struct tss_struct *tss = init_tss + cpu;
22028
22029 if (!boot_cpu_has(X86_FEATURE_SEP)) {
22030 put_cpu();
22031@@ -1121,14 +1128,16 @@ static __init int setup_disablecpuid(char *arg)
22032 }
22033 __setup("clearcpuid=", setup_disablecpuid);
22034
22035+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
22036+EXPORT_PER_CPU_SYMBOL(current_tinfo);
22037+
22038 DEFINE_PER_CPU(unsigned long, kernel_stack) =
22039- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
22040+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
22041 EXPORT_PER_CPU_SYMBOL(kernel_stack);
22042
22043 #ifdef CONFIG_X86_64
22044-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
22045-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
22046- (unsigned long) debug_idt_table };
22047+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
22048+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
22049
22050 DEFINE_PER_CPU_FIRST(union irq_stack_union,
22051 irq_stack_union) __aligned(PAGE_SIZE) __visible;
22052@@ -1291,7 +1300,7 @@ void cpu_init(void)
22053 load_ucode_ap();
22054
22055 cpu = stack_smp_processor_id();
22056- t = &per_cpu(init_tss, cpu);
22057+ t = init_tss + cpu;
22058 oist = &per_cpu(orig_ist, cpu);
22059
22060 #ifdef CONFIG_NUMA
22061@@ -1326,7 +1335,6 @@ void cpu_init(void)
22062 wrmsrl(MSR_KERNEL_GS_BASE, 0);
22063 barrier();
22064
22065- x86_configure_nx();
22066 enable_x2apic();
22067
22068 /*
22069@@ -1378,7 +1386,7 @@ void cpu_init(void)
22070 {
22071 int cpu = smp_processor_id();
22072 struct task_struct *curr = current;
22073- struct tss_struct *t = &per_cpu(init_tss, cpu);
22074+ struct tss_struct *t = init_tss + cpu;
22075 struct thread_struct *thread = &curr->thread;
22076
22077 show_ucode_info_early();
22078diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
22079index c703507..28535e3 100644
22080--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
22081+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
22082@@ -1026,6 +1026,22 @@ static struct attribute *default_attrs[] = {
22083 };
22084
22085 #ifdef CONFIG_AMD_NB
22086+static struct attribute *default_attrs_amd_nb[] = {
22087+ &type.attr,
22088+ &level.attr,
22089+ &coherency_line_size.attr,
22090+ &physical_line_partition.attr,
22091+ &ways_of_associativity.attr,
22092+ &number_of_sets.attr,
22093+ &size.attr,
22094+ &shared_cpu_map.attr,
22095+ &shared_cpu_list.attr,
22096+ NULL,
22097+ NULL,
22098+ NULL,
22099+ NULL
22100+};
22101+
22102 static struct attribute **amd_l3_attrs(void)
22103 {
22104 static struct attribute **attrs;
22105@@ -1036,18 +1052,7 @@ static struct attribute **amd_l3_attrs(void)
22106
22107 n = ARRAY_SIZE(default_attrs);
22108
22109- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
22110- n += 2;
22111-
22112- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
22113- n += 1;
22114-
22115- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
22116- if (attrs == NULL)
22117- return attrs = default_attrs;
22118-
22119- for (n = 0; default_attrs[n]; n++)
22120- attrs[n] = default_attrs[n];
22121+ attrs = default_attrs_amd_nb;
22122
22123 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
22124 attrs[n++] = &cache_disable_0.attr;
22125@@ -1098,6 +1103,13 @@ static struct kobj_type ktype_cache = {
22126 .default_attrs = default_attrs,
22127 };
22128
22129+#ifdef CONFIG_AMD_NB
22130+static struct kobj_type ktype_cache_amd_nb = {
22131+ .sysfs_ops = &sysfs_ops,
22132+ .default_attrs = default_attrs_amd_nb,
22133+};
22134+#endif
22135+
22136 static struct kobj_type ktype_percpu_entry = {
22137 .sysfs_ops = &sysfs_ops,
22138 };
22139@@ -1163,20 +1175,26 @@ static int cache_add_dev(struct device *dev)
22140 return retval;
22141 }
22142
22143+#ifdef CONFIG_AMD_NB
22144+ amd_l3_attrs();
22145+#endif
22146+
22147 for (i = 0; i < num_cache_leaves; i++) {
22148+ struct kobj_type *ktype;
22149+
22150 this_object = INDEX_KOBJECT_PTR(cpu, i);
22151 this_object->cpu = cpu;
22152 this_object->index = i;
22153
22154 this_leaf = CPUID4_INFO_IDX(cpu, i);
22155
22156- ktype_cache.default_attrs = default_attrs;
22157+ ktype = &ktype_cache;
22158 #ifdef CONFIG_AMD_NB
22159 if (this_leaf->base.nb)
22160- ktype_cache.default_attrs = amd_l3_attrs();
22161+ ktype = &ktype_cache_amd_nb;
22162 #endif
22163 retval = kobject_init_and_add(&(this_object->kobj),
22164- &ktype_cache,
22165+ ktype,
22166 per_cpu(ici_cache_kobject, cpu),
22167 "index%1lu", i);
22168 if (unlikely(retval)) {
22169diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
22170index bd9ccda..38314e7 100644
22171--- a/arch/x86/kernel/cpu/mcheck/mce.c
22172+++ b/arch/x86/kernel/cpu/mcheck/mce.c
22173@@ -45,6 +45,7 @@
22174 #include <asm/processor.h>
22175 #include <asm/mce.h>
22176 #include <asm/msr.h>
22177+#include <asm/local.h>
22178
22179 #include "mce-internal.h"
22180
22181@@ -259,7 +260,7 @@ static void print_mce(struct mce *m)
22182 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
22183 m->cs, m->ip);
22184
22185- if (m->cs == __KERNEL_CS)
22186+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
22187 print_symbol("{%s}", m->ip);
22188 pr_cont("\n");
22189 }
22190@@ -292,10 +293,10 @@ static void print_mce(struct mce *m)
22191
22192 #define PANIC_TIMEOUT 5 /* 5 seconds */
22193
22194-static atomic_t mce_paniced;
22195+static atomic_unchecked_t mce_paniced;
22196
22197 static int fake_panic;
22198-static atomic_t mce_fake_paniced;
22199+static atomic_unchecked_t mce_fake_paniced;
22200
22201 /* Panic in progress. Enable interrupts and wait for final IPI */
22202 static void wait_for_panic(void)
22203@@ -319,7 +320,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
22204 /*
22205 * Make sure only one CPU runs in machine check panic
22206 */
22207- if (atomic_inc_return(&mce_paniced) > 1)
22208+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
22209 wait_for_panic();
22210 barrier();
22211
22212@@ -327,7 +328,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
22213 console_verbose();
22214 } else {
22215 /* Don't log too much for fake panic */
22216- if (atomic_inc_return(&mce_fake_paniced) > 1)
22217+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
22218 return;
22219 }
22220 /* First print corrected ones that are still unlogged */
22221@@ -366,7 +367,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
22222 if (!fake_panic) {
22223 if (panic_timeout == 0)
22224 panic_timeout = mca_cfg.panic_timeout;
22225- panic(msg);
22226+ panic("%s", msg);
22227 } else
22228 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
22229 }
22230@@ -697,7 +698,7 @@ static int mce_timed_out(u64 *t)
22231 * might have been modified by someone else.
22232 */
22233 rmb();
22234- if (atomic_read(&mce_paniced))
22235+ if (atomic_read_unchecked(&mce_paniced))
22236 wait_for_panic();
22237 if (!mca_cfg.monarch_timeout)
22238 goto out;
22239@@ -1674,7 +1675,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
22240 }
22241
22242 /* Call the installed machine check handler for this CPU setup. */
22243-void (*machine_check_vector)(struct pt_regs *, long error_code) =
22244+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
22245 unexpected_machine_check;
22246
22247 /*
22248@@ -1697,7 +1698,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
22249 return;
22250 }
22251
22252+ pax_open_kernel();
22253 machine_check_vector = do_machine_check;
22254+ pax_close_kernel();
22255
22256 __mcheck_cpu_init_generic();
22257 __mcheck_cpu_init_vendor(c);
22258@@ -1711,7 +1714,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
22259 */
22260
22261 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
22262-static int mce_chrdev_open_count; /* #times opened */
22263+static local_t mce_chrdev_open_count; /* #times opened */
22264 static int mce_chrdev_open_exclu; /* already open exclusive? */
22265
22266 static int mce_chrdev_open(struct inode *inode, struct file *file)
22267@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
22268 spin_lock(&mce_chrdev_state_lock);
22269
22270 if (mce_chrdev_open_exclu ||
22271- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
22272+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
22273 spin_unlock(&mce_chrdev_state_lock);
22274
22275 return -EBUSY;
22276@@ -1727,7 +1730,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
22277
22278 if (file->f_flags & O_EXCL)
22279 mce_chrdev_open_exclu = 1;
22280- mce_chrdev_open_count++;
22281+ local_inc(&mce_chrdev_open_count);
22282
22283 spin_unlock(&mce_chrdev_state_lock);
22284
22285@@ -1738,7 +1741,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
22286 {
22287 spin_lock(&mce_chrdev_state_lock);
22288
22289- mce_chrdev_open_count--;
22290+ local_dec(&mce_chrdev_open_count);
22291 mce_chrdev_open_exclu = 0;
22292
22293 spin_unlock(&mce_chrdev_state_lock);
22294@@ -2413,7 +2416,7 @@ static __init void mce_init_banks(void)
22295
22296 for (i = 0; i < mca_cfg.banks; i++) {
22297 struct mce_bank *b = &mce_banks[i];
22298- struct device_attribute *a = &b->attr;
22299+ device_attribute_no_const *a = &b->attr;
22300
22301 sysfs_attr_init(&a->attr);
22302 a->attr.name = b->attrname;
22303@@ -2520,7 +2523,7 @@ struct dentry *mce_get_debugfs_dir(void)
22304 static void mce_reset(void)
22305 {
22306 cpu_missing = 0;
22307- atomic_set(&mce_fake_paniced, 0);
22308+ atomic_set_unchecked(&mce_fake_paniced, 0);
22309 atomic_set(&mce_executing, 0);
22310 atomic_set(&mce_callin, 0);
22311 atomic_set(&global_nwo, 0);
22312diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
22313index a304298..49b6d06 100644
22314--- a/arch/x86/kernel/cpu/mcheck/p5.c
22315+++ b/arch/x86/kernel/cpu/mcheck/p5.c
22316@@ -10,6 +10,7 @@
22317 #include <asm/processor.h>
22318 #include <asm/mce.h>
22319 #include <asm/msr.h>
22320+#include <asm/pgtable.h>
22321
22322 /* By default disabled */
22323 int mce_p5_enabled __read_mostly;
22324@@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
22325 if (!cpu_has(c, X86_FEATURE_MCE))
22326 return;
22327
22328+ pax_open_kernel();
22329 machine_check_vector = pentium_machine_check;
22330+ pax_close_kernel();
22331 /* Make sure the vector pointer is visible before we enable MCEs: */
22332 wmb();
22333
22334diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
22335index 7dc5564..1273569 100644
22336--- a/arch/x86/kernel/cpu/mcheck/winchip.c
22337+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
22338@@ -9,6 +9,7 @@
22339 #include <asm/processor.h>
22340 #include <asm/mce.h>
22341 #include <asm/msr.h>
22342+#include <asm/pgtable.h>
22343
22344 /* Machine check handler for WinChip C6: */
22345 static void winchip_machine_check(struct pt_regs *regs, long error_code)
22346@@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
22347 {
22348 u32 lo, hi;
22349
22350+ pax_open_kernel();
22351 machine_check_vector = winchip_machine_check;
22352+ pax_close_kernel();
22353 /* Make sure the vector pointer is visible before we enable MCEs: */
22354 wmb();
22355
22356diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
22357index dd9d619..86e1d81 100644
22358--- a/arch/x86/kernel/cpu/microcode/core.c
22359+++ b/arch/x86/kernel/cpu/microcode/core.c
22360@@ -516,7 +516,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
22361 return NOTIFY_OK;
22362 }
22363
22364-static struct notifier_block __refdata mc_cpu_notifier = {
22365+static struct notifier_block mc_cpu_notifier = {
22366 .notifier_call = mc_cpu_callback,
22367 };
22368
22369diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
22370index a276fa7..e66810f 100644
22371--- a/arch/x86/kernel/cpu/microcode/intel.c
22372+++ b/arch/x86/kernel/cpu/microcode/intel.c
22373@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
22374
22375 static int get_ucode_user(void *to, const void *from, size_t n)
22376 {
22377- return copy_from_user(to, from, n);
22378+ return copy_from_user(to, (const void __force_user *)from, n);
22379 }
22380
22381 static enum ucode_state
22382 request_microcode_user(int cpu, const void __user *buf, size_t size)
22383 {
22384- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
22385+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
22386 }
22387
22388 static void microcode_fini_cpu(int cpu)
22389diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
22390index f961de9..8a9d332 100644
22391--- a/arch/x86/kernel/cpu/mtrr/main.c
22392+++ b/arch/x86/kernel/cpu/mtrr/main.c
22393@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
22394 u64 size_or_mask, size_and_mask;
22395 static bool mtrr_aps_delayed_init;
22396
22397-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
22398+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
22399
22400 const struct mtrr_ops *mtrr_if;
22401
22402diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
22403index df5e41f..816c719 100644
22404--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
22405+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
22406@@ -25,7 +25,7 @@ struct mtrr_ops {
22407 int (*validate_add_page)(unsigned long base, unsigned long size,
22408 unsigned int type);
22409 int (*have_wrcomb)(void);
22410-};
22411+} __do_const;
22412
22413 extern int generic_get_free_region(unsigned long base, unsigned long size,
22414 int replace_reg);
22415diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
22416index 2879ecd..bb8c80b 100644
22417--- a/arch/x86/kernel/cpu/perf_event.c
22418+++ b/arch/x86/kernel/cpu/perf_event.c
22419@@ -1372,7 +1372,7 @@ static void __init pmu_check_apic(void)
22420
22421 }
22422
22423-static struct attribute_group x86_pmu_format_group = {
22424+static attribute_group_no_const x86_pmu_format_group = {
22425 .name = "format",
22426 .attrs = NULL,
22427 };
22428@@ -1471,7 +1471,7 @@ static struct attribute *events_attr[] = {
22429 NULL,
22430 };
22431
22432-static struct attribute_group x86_pmu_events_group = {
22433+static attribute_group_no_const x86_pmu_events_group = {
22434 .name = "events",
22435 .attrs = events_attr,
22436 };
22437@@ -1995,7 +1995,7 @@ static unsigned long get_segment_base(unsigned int segment)
22438 if (idx > GDT_ENTRIES)
22439 return 0;
22440
22441- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
22442+ desc = get_cpu_gdt_table(smp_processor_id());
22443 }
22444
22445 return get_desc_base(desc + idx);
22446@@ -2085,7 +2085,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
22447 break;
22448
22449 perf_callchain_store(entry, frame.return_address);
22450- fp = frame.next_frame;
22451+ fp = (const void __force_user *)frame.next_frame;
22452 }
22453 }
22454
22455diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22456index 639d128..e92d7e5 100644
22457--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22458+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
22459@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
22460 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
22461 {
22462 struct attribute **attrs;
22463- struct attribute_group *attr_group;
22464+ attribute_group_no_const *attr_group;
22465 int i = 0, j;
22466
22467 while (amd_iommu_v2_event_descs[i].attr.attr.name)
22468diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
22469index 2502d0d..e5cc05c 100644
22470--- a/arch/x86/kernel/cpu/perf_event_intel.c
22471+++ b/arch/x86/kernel/cpu/perf_event_intel.c
22472@@ -2353,10 +2353,10 @@ __init int intel_pmu_init(void)
22473 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
22474
22475 if (boot_cpu_has(X86_FEATURE_PDCM)) {
22476- u64 capabilities;
22477+ u64 capabilities = x86_pmu.intel_cap.capabilities;
22478
22479- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
22480- x86_pmu.intel_cap.capabilities = capabilities;
22481+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
22482+ x86_pmu.intel_cap.capabilities = capabilities;
22483 }
22484
22485 intel_ds_init();
22486diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22487index 619f769..d510008 100644
22488--- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22489+++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
22490@@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
22491 NULL,
22492 };
22493
22494-static struct attribute_group rapl_pmu_events_group = {
22495+static attribute_group_no_const rapl_pmu_events_group __read_only = {
22496 .name = "events",
22497 .attrs = NULL, /* patched at runtime */
22498 };
22499diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22500index 0939f86..69730af 100644
22501--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22502+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
22503@@ -3691,7 +3691,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
22504 static int __init uncore_type_init(struct intel_uncore_type *type)
22505 {
22506 struct intel_uncore_pmu *pmus;
22507- struct attribute_group *attr_group;
22508+ attribute_group_no_const *attr_group;
22509 struct attribute **attrs;
22510 int i, j;
22511
22512diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22513index 90236f0..54cb20d 100644
22514--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22515+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
22516@@ -503,7 +503,7 @@ struct intel_uncore_box {
22517 struct uncore_event_desc {
22518 struct kobj_attribute attr;
22519 const char *config;
22520-};
22521+} __do_const;
22522
22523 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
22524 { \
22525diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
22526index 3225ae6c..ee3c6db 100644
22527--- a/arch/x86/kernel/cpuid.c
22528+++ b/arch/x86/kernel/cpuid.c
22529@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
22530 return notifier_from_errno(err);
22531 }
22532
22533-static struct notifier_block __refdata cpuid_class_cpu_notifier =
22534+static struct notifier_block cpuid_class_cpu_notifier =
22535 {
22536 .notifier_call = cpuid_class_cpu_callback,
22537 };
22538diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
22539index a618fcd..200e95b 100644
22540--- a/arch/x86/kernel/crash.c
22541+++ b/arch/x86/kernel/crash.c
22542@@ -104,7 +104,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
22543 #ifdef CONFIG_X86_32
22544 struct pt_regs fixed_regs;
22545
22546- if (!user_mode_vm(regs)) {
22547+ if (!user_mode(regs)) {
22548 crash_fixup_ss_esp(&fixed_regs, regs);
22549 regs = &fixed_regs;
22550 }
22551diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
22552index afa64ad..dce67dd 100644
22553--- a/arch/x86/kernel/crash_dump_64.c
22554+++ b/arch/x86/kernel/crash_dump_64.c
22555@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
22556 return -ENOMEM;
22557
22558 if (userbuf) {
22559- if (copy_to_user(buf, vaddr + offset, csize)) {
22560+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
22561 iounmap(vaddr);
22562 return -EFAULT;
22563 }
22564diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
22565index f6dfd93..892ade4 100644
22566--- a/arch/x86/kernel/doublefault.c
22567+++ b/arch/x86/kernel/doublefault.c
22568@@ -12,7 +12,7 @@
22569
22570 #define DOUBLEFAULT_STACKSIZE (1024)
22571 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
22572-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
22573+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
22574
22575 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
22576
22577@@ -22,7 +22,7 @@ static void doublefault_fn(void)
22578 unsigned long gdt, tss;
22579
22580 native_store_gdt(&gdt_desc);
22581- gdt = gdt_desc.address;
22582+ gdt = (unsigned long)gdt_desc.address;
22583
22584 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
22585
22586@@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
22587 /* 0x2 bit is always set */
22588 .flags = X86_EFLAGS_SF | 0x2,
22589 .sp = STACK_START,
22590- .es = __USER_DS,
22591+ .es = __KERNEL_DS,
22592 .cs = __KERNEL_CS,
22593 .ss = __KERNEL_DS,
22594- .ds = __USER_DS,
22595+ .ds = __KERNEL_DS,
22596 .fs = __KERNEL_PERCPU,
22597
22598 .__cr3 = __pa_nodebug(swapper_pg_dir),
22599diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
22600index b74ebc7..2c95874 100644
22601--- a/arch/x86/kernel/dumpstack.c
22602+++ b/arch/x86/kernel/dumpstack.c
22603@@ -2,6 +2,9 @@
22604 * Copyright (C) 1991, 1992 Linus Torvalds
22605 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
22606 */
22607+#ifdef CONFIG_GRKERNSEC_HIDESYM
22608+#define __INCLUDED_BY_HIDESYM 1
22609+#endif
22610 #include <linux/kallsyms.h>
22611 #include <linux/kprobes.h>
22612 #include <linux/uaccess.h>
22613@@ -33,23 +36,21 @@ static void printk_stack_address(unsigned long address, int reliable)
22614
22615 void printk_address(unsigned long address)
22616 {
22617- pr_cont(" [<%p>] %pS\n", (void *)address, (void *)address);
22618+ pr_cont(" [<%p>] %pA\n", (void *)address, (void *)address);
22619 }
22620
22621 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
22622 static void
22623 print_ftrace_graph_addr(unsigned long addr, void *data,
22624 const struct stacktrace_ops *ops,
22625- struct thread_info *tinfo, int *graph)
22626+ struct task_struct *task, int *graph)
22627 {
22628- struct task_struct *task;
22629 unsigned long ret_addr;
22630 int index;
22631
22632 if (addr != (unsigned long)return_to_handler)
22633 return;
22634
22635- task = tinfo->task;
22636 index = task->curr_ret_stack;
22637
22638 if (!task->ret_stack || index < *graph)
22639@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22640 static inline void
22641 print_ftrace_graph_addr(unsigned long addr, void *data,
22642 const struct stacktrace_ops *ops,
22643- struct thread_info *tinfo, int *graph)
22644+ struct task_struct *task, int *graph)
22645 { }
22646 #endif
22647
22648@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
22649 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
22650 */
22651
22652-static inline int valid_stack_ptr(struct thread_info *tinfo,
22653- void *p, unsigned int size, void *end)
22654+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
22655 {
22656- void *t = tinfo;
22657 if (end) {
22658 if (p < end && p >= (end-THREAD_SIZE))
22659 return 1;
22660@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
22661 }
22662
22663 unsigned long
22664-print_context_stack(struct thread_info *tinfo,
22665+print_context_stack(struct task_struct *task, void *stack_start,
22666 unsigned long *stack, unsigned long bp,
22667 const struct stacktrace_ops *ops, void *data,
22668 unsigned long *end, int *graph)
22669 {
22670 struct stack_frame *frame = (struct stack_frame *)bp;
22671
22672- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
22673+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
22674 unsigned long addr;
22675
22676 addr = *stack;
22677@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
22678 } else {
22679 ops->address(data, addr, 0);
22680 }
22681- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22682+ print_ftrace_graph_addr(addr, data, ops, task, graph);
22683 }
22684 stack++;
22685 }
22686@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
22687 EXPORT_SYMBOL_GPL(print_context_stack);
22688
22689 unsigned long
22690-print_context_stack_bp(struct thread_info *tinfo,
22691+print_context_stack_bp(struct task_struct *task, void *stack_start,
22692 unsigned long *stack, unsigned long bp,
22693 const struct stacktrace_ops *ops, void *data,
22694 unsigned long *end, int *graph)
22695@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22696 struct stack_frame *frame = (struct stack_frame *)bp;
22697 unsigned long *ret_addr = &frame->return_address;
22698
22699- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
22700+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
22701 unsigned long addr = *ret_addr;
22702
22703 if (!__kernel_text_address(addr))
22704@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
22705 ops->address(data, addr, 1);
22706 frame = frame->next_frame;
22707 ret_addr = &frame->return_address;
22708- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
22709+ print_ftrace_graph_addr(addr, data, ops, task, graph);
22710 }
22711
22712 return (unsigned long)frame;
22713@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
22714 static void print_trace_address(void *data, unsigned long addr, int reliable)
22715 {
22716 touch_nmi_watchdog();
22717- printk(data);
22718+ printk("%s", (char *)data);
22719 printk_stack_address(addr, reliable);
22720 }
22721
22722@@ -225,6 +224,8 @@ unsigned long oops_begin(void)
22723 EXPORT_SYMBOL_GPL(oops_begin);
22724 NOKPROBE_SYMBOL(oops_begin);
22725
22726+extern void gr_handle_kernel_exploit(void);
22727+
22728 void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22729 {
22730 if (regs && kexec_should_crash(current))
22731@@ -246,7 +247,10 @@ void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
22732 panic("Fatal exception in interrupt");
22733 if (panic_on_oops)
22734 panic("Fatal exception");
22735- do_exit(signr);
22736+
22737+ gr_handle_kernel_exploit();
22738+
22739+ do_group_exit(signr);
22740 }
22741 NOKPROBE_SYMBOL(oops_end);
22742
22743@@ -275,7 +279,7 @@ int __die(const char *str, struct pt_regs *regs, long err)
22744 print_modules();
22745 show_regs(regs);
22746 #ifdef CONFIG_X86_32
22747- if (user_mode_vm(regs)) {
22748+ if (user_mode(regs)) {
22749 sp = regs->sp;
22750 ss = regs->ss & 0xffff;
22751 } else {
22752@@ -304,7 +308,7 @@ void die(const char *str, struct pt_regs *regs, long err)
22753 unsigned long flags = oops_begin();
22754 int sig = SIGSEGV;
22755
22756- if (!user_mode_vm(regs))
22757+ if (!user_mode(regs))
22758 report_bug(regs->ip, regs);
22759
22760 if (__die(str, regs, err))
22761diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
22762index 5abd4cd..c65733b 100644
22763--- a/arch/x86/kernel/dumpstack_32.c
22764+++ b/arch/x86/kernel/dumpstack_32.c
22765@@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22766 bp = stack_frame(task, regs);
22767
22768 for (;;) {
22769- struct thread_info *context;
22770+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22771 void *end_stack;
22772
22773 end_stack = is_hardirq_stack(stack, cpu);
22774 if (!end_stack)
22775 end_stack = is_softirq_stack(stack, cpu);
22776
22777- context = task_thread_info(task);
22778- bp = ops->walk_stack(context, stack, bp, ops, data,
22779+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
22780 end_stack, &graph);
22781
22782 /* Stop if not on irq stack */
22783@@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
22784 int i;
22785
22786 show_regs_print_info(KERN_EMERG);
22787- __show_regs(regs, !user_mode_vm(regs));
22788+ __show_regs(regs, !user_mode(regs));
22789
22790 /*
22791 * When in-kernel, we also print out the stack and code at the
22792 * time of the fault..
22793 */
22794- if (!user_mode_vm(regs)) {
22795+ if (!user_mode(regs)) {
22796 unsigned int code_prologue = code_bytes * 43 / 64;
22797 unsigned int code_len = code_bytes;
22798 unsigned char c;
22799 u8 *ip;
22800+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
22801
22802 pr_emerg("Stack:\n");
22803 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
22804
22805 pr_emerg("Code:");
22806
22807- ip = (u8 *)regs->ip - code_prologue;
22808+ ip = (u8 *)regs->ip - code_prologue + cs_base;
22809 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
22810 /* try starting at IP */
22811- ip = (u8 *)regs->ip;
22812+ ip = (u8 *)regs->ip + cs_base;
22813 code_len = code_len - code_prologue + 1;
22814 }
22815 for (i = 0; i < code_len; i++, ip++) {
22816@@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
22817 pr_cont(" Bad EIP value.");
22818 break;
22819 }
22820- if (ip == (u8 *)regs->ip)
22821+ if (ip == (u8 *)regs->ip + cs_base)
22822 pr_cont(" <%02x>", c);
22823 else
22824 pr_cont(" %02x", c);
22825@@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
22826 {
22827 unsigned short ud2;
22828
22829+ ip = ktla_ktva(ip);
22830 if (ip < PAGE_OFFSET)
22831 return 0;
22832 if (probe_kernel_address((unsigned short *)ip, ud2))
22833@@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
22834
22835 return ud2 == 0x0b0f;
22836 }
22837+
22838+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22839+void pax_check_alloca(unsigned long size)
22840+{
22841+ unsigned long sp = (unsigned long)&sp, stack_left;
22842+
22843+ /* all kernel stacks are of the same size */
22844+ stack_left = sp & (THREAD_SIZE - 1);
22845+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22846+}
22847+EXPORT_SYMBOL(pax_check_alloca);
22848+#endif
22849diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
22850index 1abcb50..6c8d702 100644
22851--- a/arch/x86/kernel/dumpstack_64.c
22852+++ b/arch/x86/kernel/dumpstack_64.c
22853@@ -154,12 +154,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22854 const struct stacktrace_ops *ops, void *data)
22855 {
22856 const unsigned cpu = get_cpu();
22857- struct thread_info *tinfo;
22858 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
22859 unsigned long dummy;
22860 unsigned used = 0;
22861 int graph = 0;
22862 int done = 0;
22863+ void *stack_start;
22864
22865 if (!task)
22866 task = current;
22867@@ -180,7 +180,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22868 * current stack address. If the stacks consist of nested
22869 * exceptions
22870 */
22871- tinfo = task_thread_info(task);
22872 while (!done) {
22873 unsigned long *stack_end;
22874 enum stack_type stype;
22875@@ -203,7 +202,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22876 if (ops->stack(data, id) < 0)
22877 break;
22878
22879- bp = ops->walk_stack(tinfo, stack, bp, ops,
22880+ bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
22881 data, stack_end, &graph);
22882 ops->stack(data, "<EOE>");
22883 /*
22884@@ -211,6 +210,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22885 * second-to-last pointer (index -2 to end) in the
22886 * exception stack:
22887 */
22888+ if ((u16)stack_end[-1] != __KERNEL_DS)
22889+ goto out;
22890 stack = (unsigned long *) stack_end[-2];
22891 done = 0;
22892 break;
22893@@ -219,7 +220,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22894
22895 if (ops->stack(data, "IRQ") < 0)
22896 break;
22897- bp = ops->walk_stack(tinfo, stack, bp,
22898+ bp = ops->walk_stack(task, irq_stack, stack, bp,
22899 ops, data, stack_end, &graph);
22900 /*
22901 * We link to the next stack (which would be
22902@@ -241,7 +242,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
22903 /*
22904 * This handles the process stack:
22905 */
22906- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
22907+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
22908+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
22909+out:
22910 put_cpu();
22911 }
22912 EXPORT_SYMBOL(dump_trace);
22913@@ -350,3 +353,50 @@ int is_valid_bugaddr(unsigned long ip)
22914
22915 return ud2 == 0x0b0f;
22916 }
22917+
22918+#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
22919+void pax_check_alloca(unsigned long size)
22920+{
22921+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
22922+ unsigned cpu, used;
22923+ char *id;
22924+
22925+ /* check the process stack first */
22926+ stack_start = (unsigned long)task_stack_page(current);
22927+ stack_end = stack_start + THREAD_SIZE;
22928+ if (likely(stack_start <= sp && sp < stack_end)) {
22929+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
22930+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22931+ return;
22932+ }
22933+
22934+ cpu = get_cpu();
22935+
22936+ /* check the irq stacks */
22937+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
22938+ stack_start = stack_end - IRQ_STACK_SIZE;
22939+ if (stack_start <= sp && sp < stack_end) {
22940+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
22941+ put_cpu();
22942+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22943+ return;
22944+ }
22945+
22946+ /* check the exception stacks */
22947+ used = 0;
22948+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
22949+ stack_start = stack_end - EXCEPTION_STKSZ;
22950+ if (stack_end && stack_start <= sp && sp < stack_end) {
22951+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
22952+ put_cpu();
22953+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
22954+ return;
22955+ }
22956+
22957+ put_cpu();
22958+
22959+ /* unknown stack */
22960+ BUG();
22961+}
22962+EXPORT_SYMBOL(pax_check_alloca);
22963+#endif
22964diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
22965index 988c00a..4f673b6 100644
22966--- a/arch/x86/kernel/e820.c
22967+++ b/arch/x86/kernel/e820.c
22968@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
22969
22970 static void early_panic(char *msg)
22971 {
22972- early_printk(msg);
22973- panic(msg);
22974+ early_printk("%s", msg);
22975+ panic("%s", msg);
22976 }
22977
22978 static int userdef __initdata;
22979diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22980index 01d1c18..8073693 100644
22981--- a/arch/x86/kernel/early_printk.c
22982+++ b/arch/x86/kernel/early_printk.c
22983@@ -7,6 +7,7 @@
22984 #include <linux/pci_regs.h>
22985 #include <linux/pci_ids.h>
22986 #include <linux/errno.h>
22987+#include <linux/sched.h>
22988 #include <asm/io.h>
22989 #include <asm/processor.h>
22990 #include <asm/fcntl.h>
22991diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22992index 4b0e1df..884b67e 100644
22993--- a/arch/x86/kernel/entry_32.S
22994+++ b/arch/x86/kernel/entry_32.S
22995@@ -177,13 +177,153 @@
22996 /*CFI_REL_OFFSET gs, PT_GS*/
22997 .endm
22998 .macro SET_KERNEL_GS reg
22999+
23000+#ifdef CONFIG_CC_STACKPROTECTOR
23001 movl $(__KERNEL_STACK_CANARY), \reg
23002+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
23003+ movl $(__USER_DS), \reg
23004+#else
23005+ xorl \reg, \reg
23006+#endif
23007+
23008 movl \reg, %gs
23009 .endm
23010
23011 #endif /* CONFIG_X86_32_LAZY_GS */
23012
23013-.macro SAVE_ALL
23014+.macro pax_enter_kernel
23015+#ifdef CONFIG_PAX_KERNEXEC
23016+ call pax_enter_kernel
23017+#endif
23018+.endm
23019+
23020+.macro pax_exit_kernel
23021+#ifdef CONFIG_PAX_KERNEXEC
23022+ call pax_exit_kernel
23023+#endif
23024+.endm
23025+
23026+#ifdef CONFIG_PAX_KERNEXEC
23027+ENTRY(pax_enter_kernel)
23028+#ifdef CONFIG_PARAVIRT
23029+ pushl %eax
23030+ pushl %ecx
23031+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
23032+ mov %eax, %esi
23033+#else
23034+ mov %cr0, %esi
23035+#endif
23036+ bts $16, %esi
23037+ jnc 1f
23038+ mov %cs, %esi
23039+ cmp $__KERNEL_CS, %esi
23040+ jz 3f
23041+ ljmp $__KERNEL_CS, $3f
23042+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
23043+2:
23044+#ifdef CONFIG_PARAVIRT
23045+ mov %esi, %eax
23046+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
23047+#else
23048+ mov %esi, %cr0
23049+#endif
23050+3:
23051+#ifdef CONFIG_PARAVIRT
23052+ popl %ecx
23053+ popl %eax
23054+#endif
23055+ ret
23056+ENDPROC(pax_enter_kernel)
23057+
23058+ENTRY(pax_exit_kernel)
23059+#ifdef CONFIG_PARAVIRT
23060+ pushl %eax
23061+ pushl %ecx
23062+#endif
23063+ mov %cs, %esi
23064+ cmp $__KERNEXEC_KERNEL_CS, %esi
23065+ jnz 2f
23066+#ifdef CONFIG_PARAVIRT
23067+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
23068+ mov %eax, %esi
23069+#else
23070+ mov %cr0, %esi
23071+#endif
23072+ btr $16, %esi
23073+ ljmp $__KERNEL_CS, $1f
23074+1:
23075+#ifdef CONFIG_PARAVIRT
23076+ mov %esi, %eax
23077+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
23078+#else
23079+ mov %esi, %cr0
23080+#endif
23081+2:
23082+#ifdef CONFIG_PARAVIRT
23083+ popl %ecx
23084+ popl %eax
23085+#endif
23086+ ret
23087+ENDPROC(pax_exit_kernel)
23088+#endif
23089+
23090+ .macro pax_erase_kstack
23091+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23092+ call pax_erase_kstack
23093+#endif
23094+ .endm
23095+
23096+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23097+/*
23098+ * ebp: thread_info
23099+ */
23100+ENTRY(pax_erase_kstack)
23101+ pushl %edi
23102+ pushl %ecx
23103+ pushl %eax
23104+
23105+ mov TI_lowest_stack(%ebp), %edi
23106+ mov $-0xBEEF, %eax
23107+ std
23108+
23109+1: mov %edi, %ecx
23110+ and $THREAD_SIZE_asm - 1, %ecx
23111+ shr $2, %ecx
23112+ repne scasl
23113+ jecxz 2f
23114+
23115+ cmp $2*16, %ecx
23116+ jc 2f
23117+
23118+ mov $2*16, %ecx
23119+ repe scasl
23120+ jecxz 2f
23121+ jne 1b
23122+
23123+2: cld
23124+ mov %esp, %ecx
23125+ sub %edi, %ecx
23126+
23127+ cmp $THREAD_SIZE_asm, %ecx
23128+ jb 3f
23129+ ud2
23130+3:
23131+
23132+ shr $2, %ecx
23133+ rep stosl
23134+
23135+ mov TI_task_thread_sp0(%ebp), %edi
23136+ sub $128, %edi
23137+ mov %edi, TI_lowest_stack(%ebp)
23138+
23139+ popl %eax
23140+ popl %ecx
23141+ popl %edi
23142+ ret
23143+ENDPROC(pax_erase_kstack)
23144+#endif
23145+
23146+.macro __SAVE_ALL _DS
23147 cld
23148 PUSH_GS
23149 pushl_cfi %fs
23150@@ -206,7 +346,7 @@
23151 CFI_REL_OFFSET ecx, 0
23152 pushl_cfi %ebx
23153 CFI_REL_OFFSET ebx, 0
23154- movl $(__USER_DS), %edx
23155+ movl $\_DS, %edx
23156 movl %edx, %ds
23157 movl %edx, %es
23158 movl $(__KERNEL_PERCPU), %edx
23159@@ -214,6 +354,15 @@
23160 SET_KERNEL_GS %edx
23161 .endm
23162
23163+.macro SAVE_ALL
23164+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23165+ __SAVE_ALL __KERNEL_DS
23166+ pax_enter_kernel
23167+#else
23168+ __SAVE_ALL __USER_DS
23169+#endif
23170+.endm
23171+
23172 .macro RESTORE_INT_REGS
23173 popl_cfi %ebx
23174 CFI_RESTORE ebx
23175@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
23176 popfl_cfi
23177 jmp syscall_exit
23178 CFI_ENDPROC
23179-END(ret_from_fork)
23180+ENDPROC(ret_from_fork)
23181
23182 ENTRY(ret_from_kernel_thread)
23183 CFI_STARTPROC
23184@@ -340,7 +489,15 @@ ret_from_intr:
23185 andl $SEGMENT_RPL_MASK, %eax
23186 #endif
23187 cmpl $USER_RPL, %eax
23188+
23189+#ifdef CONFIG_PAX_KERNEXEC
23190+ jae resume_userspace
23191+
23192+ pax_exit_kernel
23193+ jmp resume_kernel
23194+#else
23195 jb resume_kernel # not returning to v8086 or userspace
23196+#endif
23197
23198 ENTRY(resume_userspace)
23199 LOCKDEP_SYS_EXIT
23200@@ -352,8 +509,8 @@ ENTRY(resume_userspace)
23201 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
23202 # int/exception return?
23203 jne work_pending
23204- jmp restore_all
23205-END(ret_from_exception)
23206+ jmp restore_all_pax
23207+ENDPROC(ret_from_exception)
23208
23209 #ifdef CONFIG_PREEMPT
23210 ENTRY(resume_kernel)
23211@@ -365,7 +522,7 @@ need_resched:
23212 jz restore_all
23213 call preempt_schedule_irq
23214 jmp need_resched
23215-END(resume_kernel)
23216+ENDPROC(resume_kernel)
23217 #endif
23218 CFI_ENDPROC
23219
23220@@ -395,30 +552,45 @@ sysenter_past_esp:
23221 /*CFI_REL_OFFSET cs, 0*/
23222 /*
23223 * Push current_thread_info()->sysenter_return to the stack.
23224- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
23225- * pushed above; +8 corresponds to copy_thread's esp0 setting.
23226 */
23227- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
23228+ pushl_cfi $0
23229 CFI_REL_OFFSET eip, 0
23230
23231 pushl_cfi %eax
23232 SAVE_ALL
23233+ GET_THREAD_INFO(%ebp)
23234+ movl TI_sysenter_return(%ebp),%ebp
23235+ movl %ebp,PT_EIP(%esp)
23236 ENABLE_INTERRUPTS(CLBR_NONE)
23237
23238 /*
23239 * Load the potential sixth argument from user stack.
23240 * Careful about security.
23241 */
23242+ movl PT_OLDESP(%esp),%ebp
23243+
23244+#ifdef CONFIG_PAX_MEMORY_UDEREF
23245+ mov PT_OLDSS(%esp),%ds
23246+1: movl %ds:(%ebp),%ebp
23247+ push %ss
23248+ pop %ds
23249+#else
23250 cmpl $__PAGE_OFFSET-3,%ebp
23251 jae syscall_fault
23252 ASM_STAC
23253 1: movl (%ebp),%ebp
23254 ASM_CLAC
23255+#endif
23256+
23257 movl %ebp,PT_EBP(%esp)
23258 _ASM_EXTABLE(1b,syscall_fault)
23259
23260 GET_THREAD_INFO(%ebp)
23261
23262+#ifdef CONFIG_PAX_RANDKSTACK
23263+ pax_erase_kstack
23264+#endif
23265+
23266 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
23267 jnz sysenter_audit
23268 sysenter_do_call:
23269@@ -434,12 +606,24 @@ sysenter_after_call:
23270 testl $_TIF_ALLWORK_MASK, %ecx
23271 jne sysexit_audit
23272 sysenter_exit:
23273+
23274+#ifdef CONFIG_PAX_RANDKSTACK
23275+ pushl_cfi %eax
23276+ movl %esp, %eax
23277+ call pax_randomize_kstack
23278+ popl_cfi %eax
23279+#endif
23280+
23281+ pax_erase_kstack
23282+
23283 /* if something modifies registers it must also disable sysexit */
23284 movl PT_EIP(%esp), %edx
23285 movl PT_OLDESP(%esp), %ecx
23286 xorl %ebp,%ebp
23287 TRACE_IRQS_ON
23288 1: mov PT_FS(%esp), %fs
23289+2: mov PT_DS(%esp), %ds
23290+3: mov PT_ES(%esp), %es
23291 PTGS_TO_GS
23292 ENABLE_INTERRUPTS_SYSEXIT
23293
23294@@ -456,6 +640,9 @@ sysenter_audit:
23295 movl %eax,%edx /* 2nd arg: syscall number */
23296 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
23297 call __audit_syscall_entry
23298+
23299+ pax_erase_kstack
23300+
23301 pushl_cfi %ebx
23302 movl PT_EAX(%esp),%eax /* reload syscall number */
23303 jmp sysenter_do_call
23304@@ -481,10 +668,16 @@ sysexit_audit:
23305
23306 CFI_ENDPROC
23307 .pushsection .fixup,"ax"
23308-2: movl $0,PT_FS(%esp)
23309+4: movl $0,PT_FS(%esp)
23310+ jmp 1b
23311+5: movl $0,PT_DS(%esp)
23312+ jmp 1b
23313+6: movl $0,PT_ES(%esp)
23314 jmp 1b
23315 .popsection
23316- _ASM_EXTABLE(1b,2b)
23317+ _ASM_EXTABLE(1b,4b)
23318+ _ASM_EXTABLE(2b,5b)
23319+ _ASM_EXTABLE(3b,6b)
23320 PTGS_TO_GS_EX
23321 ENDPROC(ia32_sysenter_target)
23322
23323@@ -495,6 +688,11 @@ ENTRY(system_call)
23324 pushl_cfi %eax # save orig_eax
23325 SAVE_ALL
23326 GET_THREAD_INFO(%ebp)
23327+
23328+#ifdef CONFIG_PAX_RANDKSTACK
23329+ pax_erase_kstack
23330+#endif
23331+
23332 # system call tracing in operation / emulation
23333 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
23334 jnz syscall_trace_entry
23335@@ -514,6 +712,15 @@ syscall_exit:
23336 testl $_TIF_ALLWORK_MASK, %ecx # current->work
23337 jne syscall_exit_work
23338
23339+restore_all_pax:
23340+
23341+#ifdef CONFIG_PAX_RANDKSTACK
23342+ movl %esp, %eax
23343+ call pax_randomize_kstack
23344+#endif
23345+
23346+ pax_erase_kstack
23347+
23348 restore_all:
23349 TRACE_IRQS_IRET
23350 restore_all_notrace:
23351@@ -568,14 +775,34 @@ ldt_ss:
23352 * compensating for the offset by changing to the ESPFIX segment with
23353 * a base address that matches for the difference.
23354 */
23355-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
23356+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
23357 mov %esp, %edx /* load kernel esp */
23358 mov PT_OLDESP(%esp), %eax /* load userspace esp */
23359 mov %dx, %ax /* eax: new kernel esp */
23360 sub %eax, %edx /* offset (low word is 0) */
23361+#ifdef CONFIG_SMP
23362+ movl PER_CPU_VAR(cpu_number), %ebx
23363+ shll $PAGE_SHIFT_asm, %ebx
23364+ addl $cpu_gdt_table, %ebx
23365+#else
23366+ movl $cpu_gdt_table, %ebx
23367+#endif
23368 shr $16, %edx
23369- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
23370- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
23371+
23372+#ifdef CONFIG_PAX_KERNEXEC
23373+ mov %cr0, %esi
23374+ btr $16, %esi
23375+ mov %esi, %cr0
23376+#endif
23377+
23378+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
23379+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
23380+
23381+#ifdef CONFIG_PAX_KERNEXEC
23382+ bts $16, %esi
23383+ mov %esi, %cr0
23384+#endif
23385+
23386 pushl_cfi $__ESPFIX_SS
23387 pushl_cfi %eax /* new kernel esp */
23388 /* Disable interrupts, but do not irqtrace this section: we
23389@@ -605,20 +832,18 @@ work_resched:
23390 movl TI_flags(%ebp), %ecx
23391 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
23392 # than syscall tracing?
23393- jz restore_all
23394+ jz restore_all_pax
23395 testb $_TIF_NEED_RESCHED, %cl
23396 jnz work_resched
23397
23398 work_notifysig: # deal with pending signals and
23399 # notify-resume requests
23400+ movl %esp, %eax
23401 #ifdef CONFIG_VM86
23402 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
23403- movl %esp, %eax
23404 jne work_notifysig_v86 # returning to kernel-space or
23405 # vm86-space
23406 1:
23407-#else
23408- movl %esp, %eax
23409 #endif
23410 TRACE_IRQS_ON
23411 ENABLE_INTERRUPTS(CLBR_NONE)
23412@@ -639,7 +864,7 @@ work_notifysig_v86:
23413 movl %eax, %esp
23414 jmp 1b
23415 #endif
23416-END(work_pending)
23417+ENDPROC(work_pending)
23418
23419 # perform syscall exit tracing
23420 ALIGN
23421@@ -647,11 +872,14 @@ syscall_trace_entry:
23422 movl $-ENOSYS,PT_EAX(%esp)
23423 movl %esp, %eax
23424 call syscall_trace_enter
23425+
23426+ pax_erase_kstack
23427+
23428 /* What it returned is what we'll actually use. */
23429 cmpl $(NR_syscalls), %eax
23430 jnae syscall_call
23431 jmp syscall_exit
23432-END(syscall_trace_entry)
23433+ENDPROC(syscall_trace_entry)
23434
23435 # perform syscall exit tracing
23436 ALIGN
23437@@ -664,26 +892,30 @@ syscall_exit_work:
23438 movl %esp, %eax
23439 call syscall_trace_leave
23440 jmp resume_userspace
23441-END(syscall_exit_work)
23442+ENDPROC(syscall_exit_work)
23443 CFI_ENDPROC
23444
23445 RING0_INT_FRAME # can't unwind into user space anyway
23446 syscall_fault:
23447+#ifdef CONFIG_PAX_MEMORY_UDEREF
23448+ push %ss
23449+ pop %ds
23450+#endif
23451 ASM_CLAC
23452 GET_THREAD_INFO(%ebp)
23453 movl $-EFAULT,PT_EAX(%esp)
23454 jmp resume_userspace
23455-END(syscall_fault)
23456+ENDPROC(syscall_fault)
23457
23458 syscall_badsys:
23459 movl $-ENOSYS,%eax
23460 jmp syscall_after_call
23461-END(syscall_badsys)
23462+ENDPROC(syscall_badsys)
23463
23464 sysenter_badsys:
23465 movl $-ENOSYS,%eax
23466 jmp sysenter_after_call
23467-END(sysenter_badsys)
23468+ENDPROC(sysenter_badsys)
23469 CFI_ENDPROC
23470
23471 .macro FIXUP_ESPFIX_STACK
23472@@ -696,8 +928,15 @@ END(sysenter_badsys)
23473 */
23474 #ifdef CONFIG_X86_ESPFIX32
23475 /* fixup the stack */
23476- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
23477- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
23478+#ifdef CONFIG_SMP
23479+ movl PER_CPU_VAR(cpu_number), %ebx
23480+ shll $PAGE_SHIFT_asm, %ebx
23481+ addl $cpu_gdt_table, %ebx
23482+#else
23483+ movl $cpu_gdt_table, %ebx
23484+#endif
23485+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
23486+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
23487 shl $16, %eax
23488 addl %esp, %eax /* the adjusted stack pointer */
23489 pushl_cfi $__KERNEL_DS
23490@@ -753,7 +992,7 @@ vector=vector+1
23491 .endr
23492 2: jmp common_interrupt
23493 .endr
23494-END(irq_entries_start)
23495+ENDPROC(irq_entries_start)
23496
23497 .previous
23498 END(interrupt)
23499@@ -810,7 +1049,7 @@ ENTRY(coprocessor_error)
23500 pushl_cfi $do_coprocessor_error
23501 jmp error_code
23502 CFI_ENDPROC
23503-END(coprocessor_error)
23504+ENDPROC(coprocessor_error)
23505
23506 ENTRY(simd_coprocessor_error)
23507 RING0_INT_FRAME
23508@@ -823,7 +1062,7 @@ ENTRY(simd_coprocessor_error)
23509 .section .altinstructions,"a"
23510 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
23511 .previous
23512-.section .altinstr_replacement,"ax"
23513+.section .altinstr_replacement,"a"
23514 663: pushl $do_simd_coprocessor_error
23515 664:
23516 .previous
23517@@ -832,7 +1071,7 @@ ENTRY(simd_coprocessor_error)
23518 #endif
23519 jmp error_code
23520 CFI_ENDPROC
23521-END(simd_coprocessor_error)
23522+ENDPROC(simd_coprocessor_error)
23523
23524 ENTRY(device_not_available)
23525 RING0_INT_FRAME
23526@@ -841,18 +1080,18 @@ ENTRY(device_not_available)
23527 pushl_cfi $do_device_not_available
23528 jmp error_code
23529 CFI_ENDPROC
23530-END(device_not_available)
23531+ENDPROC(device_not_available)
23532
23533 #ifdef CONFIG_PARAVIRT
23534 ENTRY(native_iret)
23535 iret
23536 _ASM_EXTABLE(native_iret, iret_exc)
23537-END(native_iret)
23538+ENDPROC(native_iret)
23539
23540 ENTRY(native_irq_enable_sysexit)
23541 sti
23542 sysexit
23543-END(native_irq_enable_sysexit)
23544+ENDPROC(native_irq_enable_sysexit)
23545 #endif
23546
23547 ENTRY(overflow)
23548@@ -862,7 +1101,7 @@ ENTRY(overflow)
23549 pushl_cfi $do_overflow
23550 jmp error_code
23551 CFI_ENDPROC
23552-END(overflow)
23553+ENDPROC(overflow)
23554
23555 ENTRY(bounds)
23556 RING0_INT_FRAME
23557@@ -871,7 +1110,7 @@ ENTRY(bounds)
23558 pushl_cfi $do_bounds
23559 jmp error_code
23560 CFI_ENDPROC
23561-END(bounds)
23562+ENDPROC(bounds)
23563
23564 ENTRY(invalid_op)
23565 RING0_INT_FRAME
23566@@ -880,7 +1119,7 @@ ENTRY(invalid_op)
23567 pushl_cfi $do_invalid_op
23568 jmp error_code
23569 CFI_ENDPROC
23570-END(invalid_op)
23571+ENDPROC(invalid_op)
23572
23573 ENTRY(coprocessor_segment_overrun)
23574 RING0_INT_FRAME
23575@@ -889,7 +1128,7 @@ ENTRY(coprocessor_segment_overrun)
23576 pushl_cfi $do_coprocessor_segment_overrun
23577 jmp error_code
23578 CFI_ENDPROC
23579-END(coprocessor_segment_overrun)
23580+ENDPROC(coprocessor_segment_overrun)
23581
23582 ENTRY(invalid_TSS)
23583 RING0_EC_FRAME
23584@@ -897,7 +1136,7 @@ ENTRY(invalid_TSS)
23585 pushl_cfi $do_invalid_TSS
23586 jmp error_code
23587 CFI_ENDPROC
23588-END(invalid_TSS)
23589+ENDPROC(invalid_TSS)
23590
23591 ENTRY(segment_not_present)
23592 RING0_EC_FRAME
23593@@ -905,7 +1144,7 @@ ENTRY(segment_not_present)
23594 pushl_cfi $do_segment_not_present
23595 jmp error_code
23596 CFI_ENDPROC
23597-END(segment_not_present)
23598+ENDPROC(segment_not_present)
23599
23600 ENTRY(stack_segment)
23601 RING0_EC_FRAME
23602@@ -913,7 +1152,7 @@ ENTRY(stack_segment)
23603 pushl_cfi $do_stack_segment
23604 jmp error_code
23605 CFI_ENDPROC
23606-END(stack_segment)
23607+ENDPROC(stack_segment)
23608
23609 ENTRY(alignment_check)
23610 RING0_EC_FRAME
23611@@ -921,7 +1160,7 @@ ENTRY(alignment_check)
23612 pushl_cfi $do_alignment_check
23613 jmp error_code
23614 CFI_ENDPROC
23615-END(alignment_check)
23616+ENDPROC(alignment_check)
23617
23618 ENTRY(divide_error)
23619 RING0_INT_FRAME
23620@@ -930,7 +1169,7 @@ ENTRY(divide_error)
23621 pushl_cfi $do_divide_error
23622 jmp error_code
23623 CFI_ENDPROC
23624-END(divide_error)
23625+ENDPROC(divide_error)
23626
23627 #ifdef CONFIG_X86_MCE
23628 ENTRY(machine_check)
23629@@ -940,7 +1179,7 @@ ENTRY(machine_check)
23630 pushl_cfi machine_check_vector
23631 jmp error_code
23632 CFI_ENDPROC
23633-END(machine_check)
23634+ENDPROC(machine_check)
23635 #endif
23636
23637 ENTRY(spurious_interrupt_bug)
23638@@ -950,7 +1189,7 @@ ENTRY(spurious_interrupt_bug)
23639 pushl_cfi $do_spurious_interrupt_bug
23640 jmp error_code
23641 CFI_ENDPROC
23642-END(spurious_interrupt_bug)
23643+ENDPROC(spurious_interrupt_bug)
23644
23645 #ifdef CONFIG_XEN
23646 /* Xen doesn't set %esp to be precisely what the normal sysenter
23647@@ -1056,7 +1295,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
23648
23649 ENTRY(mcount)
23650 ret
23651-END(mcount)
23652+ENDPROC(mcount)
23653
23654 ENTRY(ftrace_caller)
23655 pushl %eax
23656@@ -1086,7 +1325,7 @@ ftrace_graph_call:
23657 .globl ftrace_stub
23658 ftrace_stub:
23659 ret
23660-END(ftrace_caller)
23661+ENDPROC(ftrace_caller)
23662
23663 ENTRY(ftrace_regs_caller)
23664 pushf /* push flags before compare (in cs location) */
23665@@ -1184,7 +1423,7 @@ trace:
23666 popl %ecx
23667 popl %eax
23668 jmp ftrace_stub
23669-END(mcount)
23670+ENDPROC(mcount)
23671 #endif /* CONFIG_DYNAMIC_FTRACE */
23672 #endif /* CONFIG_FUNCTION_TRACER */
23673
23674@@ -1202,7 +1441,7 @@ ENTRY(ftrace_graph_caller)
23675 popl %ecx
23676 popl %eax
23677 ret
23678-END(ftrace_graph_caller)
23679+ENDPROC(ftrace_graph_caller)
23680
23681 .globl return_to_handler
23682 return_to_handler:
23683@@ -1263,15 +1502,18 @@ error_code:
23684 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
23685 REG_TO_PTGS %ecx
23686 SET_KERNEL_GS %ecx
23687- movl $(__USER_DS), %ecx
23688+ movl $(__KERNEL_DS), %ecx
23689 movl %ecx, %ds
23690 movl %ecx, %es
23691+
23692+ pax_enter_kernel
23693+
23694 TRACE_IRQS_OFF
23695 movl %esp,%eax # pt_regs pointer
23696 call *%edi
23697 jmp ret_from_exception
23698 CFI_ENDPROC
23699-END(page_fault)
23700+ENDPROC(page_fault)
23701
23702 /*
23703 * Debug traps and NMI can happen at the one SYSENTER instruction
23704@@ -1314,7 +1556,7 @@ debug_stack_correct:
23705 call do_debug
23706 jmp ret_from_exception
23707 CFI_ENDPROC
23708-END(debug)
23709+ENDPROC(debug)
23710
23711 /*
23712 * NMI is doubly nasty. It can happen _while_ we're handling
23713@@ -1354,6 +1596,9 @@ nmi_stack_correct:
23714 xorl %edx,%edx # zero error code
23715 movl %esp,%eax # pt_regs pointer
23716 call do_nmi
23717+
23718+ pax_exit_kernel
23719+
23720 jmp restore_all_notrace
23721 CFI_ENDPROC
23722
23723@@ -1391,13 +1636,16 @@ nmi_espfix_stack:
23724 FIXUP_ESPFIX_STACK # %eax == %esp
23725 xorl %edx,%edx # zero error code
23726 call do_nmi
23727+
23728+ pax_exit_kernel
23729+
23730 RESTORE_REGS
23731 lss 12+4(%esp), %esp # back to espfix stack
23732 CFI_ADJUST_CFA_OFFSET -24
23733 jmp irq_return
23734 #endif
23735 CFI_ENDPROC
23736-END(nmi)
23737+ENDPROC(nmi)
23738
23739 ENTRY(int3)
23740 RING0_INT_FRAME
23741@@ -1410,14 +1658,14 @@ ENTRY(int3)
23742 call do_int3
23743 jmp ret_from_exception
23744 CFI_ENDPROC
23745-END(int3)
23746+ENDPROC(int3)
23747
23748 ENTRY(general_protection)
23749 RING0_EC_FRAME
23750 pushl_cfi $do_general_protection
23751 jmp error_code
23752 CFI_ENDPROC
23753-END(general_protection)
23754+ENDPROC(general_protection)
23755
23756 #ifdef CONFIG_KVM_GUEST
23757 ENTRY(async_page_fault)
23758@@ -1426,6 +1674,6 @@ ENTRY(async_page_fault)
23759 pushl_cfi $do_async_page_fault
23760 jmp error_code
23761 CFI_ENDPROC
23762-END(async_page_fault)
23763+ENDPROC(async_page_fault)
23764 #endif
23765
23766diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
23767index 2fac134..b020fca 100644
23768--- a/arch/x86/kernel/entry_64.S
23769+++ b/arch/x86/kernel/entry_64.S
23770@@ -59,6 +59,8 @@
23771 #include <asm/smap.h>
23772 #include <asm/pgtable_types.h>
23773 #include <linux/err.h>
23774+#include <asm/pgtable.h>
23775+#include <asm/alternative-asm.h>
23776
23777 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
23778 #include <linux/elf-em.h>
23779@@ -81,6 +83,430 @@ ENTRY(native_usergs_sysret64)
23780 ENDPROC(native_usergs_sysret64)
23781 #endif /* CONFIG_PARAVIRT */
23782
23783+ .macro ljmpq sel, off
23784+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
23785+ .byte 0x48; ljmp *1234f(%rip)
23786+ .pushsection .rodata
23787+ .align 16
23788+ 1234: .quad \off; .word \sel
23789+ .popsection
23790+#else
23791+ pushq $\sel
23792+ pushq $\off
23793+ lretq
23794+#endif
23795+ .endm
23796+
23797+ .macro pax_enter_kernel
23798+ pax_set_fptr_mask
23799+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23800+ call pax_enter_kernel
23801+#endif
23802+ .endm
23803+
23804+ .macro pax_exit_kernel
23805+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23806+ call pax_exit_kernel
23807+#endif
23808+
23809+ .endm
23810+
23811+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
23812+ENTRY(pax_enter_kernel)
23813+ pushq %rdi
23814+
23815+#ifdef CONFIG_PARAVIRT
23816+ PV_SAVE_REGS(CLBR_RDI)
23817+#endif
23818+
23819+#ifdef CONFIG_PAX_KERNEXEC
23820+ GET_CR0_INTO_RDI
23821+ bts $16,%rdi
23822+ jnc 3f
23823+ mov %cs,%edi
23824+ cmp $__KERNEL_CS,%edi
23825+ jnz 2f
23826+1:
23827+#endif
23828+
23829+#ifdef CONFIG_PAX_MEMORY_UDEREF
23830+ 661: jmp 111f
23831+ .pushsection .altinstr_replacement, "a"
23832+ 662: ASM_NOP2
23833+ .popsection
23834+ .pushsection .altinstructions, "a"
23835+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23836+ .popsection
23837+ GET_CR3_INTO_RDI
23838+ cmp $0,%dil
23839+ jnz 112f
23840+ mov $__KERNEL_DS,%edi
23841+ mov %edi,%ss
23842+ jmp 111f
23843+112: cmp $1,%dil
23844+ jz 113f
23845+ ud2
23846+113: sub $4097,%rdi
23847+ bts $63,%rdi
23848+ SET_RDI_INTO_CR3
23849+ mov $__UDEREF_KERNEL_DS,%edi
23850+ mov %edi,%ss
23851+111:
23852+#endif
23853+
23854+#ifdef CONFIG_PARAVIRT
23855+ PV_RESTORE_REGS(CLBR_RDI)
23856+#endif
23857+
23858+ popq %rdi
23859+ pax_force_retaddr
23860+ retq
23861+
23862+#ifdef CONFIG_PAX_KERNEXEC
23863+2: ljmpq __KERNEL_CS,1b
23864+3: ljmpq __KERNEXEC_KERNEL_CS,4f
23865+4: SET_RDI_INTO_CR0
23866+ jmp 1b
23867+#endif
23868+ENDPROC(pax_enter_kernel)
23869+
23870+ENTRY(pax_exit_kernel)
23871+ pushq %rdi
23872+
23873+#ifdef CONFIG_PARAVIRT
23874+ PV_SAVE_REGS(CLBR_RDI)
23875+#endif
23876+
23877+#ifdef CONFIG_PAX_KERNEXEC
23878+ mov %cs,%rdi
23879+ cmp $__KERNEXEC_KERNEL_CS,%edi
23880+ jz 2f
23881+ GET_CR0_INTO_RDI
23882+ bts $16,%rdi
23883+ jnc 4f
23884+1:
23885+#endif
23886+
23887+#ifdef CONFIG_PAX_MEMORY_UDEREF
23888+ 661: jmp 111f
23889+ .pushsection .altinstr_replacement, "a"
23890+ 662: ASM_NOP2
23891+ .popsection
23892+ .pushsection .altinstructions, "a"
23893+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23894+ .popsection
23895+ mov %ss,%edi
23896+ cmp $__UDEREF_KERNEL_DS,%edi
23897+ jnz 111f
23898+ GET_CR3_INTO_RDI
23899+ cmp $0,%dil
23900+ jz 112f
23901+ ud2
23902+112: add $4097,%rdi
23903+ bts $63,%rdi
23904+ SET_RDI_INTO_CR3
23905+ mov $__KERNEL_DS,%edi
23906+ mov %edi,%ss
23907+111:
23908+#endif
23909+
23910+#ifdef CONFIG_PARAVIRT
23911+ PV_RESTORE_REGS(CLBR_RDI);
23912+#endif
23913+
23914+ popq %rdi
23915+ pax_force_retaddr
23916+ retq
23917+
23918+#ifdef CONFIG_PAX_KERNEXEC
23919+2: GET_CR0_INTO_RDI
23920+ btr $16,%rdi
23921+ jnc 4f
23922+ ljmpq __KERNEL_CS,3f
23923+3: SET_RDI_INTO_CR0
23924+ jmp 1b
23925+4: ud2
23926+ jmp 4b
23927+#endif
23928+ENDPROC(pax_exit_kernel)
23929+#endif
23930+
23931+ .macro pax_enter_kernel_user
23932+ pax_set_fptr_mask
23933+#ifdef CONFIG_PAX_MEMORY_UDEREF
23934+ call pax_enter_kernel_user
23935+#endif
23936+ .endm
23937+
23938+ .macro pax_exit_kernel_user
23939+#ifdef CONFIG_PAX_MEMORY_UDEREF
23940+ call pax_exit_kernel_user
23941+#endif
23942+#ifdef CONFIG_PAX_RANDKSTACK
23943+ pushq %rax
23944+ pushq %r11
23945+ call pax_randomize_kstack
23946+ popq %r11
23947+ popq %rax
23948+#endif
23949+ .endm
23950+
23951+#ifdef CONFIG_PAX_MEMORY_UDEREF
23952+ENTRY(pax_enter_kernel_user)
23953+ pushq %rdi
23954+ pushq %rbx
23955+
23956+#ifdef CONFIG_PARAVIRT
23957+ PV_SAVE_REGS(CLBR_RDI)
23958+#endif
23959+
23960+ 661: jmp 111f
23961+ .pushsection .altinstr_replacement, "a"
23962+ 662: ASM_NOP2
23963+ .popsection
23964+ .pushsection .altinstructions, "a"
23965+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23966+ .popsection
23967+ GET_CR3_INTO_RDI
23968+ cmp $1,%dil
23969+ jnz 4f
23970+ sub $4097,%rdi
23971+ bts $63,%rdi
23972+ SET_RDI_INTO_CR3
23973+ jmp 3f
23974+111:
23975+
23976+ GET_CR3_INTO_RDI
23977+ mov %rdi,%rbx
23978+ add $__START_KERNEL_map,%rbx
23979+ sub phys_base(%rip),%rbx
23980+
23981+#ifdef CONFIG_PARAVIRT
23982+ cmpl $0, pv_info+PARAVIRT_enabled
23983+ jz 1f
23984+ pushq %rdi
23985+ i = 0
23986+ .rept USER_PGD_PTRS
23987+ mov i*8(%rbx),%rsi
23988+ mov $0,%sil
23989+ lea i*8(%rbx),%rdi
23990+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23991+ i = i + 1
23992+ .endr
23993+ popq %rdi
23994+ jmp 2f
23995+1:
23996+#endif
23997+
23998+ i = 0
23999+ .rept USER_PGD_PTRS
24000+ movb $0,i*8(%rbx)
24001+ i = i + 1
24002+ .endr
24003+
24004+2: SET_RDI_INTO_CR3
24005+
24006+#ifdef CONFIG_PAX_KERNEXEC
24007+ GET_CR0_INTO_RDI
24008+ bts $16,%rdi
24009+ SET_RDI_INTO_CR0
24010+#endif
24011+
24012+3:
24013+
24014+#ifdef CONFIG_PARAVIRT
24015+ PV_RESTORE_REGS(CLBR_RDI)
24016+#endif
24017+
24018+ popq %rbx
24019+ popq %rdi
24020+ pax_force_retaddr
24021+ retq
24022+4: ud2
24023+ENDPROC(pax_enter_kernel_user)
24024+
24025+ENTRY(pax_exit_kernel_user)
24026+ pushq %rdi
24027+ pushq %rbx
24028+
24029+#ifdef CONFIG_PARAVIRT
24030+ PV_SAVE_REGS(CLBR_RDI)
24031+#endif
24032+
24033+ GET_CR3_INTO_RDI
24034+ 661: jmp 1f
24035+ .pushsection .altinstr_replacement, "a"
24036+ 662: ASM_NOP2
24037+ .popsection
24038+ .pushsection .altinstructions, "a"
24039+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
24040+ .popsection
24041+ cmp $0,%dil
24042+ jnz 3f
24043+ add $4097,%rdi
24044+ bts $63,%rdi
24045+ SET_RDI_INTO_CR3
24046+ jmp 2f
24047+1:
24048+
24049+ mov %rdi,%rbx
24050+
24051+#ifdef CONFIG_PAX_KERNEXEC
24052+ GET_CR0_INTO_RDI
24053+ btr $16,%rdi
24054+ jnc 3f
24055+ SET_RDI_INTO_CR0
24056+#endif
24057+
24058+ add $__START_KERNEL_map,%rbx
24059+ sub phys_base(%rip),%rbx
24060+
24061+#ifdef CONFIG_PARAVIRT
24062+ cmpl $0, pv_info+PARAVIRT_enabled
24063+ jz 1f
24064+ i = 0
24065+ .rept USER_PGD_PTRS
24066+ mov i*8(%rbx),%rsi
24067+ mov $0x67,%sil
24068+ lea i*8(%rbx),%rdi
24069+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
24070+ i = i + 1
24071+ .endr
24072+ jmp 2f
24073+1:
24074+#endif
24075+
24076+ i = 0
24077+ .rept USER_PGD_PTRS
24078+ movb $0x67,i*8(%rbx)
24079+ i = i + 1
24080+ .endr
24081+2:
24082+
24083+#ifdef CONFIG_PARAVIRT
24084+ PV_RESTORE_REGS(CLBR_RDI)
24085+#endif
24086+
24087+ popq %rbx
24088+ popq %rdi
24089+ pax_force_retaddr
24090+ retq
24091+3: ud2
24092+ENDPROC(pax_exit_kernel_user)
24093+#endif
24094+
24095+ .macro pax_enter_kernel_nmi
24096+ pax_set_fptr_mask
24097+
24098+#ifdef CONFIG_PAX_KERNEXEC
24099+ GET_CR0_INTO_RDI
24100+ bts $16,%rdi
24101+ jc 110f
24102+ SET_RDI_INTO_CR0
24103+ or $2,%ebx
24104+110:
24105+#endif
24106+
24107+#ifdef CONFIG_PAX_MEMORY_UDEREF
24108+ 661: jmp 111f
24109+ .pushsection .altinstr_replacement, "a"
24110+ 662: ASM_NOP2
24111+ .popsection
24112+ .pushsection .altinstructions, "a"
24113+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
24114+ .popsection
24115+ GET_CR3_INTO_RDI
24116+ cmp $0,%dil
24117+ jz 111f
24118+ sub $4097,%rdi
24119+ or $4,%ebx
24120+ bts $63,%rdi
24121+ SET_RDI_INTO_CR3
24122+ mov $__UDEREF_KERNEL_DS,%edi
24123+ mov %edi,%ss
24124+111:
24125+#endif
24126+ .endm
24127+
24128+ .macro pax_exit_kernel_nmi
24129+#ifdef CONFIG_PAX_KERNEXEC
24130+ btr $1,%ebx
24131+ jnc 110f
24132+ GET_CR0_INTO_RDI
24133+ btr $16,%rdi
24134+ SET_RDI_INTO_CR0
24135+110:
24136+#endif
24137+
24138+#ifdef CONFIG_PAX_MEMORY_UDEREF
24139+ btr $2,%ebx
24140+ jnc 111f
24141+ GET_CR3_INTO_RDI
24142+ add $4097,%rdi
24143+ bts $63,%rdi
24144+ SET_RDI_INTO_CR3
24145+ mov $__KERNEL_DS,%edi
24146+ mov %edi,%ss
24147+111:
24148+#endif
24149+ .endm
24150+
24151+ .macro pax_erase_kstack
24152+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
24153+ call pax_erase_kstack
24154+#endif
24155+ .endm
24156+
24157+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
24158+ENTRY(pax_erase_kstack)
24159+ pushq %rdi
24160+ pushq %rcx
24161+ pushq %rax
24162+ pushq %r11
24163+
24164+ GET_THREAD_INFO(%r11)
24165+ mov TI_lowest_stack(%r11), %rdi
24166+ mov $-0xBEEF, %rax
24167+ std
24168+
24169+1: mov %edi, %ecx
24170+ and $THREAD_SIZE_asm - 1, %ecx
24171+ shr $3, %ecx
24172+ repne scasq
24173+ jecxz 2f
24174+
24175+ cmp $2*8, %ecx
24176+ jc 2f
24177+
24178+ mov $2*8, %ecx
24179+ repe scasq
24180+ jecxz 2f
24181+ jne 1b
24182+
24183+2: cld
24184+ mov %esp, %ecx
24185+ sub %edi, %ecx
24186+
24187+ cmp $THREAD_SIZE_asm, %rcx
24188+ jb 3f
24189+ ud2
24190+3:
24191+
24192+ shr $3, %ecx
24193+ rep stosq
24194+
24195+ mov TI_task_thread_sp0(%r11), %rdi
24196+ sub $256, %rdi
24197+ mov %rdi, TI_lowest_stack(%r11)
24198+
24199+ popq %r11
24200+ popq %rax
24201+ popq %rcx
24202+ popq %rdi
24203+ pax_force_retaddr
24204+ ret
24205+ENDPROC(pax_erase_kstack)
24206+#endif
24207
24208 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
24209 #ifdef CONFIG_TRACE_IRQFLAGS
24210@@ -117,7 +543,7 @@ ENDPROC(native_usergs_sysret64)
24211 .endm
24212
24213 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
24214- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
24215+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
24216 jnc 1f
24217 TRACE_IRQS_ON_DEBUG
24218 1:
24219@@ -155,27 +581,6 @@ ENDPROC(native_usergs_sysret64)
24220 movq \tmp,R11+\offset(%rsp)
24221 .endm
24222
24223- .macro FAKE_STACK_FRAME child_rip
24224- /* push in order ss, rsp, eflags, cs, rip */
24225- xorl %eax, %eax
24226- pushq_cfi $__KERNEL_DS /* ss */
24227- /*CFI_REL_OFFSET ss,0*/
24228- pushq_cfi %rax /* rsp */
24229- CFI_REL_OFFSET rsp,0
24230- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
24231- /*CFI_REL_OFFSET rflags,0*/
24232- pushq_cfi $__KERNEL_CS /* cs */
24233- /*CFI_REL_OFFSET cs,0*/
24234- pushq_cfi \child_rip /* rip */
24235- CFI_REL_OFFSET rip,0
24236- pushq_cfi %rax /* orig rax */
24237- .endm
24238-
24239- .macro UNFAKE_STACK_FRAME
24240- addq $8*6, %rsp
24241- CFI_ADJUST_CFA_OFFSET -(6*8)
24242- .endm
24243-
24244 /*
24245 * initial frame state for interrupts (and exceptions without error code)
24246 */
24247@@ -241,25 +646,26 @@ ENDPROC(native_usergs_sysret64)
24248 /* save partial stack frame */
24249 .macro SAVE_ARGS_IRQ
24250 cld
24251- /* start from rbp in pt_regs and jump over */
24252- movq_cfi rdi, (RDI-RBP)
24253- movq_cfi rsi, (RSI-RBP)
24254- movq_cfi rdx, (RDX-RBP)
24255- movq_cfi rcx, (RCX-RBP)
24256- movq_cfi rax, (RAX-RBP)
24257- movq_cfi r8, (R8-RBP)
24258- movq_cfi r9, (R9-RBP)
24259- movq_cfi r10, (R10-RBP)
24260- movq_cfi r11, (R11-RBP)
24261+ /* start from r15 in pt_regs and jump over */
24262+ movq_cfi rdi, RDI
24263+ movq_cfi rsi, RSI
24264+ movq_cfi rdx, RDX
24265+ movq_cfi rcx, RCX
24266+ movq_cfi rax, RAX
24267+ movq_cfi r8, R8
24268+ movq_cfi r9, R9
24269+ movq_cfi r10, R10
24270+ movq_cfi r11, R11
24271+ movq_cfi r12, R12
24272
24273 /* Save rbp so that we can unwind from get_irq_regs() */
24274- movq_cfi rbp, 0
24275+ movq_cfi rbp, RBP
24276
24277 /* Save previous stack value */
24278 movq %rsp, %rsi
24279
24280- leaq -RBP(%rsp),%rdi /* arg1 for handler */
24281- testl $3, CS-RBP(%rsi)
24282+ movq %rsp,%rdi /* arg1 for handler */
24283+ testb $3, CS(%rsi)
24284 je 1f
24285 SWAPGS
24286 /*
24287@@ -279,6 +685,18 @@ ENDPROC(native_usergs_sysret64)
24288 0x06 /* DW_OP_deref */, \
24289 0x08 /* DW_OP_const1u */, SS+8-RBP, \
24290 0x22 /* DW_OP_plus */
24291+
24292+#ifdef CONFIG_PAX_MEMORY_UDEREF
24293+ testb $3, CS(%rdi)
24294+ jnz 1f
24295+ pax_enter_kernel
24296+ jmp 2f
24297+1: pax_enter_kernel_user
24298+2:
24299+#else
24300+ pax_enter_kernel
24301+#endif
24302+
24303 /* We entered an interrupt context - irqs are off: */
24304 TRACE_IRQS_OFF
24305 .endm
24306@@ -308,9 +726,52 @@ ENTRY(save_paranoid)
24307 js 1f /* negative -> in kernel */
24308 SWAPGS
24309 xorl %ebx,%ebx
24310-1: ret
24311+1:
24312+#ifdef CONFIG_PAX_MEMORY_UDEREF
24313+ testb $3, CS+8(%rsp)
24314+ jnz 1f
24315+ pax_enter_kernel
24316+ jmp 2f
24317+1: pax_enter_kernel_user
24318+2:
24319+#else
24320+ pax_enter_kernel
24321+#endif
24322+ pax_force_retaddr
24323+ ret
24324 CFI_ENDPROC
24325-END(save_paranoid)
24326+ENDPROC(save_paranoid)
24327+
24328+ENTRY(save_paranoid_nmi)
24329+ XCPT_FRAME 1 RDI+8
24330+ cld
24331+ movq_cfi rdi, RDI+8
24332+ movq_cfi rsi, RSI+8
24333+ movq_cfi rdx, RDX+8
24334+ movq_cfi rcx, RCX+8
24335+ movq_cfi rax, RAX+8
24336+ movq_cfi r8, R8+8
24337+ movq_cfi r9, R9+8
24338+ movq_cfi r10, R10+8
24339+ movq_cfi r11, R11+8
24340+ movq_cfi rbx, RBX+8
24341+ movq_cfi rbp, RBP+8
24342+ movq_cfi r12, R12+8
24343+ movq_cfi r13, R13+8
24344+ movq_cfi r14, R14+8
24345+ movq_cfi r15, R15+8
24346+ movl $1,%ebx
24347+ movl $MSR_GS_BASE,%ecx
24348+ rdmsr
24349+ testl %edx,%edx
24350+ js 1f /* negative -> in kernel */
24351+ SWAPGS
24352+ xorl %ebx,%ebx
24353+1: pax_enter_kernel_nmi
24354+ pax_force_retaddr
24355+ ret
24356+ CFI_ENDPROC
24357+ENDPROC(save_paranoid_nmi)
24358
24359 /*
24360 * A newly forked process directly context switches into this address.
24361@@ -331,7 +792,7 @@ ENTRY(ret_from_fork)
24362
24363 RESTORE_REST
24364
24365- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
24366+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
24367 jz 1f
24368
24369 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
24370@@ -341,15 +802,13 @@ ENTRY(ret_from_fork)
24371 jmp ret_from_sys_call # go to the SYSRET fastpath
24372
24373 1:
24374- subq $REST_SKIP, %rsp # leave space for volatiles
24375- CFI_ADJUST_CFA_OFFSET REST_SKIP
24376 movq %rbp, %rdi
24377 call *%rbx
24378 movl $0, RAX(%rsp)
24379 RESTORE_REST
24380 jmp int_ret_from_sys_call
24381 CFI_ENDPROC
24382-END(ret_from_fork)
24383+ENDPROC(ret_from_fork)
24384
24385 /*
24386 * System call entry. Up to 6 arguments in registers are supported.
24387@@ -386,7 +845,7 @@ END(ret_from_fork)
24388 ENTRY(system_call)
24389 CFI_STARTPROC simple
24390 CFI_SIGNAL_FRAME
24391- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
24392+ CFI_DEF_CFA rsp,0
24393 CFI_REGISTER rip,rcx
24394 /*CFI_REGISTER rflags,r11*/
24395 SWAPGS_UNSAFE_STACK
24396@@ -399,16 +858,23 @@ GLOBAL(system_call_after_swapgs)
24397
24398 movq %rsp,PER_CPU_VAR(old_rsp)
24399 movq PER_CPU_VAR(kernel_stack),%rsp
24400+ SAVE_ARGS 8*6,0
24401+ pax_enter_kernel_user
24402+
24403+#ifdef CONFIG_PAX_RANDKSTACK
24404+ pax_erase_kstack
24405+#endif
24406+
24407 /*
24408 * No need to follow this irqs off/on section - it's straight
24409 * and short:
24410 */
24411 ENABLE_INTERRUPTS(CLBR_NONE)
24412- SAVE_ARGS 8,0
24413 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
24414 movq %rcx,RIP-ARGOFFSET(%rsp)
24415 CFI_REL_OFFSET rip,RIP-ARGOFFSET
24416- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
24417+ GET_THREAD_INFO(%rcx)
24418+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
24419 jnz tracesys
24420 system_call_fastpath:
24421 #if __SYSCALL_MASK == ~0
24422@@ -432,10 +898,13 @@ sysret_check:
24423 LOCKDEP_SYS_EXIT
24424 DISABLE_INTERRUPTS(CLBR_NONE)
24425 TRACE_IRQS_OFF
24426- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
24427+ GET_THREAD_INFO(%rcx)
24428+ movl TI_flags(%rcx),%edx
24429 andl %edi,%edx
24430 jnz sysret_careful
24431 CFI_REMEMBER_STATE
24432+ pax_exit_kernel_user
24433+ pax_erase_kstack
24434 /*
24435 * sysretq will re-enable interrupts:
24436 */
24437@@ -494,6 +963,9 @@ auditsys:
24438 movq %rax,%rsi /* 2nd arg: syscall number */
24439 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
24440 call __audit_syscall_entry
24441+
24442+ pax_erase_kstack
24443+
24444 LOAD_ARGS 0 /* reload call-clobbered registers */
24445 jmp system_call_fastpath
24446
24447@@ -515,7 +987,7 @@ sysret_audit:
24448 /* Do syscall tracing */
24449 tracesys:
24450 #ifdef CONFIG_AUDITSYSCALL
24451- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
24452+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
24453 jz auditsys
24454 #endif
24455 SAVE_REST
24456@@ -523,12 +995,15 @@ tracesys:
24457 FIXUP_TOP_OF_STACK %rdi
24458 movq %rsp,%rdi
24459 call syscall_trace_enter
24460+
24461+ pax_erase_kstack
24462+
24463 /*
24464 * Reload arg registers from stack in case ptrace changed them.
24465 * We don't reload %rax because syscall_trace_enter() returned
24466 * the value it wants us to use in the table lookup.
24467 */
24468- LOAD_ARGS ARGOFFSET, 1
24469+ LOAD_ARGS 1
24470 RESTORE_REST
24471 #if __SYSCALL_MASK == ~0
24472 cmpq $__NR_syscall_max,%rax
24473@@ -558,7 +1033,9 @@ GLOBAL(int_with_check)
24474 andl %edi,%edx
24475 jnz int_careful
24476 andl $~TS_COMPAT,TI_status(%rcx)
24477- jmp retint_swapgs
24478+ pax_exit_kernel_user
24479+ pax_erase_kstack
24480+ jmp retint_swapgs_pax
24481
24482 /* Either reschedule or signal or syscall exit tracking needed. */
24483 /* First do a reschedule test. */
24484@@ -604,7 +1081,7 @@ int_restore_rest:
24485 TRACE_IRQS_OFF
24486 jmp int_with_check
24487 CFI_ENDPROC
24488-END(system_call)
24489+ENDPROC(system_call)
24490
24491 .macro FORK_LIKE func
24492 ENTRY(stub_\func)
24493@@ -617,9 +1094,10 @@ ENTRY(stub_\func)
24494 DEFAULT_FRAME 0 8 /* offset 8: return address */
24495 call sys_\func
24496 RESTORE_TOP_OF_STACK %r11, 8
24497- ret $REST_SKIP /* pop extended registers */
24498+ pax_force_retaddr
24499+ ret
24500 CFI_ENDPROC
24501-END(stub_\func)
24502+ENDPROC(stub_\func)
24503 .endm
24504
24505 .macro FIXED_FRAME label,func
24506@@ -629,9 +1107,10 @@ ENTRY(\label)
24507 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
24508 call \func
24509 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
24510+ pax_force_retaddr
24511 ret
24512 CFI_ENDPROC
24513-END(\label)
24514+ENDPROC(\label)
24515 .endm
24516
24517 FORK_LIKE clone
24518@@ -639,19 +1118,6 @@ END(\label)
24519 FORK_LIKE vfork
24520 FIXED_FRAME stub_iopl, sys_iopl
24521
24522-ENTRY(ptregscall_common)
24523- DEFAULT_FRAME 1 8 /* offset 8: return address */
24524- RESTORE_TOP_OF_STACK %r11, 8
24525- movq_cfi_restore R15+8, r15
24526- movq_cfi_restore R14+8, r14
24527- movq_cfi_restore R13+8, r13
24528- movq_cfi_restore R12+8, r12
24529- movq_cfi_restore RBP+8, rbp
24530- movq_cfi_restore RBX+8, rbx
24531- ret $REST_SKIP /* pop extended registers */
24532- CFI_ENDPROC
24533-END(ptregscall_common)
24534-
24535 ENTRY(stub_execve)
24536 CFI_STARTPROC
24537 addq $8, %rsp
24538@@ -663,7 +1129,7 @@ ENTRY(stub_execve)
24539 RESTORE_REST
24540 jmp int_ret_from_sys_call
24541 CFI_ENDPROC
24542-END(stub_execve)
24543+ENDPROC(stub_execve)
24544
24545 /*
24546 * sigreturn is special because it needs to restore all registers on return.
24547@@ -680,7 +1146,7 @@ ENTRY(stub_rt_sigreturn)
24548 RESTORE_REST
24549 jmp int_ret_from_sys_call
24550 CFI_ENDPROC
24551-END(stub_rt_sigreturn)
24552+ENDPROC(stub_rt_sigreturn)
24553
24554 #ifdef CONFIG_X86_X32_ABI
24555 ENTRY(stub_x32_rt_sigreturn)
24556@@ -694,7 +1160,7 @@ ENTRY(stub_x32_rt_sigreturn)
24557 RESTORE_REST
24558 jmp int_ret_from_sys_call
24559 CFI_ENDPROC
24560-END(stub_x32_rt_sigreturn)
24561+ENDPROC(stub_x32_rt_sigreturn)
24562
24563 ENTRY(stub_x32_execve)
24564 CFI_STARTPROC
24565@@ -708,7 +1174,7 @@ ENTRY(stub_x32_execve)
24566 RESTORE_REST
24567 jmp int_ret_from_sys_call
24568 CFI_ENDPROC
24569-END(stub_x32_execve)
24570+ENDPROC(stub_x32_execve)
24571
24572 #endif
24573
24574@@ -745,7 +1211,7 @@ vector=vector+1
24575 2: jmp common_interrupt
24576 .endr
24577 CFI_ENDPROC
24578-END(irq_entries_start)
24579+ENDPROC(irq_entries_start)
24580
24581 .previous
24582 END(interrupt)
24583@@ -762,8 +1228,8 @@ END(interrupt)
24584 /* 0(%rsp): ~(interrupt number) */
24585 .macro interrupt func
24586 /* reserve pt_regs for scratch regs and rbp */
24587- subq $ORIG_RAX-RBP, %rsp
24588- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
24589+ subq $ORIG_RAX, %rsp
24590+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
24591 SAVE_ARGS_IRQ
24592 call \func
24593 .endm
24594@@ -786,14 +1252,14 @@ ret_from_intr:
24595
24596 /* Restore saved previous stack */
24597 popq %rsi
24598- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
24599- leaq ARGOFFSET-RBP(%rsi), %rsp
24600+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
24601+ movq %rsi, %rsp
24602 CFI_DEF_CFA_REGISTER rsp
24603- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
24604+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
24605
24606 exit_intr:
24607 GET_THREAD_INFO(%rcx)
24608- testl $3,CS-ARGOFFSET(%rsp)
24609+ testb $3,CS-ARGOFFSET(%rsp)
24610 je retint_kernel
24611
24612 /* Interrupt came from user space */
24613@@ -815,12 +1281,35 @@ retint_swapgs: /* return to user-space */
24614 * The iretq could re-enable interrupts:
24615 */
24616 DISABLE_INTERRUPTS(CLBR_ANY)
24617+ pax_exit_kernel_user
24618+retint_swapgs_pax:
24619 TRACE_IRQS_IRETQ
24620 SWAPGS
24621 jmp restore_args
24622
24623 retint_restore_args: /* return to kernel space */
24624 DISABLE_INTERRUPTS(CLBR_ANY)
24625+ pax_exit_kernel
24626+
24627+#if defined(CONFIG_EFI) && defined(CONFIG_PAX_KERNEXEC)
24628+ /* This is a quirk to allow IRQs/NMIs/MCEs during early EFI setup,
24629+ * namely calling EFI runtime services with a phys mapping. We're
24630+ * starting off with NOPs and patch in the real instrumentation
24631+ * (BTS/OR) before starting any userland process; even before starting
24632+ * up the APs.
24633+ */
24634+ .pushsection .altinstr_replacement, "a"
24635+ 601: pax_force_retaddr (RIP-ARGOFFSET)
24636+ 602:
24637+ .popsection
24638+ 603: .fill 602b-601b, 1, 0x90
24639+ .pushsection .altinstructions, "a"
24640+ altinstruction_entry 603b, 601b, X86_FEATURE_ALWAYS, 602b-601b, 602b-601b
24641+ .popsection
24642+#else
24643+ pax_force_retaddr (RIP-ARGOFFSET)
24644+#endif
24645+
24646 /*
24647 * The iretq could re-enable interrupts:
24648 */
24649@@ -933,7 +1422,7 @@ ENTRY(retint_kernel)
24650 jmp exit_intr
24651 #endif
24652 CFI_ENDPROC
24653-END(common_interrupt)
24654+ENDPROC(common_interrupt)
24655
24656 /*
24657 * If IRET takes a fault on the espfix stack, then we
24658@@ -955,13 +1444,13 @@ __do_double_fault:
24659 cmpq $native_irq_return_iret,%rax
24660 jne do_double_fault /* This shouldn't happen... */
24661 movq PER_CPU_VAR(kernel_stack),%rax
24662- subq $(6*8-KERNEL_STACK_OFFSET),%rax /* Reset to original stack */
24663+ subq $(6*8),%rax /* Reset to original stack */
24664 movq %rax,RSP(%rdi)
24665 movq $0,(%rax) /* Missing (lost) #GP error code */
24666 movq $general_protection,RIP(%rdi)
24667 retq
24668 CFI_ENDPROC
24669-END(__do_double_fault)
24670+ENDPROC(__do_double_fault)
24671 #else
24672 # define __do_double_fault do_double_fault
24673 #endif
24674@@ -978,7 +1467,7 @@ ENTRY(\sym)
24675 interrupt \do_sym
24676 jmp ret_from_intr
24677 CFI_ENDPROC
24678-END(\sym)
24679+ENDPROC(\sym)
24680 .endm
24681
24682 #ifdef CONFIG_TRACING
24683@@ -1051,7 +1540,7 @@ apicinterrupt IRQ_WORK_VECTOR \
24684 /*
24685 * Exception entry points.
24686 */
24687-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
24688+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
24689
24690 .macro idtentry sym do_sym has_error_code:req paranoid=0 shift_ist=-1
24691 ENTRY(\sym)
24692@@ -1102,6 +1591,12 @@ ENTRY(\sym)
24693 .endif
24694
24695 .if \shift_ist != -1
24696+#ifdef CONFIG_SMP
24697+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
24698+ lea init_tss(%r13), %r13
24699+#else
24700+ lea init_tss(%rip), %r13
24701+#endif
24702 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\shift_ist)
24703 .endif
24704
24705@@ -1118,7 +1613,7 @@ ENTRY(\sym)
24706 .endif
24707
24708 CFI_ENDPROC
24709-END(\sym)
24710+ENDPROC(\sym)
24711 .endm
24712
24713 #ifdef CONFIG_TRACING
24714@@ -1159,9 +1654,10 @@ gs_change:
24715 2: mfence /* workaround */
24716 SWAPGS
24717 popfq_cfi
24718+ pax_force_retaddr
24719 ret
24720 CFI_ENDPROC
24721-END(native_load_gs_index)
24722+ENDPROC(native_load_gs_index)
24723
24724 _ASM_EXTABLE(gs_change,bad_gs)
24725 .section .fixup,"ax"
24726@@ -1189,9 +1685,10 @@ ENTRY(do_softirq_own_stack)
24727 CFI_DEF_CFA_REGISTER rsp
24728 CFI_ADJUST_CFA_OFFSET -8
24729 decl PER_CPU_VAR(irq_count)
24730+ pax_force_retaddr
24731 ret
24732 CFI_ENDPROC
24733-END(do_softirq_own_stack)
24734+ENDPROC(do_softirq_own_stack)
24735
24736 #ifdef CONFIG_XEN
24737 idtentry xen_hypervisor_callback xen_do_hypervisor_callback has_error_code=0
24738@@ -1229,7 +1726,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
24739 decl PER_CPU_VAR(irq_count)
24740 jmp error_exit
24741 CFI_ENDPROC
24742-END(xen_do_hypervisor_callback)
24743+ENDPROC(xen_do_hypervisor_callback)
24744
24745 /*
24746 * Hypervisor uses this for application faults while it executes.
24747@@ -1288,7 +1785,7 @@ ENTRY(xen_failsafe_callback)
24748 SAVE_ALL
24749 jmp error_exit
24750 CFI_ENDPROC
24751-END(xen_failsafe_callback)
24752+ENDPROC(xen_failsafe_callback)
24753
24754 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
24755 xen_hvm_callback_vector xen_evtchn_do_upcall
24756@@ -1335,18 +1832,33 @@ ENTRY(paranoid_exit)
24757 DEFAULT_FRAME
24758 DISABLE_INTERRUPTS(CLBR_NONE)
24759 TRACE_IRQS_OFF_DEBUG
24760- testl %ebx,%ebx /* swapgs needed? */
24761+ testl $1,%ebx /* swapgs needed? */
24762 jnz paranoid_restore
24763- testl $3,CS(%rsp)
24764+ testb $3,CS(%rsp)
24765 jnz paranoid_userspace
24766+#ifdef CONFIG_PAX_MEMORY_UDEREF
24767+ pax_exit_kernel
24768+ TRACE_IRQS_IRETQ 0
24769+ SWAPGS_UNSAFE_STACK
24770+ RESTORE_ALL 8
24771+ pax_force_retaddr_bts
24772+ jmp irq_return
24773+#endif
24774 paranoid_swapgs:
24775+#ifdef CONFIG_PAX_MEMORY_UDEREF
24776+ pax_exit_kernel_user
24777+#else
24778+ pax_exit_kernel
24779+#endif
24780 TRACE_IRQS_IRETQ 0
24781 SWAPGS_UNSAFE_STACK
24782 RESTORE_ALL 8
24783 jmp irq_return
24784 paranoid_restore:
24785+ pax_exit_kernel
24786 TRACE_IRQS_IRETQ_DEBUG 0
24787 RESTORE_ALL 8
24788+ pax_force_retaddr_bts
24789 jmp irq_return
24790 paranoid_userspace:
24791 GET_THREAD_INFO(%rcx)
24792@@ -1375,7 +1887,7 @@ paranoid_schedule:
24793 TRACE_IRQS_OFF
24794 jmp paranoid_userspace
24795 CFI_ENDPROC
24796-END(paranoid_exit)
24797+ENDPROC(paranoid_exit)
24798
24799 /*
24800 * Exception entry point. This expects an error code/orig_rax on the stack.
24801@@ -1402,12 +1914,23 @@ ENTRY(error_entry)
24802 movq %r14, R14+8(%rsp)
24803 movq %r15, R15+8(%rsp)
24804 xorl %ebx,%ebx
24805- testl $3,CS+8(%rsp)
24806+ testb $3,CS+8(%rsp)
24807 je error_kernelspace
24808 error_swapgs:
24809 SWAPGS
24810 error_sti:
24811+#ifdef CONFIG_PAX_MEMORY_UDEREF
24812+ testb $3, CS+8(%rsp)
24813+ jnz 1f
24814+ pax_enter_kernel
24815+ jmp 2f
24816+1: pax_enter_kernel_user
24817+2:
24818+#else
24819+ pax_enter_kernel
24820+#endif
24821 TRACE_IRQS_OFF
24822+ pax_force_retaddr
24823 ret
24824
24825 /*
24826@@ -1435,7 +1958,7 @@ bstep_iret:
24827 movq %rcx,RIP+8(%rsp)
24828 jmp error_swapgs
24829 CFI_ENDPROC
24830-END(error_entry)
24831+ENDPROC(error_entry)
24832
24833
24834 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
24835@@ -1446,7 +1969,7 @@ ENTRY(error_exit)
24836 DISABLE_INTERRUPTS(CLBR_NONE)
24837 TRACE_IRQS_OFF
24838 GET_THREAD_INFO(%rcx)
24839- testl %eax,%eax
24840+ testl $1,%eax
24841 jne retint_kernel
24842 LOCKDEP_SYS_EXIT_IRQ
24843 movl TI_flags(%rcx),%edx
24844@@ -1455,7 +1978,7 @@ ENTRY(error_exit)
24845 jnz retint_careful
24846 jmp retint_swapgs
24847 CFI_ENDPROC
24848-END(error_exit)
24849+ENDPROC(error_exit)
24850
24851 /*
24852 * Test if a given stack is an NMI stack or not.
24853@@ -1513,9 +2036,11 @@ ENTRY(nmi)
24854 * If %cs was not the kernel segment, then the NMI triggered in user
24855 * space, which means it is definitely not nested.
24856 */
24857+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
24858+ je 1f
24859 cmpl $__KERNEL_CS, 16(%rsp)
24860 jne first_nmi
24861-
24862+1:
24863 /*
24864 * Check the special variable on the stack to see if NMIs are
24865 * executing.
24866@@ -1549,8 +2074,7 @@ nested_nmi:
24867
24868 1:
24869 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
24870- leaq -1*8(%rsp), %rdx
24871- movq %rdx, %rsp
24872+ subq $8, %rsp
24873 CFI_ADJUST_CFA_OFFSET 1*8
24874 leaq -10*8(%rsp), %rdx
24875 pushq_cfi $__KERNEL_DS
24876@@ -1568,6 +2092,7 @@ nested_nmi_out:
24877 CFI_RESTORE rdx
24878
24879 /* No need to check faults here */
24880+# pax_force_retaddr_bts
24881 INTERRUPT_RETURN
24882
24883 CFI_RESTORE_STATE
24884@@ -1664,13 +2189,13 @@ end_repeat_nmi:
24885 subq $ORIG_RAX-R15, %rsp
24886 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
24887 /*
24888- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
24889+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
24890 * as we should not be calling schedule in NMI context.
24891 * Even with normal interrupts enabled. An NMI should not be
24892 * setting NEED_RESCHED or anything that normal interrupts and
24893 * exceptions might do.
24894 */
24895- call save_paranoid
24896+ call save_paranoid_nmi
24897 DEFAULT_FRAME 0
24898
24899 /*
24900@@ -1680,9 +2205,9 @@ end_repeat_nmi:
24901 * NMI itself takes a page fault, the page fault that was preempted
24902 * will read the information from the NMI page fault and not the
24903 * origin fault. Save it off and restore it if it changes.
24904- * Use the r12 callee-saved register.
24905+ * Use the r13 callee-saved register.
24906 */
24907- movq %cr2, %r12
24908+ movq %cr2, %r13
24909
24910 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24911 movq %rsp,%rdi
24912@@ -1691,29 +2216,34 @@ end_repeat_nmi:
24913
24914 /* Did the NMI take a page fault? Restore cr2 if it did */
24915 movq %cr2, %rcx
24916- cmpq %rcx, %r12
24917+ cmpq %rcx, %r13
24918 je 1f
24919- movq %r12, %cr2
24920+ movq %r13, %cr2
24921 1:
24922
24923- testl %ebx,%ebx /* swapgs needed? */
24924+ testl $1,%ebx /* swapgs needed? */
24925 jnz nmi_restore
24926 nmi_swapgs:
24927 SWAPGS_UNSAFE_STACK
24928 nmi_restore:
24929+ pax_exit_kernel_nmi
24930 /* Pop the extra iret frame at once */
24931 RESTORE_ALL 6*8
24932+ testb $3, 8(%rsp)
24933+ jnz 1f
24934+ pax_force_retaddr_bts
24935+1:
24936
24937 /* Clear the NMI executing stack variable */
24938 movq $0, 5*8(%rsp)
24939 jmp irq_return
24940 CFI_ENDPROC
24941-END(nmi)
24942+ENDPROC(nmi)
24943
24944 ENTRY(ignore_sysret)
24945 CFI_STARTPROC
24946 mov $-ENOSYS,%eax
24947 sysret
24948 CFI_ENDPROC
24949-END(ignore_sysret)
24950+ENDPROC(ignore_sysret)
24951
24952diff --git a/arch/x86/kernel/espfix_64.c b/arch/x86/kernel/espfix_64.c
24953index 94d857f..bf1f0bf 100644
24954--- a/arch/x86/kernel/espfix_64.c
24955+++ b/arch/x86/kernel/espfix_64.c
24956@@ -197,7 +197,7 @@ void init_espfix_ap(void)
24957 set_pte(&pte_p[n*PTE_STRIDE], pte);
24958
24959 /* Job is done for this CPU and any CPU which shares this page */
24960- ACCESS_ONCE(espfix_pages[page]) = stack_page;
24961+ ACCESS_ONCE_RW(espfix_pages[page]) = stack_page;
24962
24963 unlock_done:
24964 mutex_unlock(&espfix_init_mutex);
24965diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24966index 3386dc9..28bdf81 100644
24967--- a/arch/x86/kernel/ftrace.c
24968+++ b/arch/x86/kernel/ftrace.c
24969@@ -88,7 +88,7 @@ static unsigned long text_ip_addr(unsigned long ip)
24970 * kernel identity mapping to modify code.
24971 */
24972 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24973- ip = (unsigned long)__va(__pa_symbol(ip));
24974+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24975
24976 return ip;
24977 }
24978@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24979 {
24980 unsigned char replaced[MCOUNT_INSN_SIZE];
24981
24982+ ip = ktla_ktva(ip);
24983+
24984 /*
24985 * Note: Due to modules and __init, code can
24986 * disappear and change, we need to protect against faulting
24987@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24988 unsigned char old[MCOUNT_INSN_SIZE];
24989 int ret;
24990
24991- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24992+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24993
24994 ftrace_update_func = ip;
24995 /* Make sure the breakpoints see the ftrace_update_func update */
24996@@ -310,7 +312,7 @@ static int add_break(unsigned long ip, const char *old)
24997 unsigned char replaced[MCOUNT_INSN_SIZE];
24998 unsigned char brk = BREAKPOINT_INSTRUCTION;
24999
25000- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
25001+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
25002 return -EFAULT;
25003
25004 /* Make sure it is what we expect it to be */
25005diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
25006index eda1a86..8f6df48 100644
25007--- a/arch/x86/kernel/head64.c
25008+++ b/arch/x86/kernel/head64.c
25009@@ -67,12 +67,12 @@ again:
25010 pgd = *pgd_p;
25011
25012 /*
25013- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
25014- * critical -- __PAGE_OFFSET would point us back into the dynamic
25015+ * The use of __early_va rather than __va here is critical:
25016+ * __va would point us back into the dynamic
25017 * range and we might end up looping forever...
25018 */
25019 if (pgd)
25020- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
25021+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
25022 else {
25023 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
25024 reset_early_page_tables();
25025@@ -82,13 +82,13 @@ again:
25026 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
25027 for (i = 0; i < PTRS_PER_PUD; i++)
25028 pud_p[i] = 0;
25029- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
25030+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
25031 }
25032 pud_p += pud_index(address);
25033 pud = *pud_p;
25034
25035 if (pud)
25036- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
25037+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
25038 else {
25039 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
25040 reset_early_page_tables();
25041@@ -98,7 +98,7 @@ again:
25042 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
25043 for (i = 0; i < PTRS_PER_PMD; i++)
25044 pmd_p[i] = 0;
25045- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
25046+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
25047 }
25048 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
25049 pmd_p[pmd_index(address)] = pmd;
25050@@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
25051 if (console_loglevel >= CONSOLE_LOGLEVEL_DEBUG)
25052 early_printk("Kernel alive\n");
25053
25054- clear_page(init_level4_pgt);
25055 /* set init_level4_pgt kernel high mapping*/
25056 init_level4_pgt[511] = early_level4_pgt[511];
25057
25058diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
25059index f36bd42..0ab4474 100644
25060--- a/arch/x86/kernel/head_32.S
25061+++ b/arch/x86/kernel/head_32.S
25062@@ -26,6 +26,12 @@
25063 /* Physical address */
25064 #define pa(X) ((X) - __PAGE_OFFSET)
25065
25066+#ifdef CONFIG_PAX_KERNEXEC
25067+#define ta(X) (X)
25068+#else
25069+#define ta(X) ((X) - __PAGE_OFFSET)
25070+#endif
25071+
25072 /*
25073 * References to members of the new_cpu_data structure.
25074 */
25075@@ -55,11 +61,7 @@
25076 * and small than max_low_pfn, otherwise will waste some page table entries
25077 */
25078
25079-#if PTRS_PER_PMD > 1
25080-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
25081-#else
25082-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
25083-#endif
25084+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
25085
25086 /* Number of possible pages in the lowmem region */
25087 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
25088@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
25089 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
25090
25091 /*
25092+ * Real beginning of normal "text" segment
25093+ */
25094+ENTRY(stext)
25095+ENTRY(_stext)
25096+
25097+/*
25098 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
25099 * %esi points to the real-mode code as a 32-bit pointer.
25100 * CS and DS must be 4 GB flat segments, but we don't depend on
25101@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
25102 * can.
25103 */
25104 __HEAD
25105+
25106+#ifdef CONFIG_PAX_KERNEXEC
25107+ jmp startup_32
25108+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
25109+.fill PAGE_SIZE-5,1,0xcc
25110+#endif
25111+
25112 ENTRY(startup_32)
25113 movl pa(stack_start),%ecx
25114
25115@@ -106,6 +121,59 @@ ENTRY(startup_32)
25116 2:
25117 leal -__PAGE_OFFSET(%ecx),%esp
25118
25119+#ifdef CONFIG_SMP
25120+ movl $pa(cpu_gdt_table),%edi
25121+ movl $__per_cpu_load,%eax
25122+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
25123+ rorl $16,%eax
25124+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
25125+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
25126+ movl $__per_cpu_end - 1,%eax
25127+ subl $__per_cpu_start,%eax
25128+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
25129+#endif
25130+
25131+#ifdef CONFIG_PAX_MEMORY_UDEREF
25132+ movl $NR_CPUS,%ecx
25133+ movl $pa(cpu_gdt_table),%edi
25134+1:
25135+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
25136+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
25137+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
25138+ addl $PAGE_SIZE_asm,%edi
25139+ loop 1b
25140+#endif
25141+
25142+#ifdef CONFIG_PAX_KERNEXEC
25143+ movl $pa(boot_gdt),%edi
25144+ movl $__LOAD_PHYSICAL_ADDR,%eax
25145+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
25146+ rorl $16,%eax
25147+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
25148+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
25149+ rorl $16,%eax
25150+
25151+ ljmp $(__BOOT_CS),$1f
25152+1:
25153+
25154+ movl $NR_CPUS,%ecx
25155+ movl $pa(cpu_gdt_table),%edi
25156+ addl $__PAGE_OFFSET,%eax
25157+1:
25158+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
25159+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
25160+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
25161+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
25162+ rorl $16,%eax
25163+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
25164+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
25165+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
25166+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
25167+ rorl $16,%eax
25168+ addl $PAGE_SIZE_asm,%edi
25169+ loop 1b
25170+#endif
25171+
25172 /*
25173 * Clear BSS first so that there are no surprises...
25174 */
25175@@ -201,8 +269,11 @@ ENTRY(startup_32)
25176 movl %eax, pa(max_pfn_mapped)
25177
25178 /* Do early initialization of the fixmap area */
25179- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
25180- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
25181+#ifdef CONFIG_COMPAT_VDSO
25182+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
25183+#else
25184+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
25185+#endif
25186 #else /* Not PAE */
25187
25188 page_pde_offset = (__PAGE_OFFSET >> 20);
25189@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
25190 movl %eax, pa(max_pfn_mapped)
25191
25192 /* Do early initialization of the fixmap area */
25193- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
25194- movl %eax,pa(initial_page_table+0xffc)
25195+#ifdef CONFIG_COMPAT_VDSO
25196+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
25197+#else
25198+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
25199+#endif
25200 #endif
25201
25202 #ifdef CONFIG_PARAVIRT
25203@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
25204 cmpl $num_subarch_entries, %eax
25205 jae bad_subarch
25206
25207- movl pa(subarch_entries)(,%eax,4), %eax
25208- subl $__PAGE_OFFSET, %eax
25209- jmp *%eax
25210+ jmp *pa(subarch_entries)(,%eax,4)
25211
25212 bad_subarch:
25213 WEAK(lguest_entry)
25214@@ -261,10 +333,10 @@ WEAK(xen_entry)
25215 __INITDATA
25216
25217 subarch_entries:
25218- .long default_entry /* normal x86/PC */
25219- .long lguest_entry /* lguest hypervisor */
25220- .long xen_entry /* Xen hypervisor */
25221- .long default_entry /* Moorestown MID */
25222+ .long ta(default_entry) /* normal x86/PC */
25223+ .long ta(lguest_entry) /* lguest hypervisor */
25224+ .long ta(xen_entry) /* Xen hypervisor */
25225+ .long ta(default_entry) /* Moorestown MID */
25226 num_subarch_entries = (. - subarch_entries) / 4
25227 .previous
25228 #else
25229@@ -354,6 +426,7 @@ default_entry:
25230 movl pa(mmu_cr4_features),%eax
25231 movl %eax,%cr4
25232
25233+#ifdef CONFIG_X86_PAE
25234 testb $X86_CR4_PAE, %al # check if PAE is enabled
25235 jz enable_paging
25236
25237@@ -382,6 +455,9 @@ default_entry:
25238 /* Make changes effective */
25239 wrmsr
25240
25241+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
25242+#endif
25243+
25244 enable_paging:
25245
25246 /*
25247@@ -449,14 +525,20 @@ is486:
25248 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
25249 movl %eax,%ss # after changing gdt.
25250
25251- movl $(__USER_DS),%eax # DS/ES contains default USER segment
25252+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
25253 movl %eax,%ds
25254 movl %eax,%es
25255
25256 movl $(__KERNEL_PERCPU), %eax
25257 movl %eax,%fs # set this cpu's percpu
25258
25259+#ifdef CONFIG_CC_STACKPROTECTOR
25260 movl $(__KERNEL_STACK_CANARY),%eax
25261+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
25262+ movl $(__USER_DS),%eax
25263+#else
25264+ xorl %eax,%eax
25265+#endif
25266 movl %eax,%gs
25267
25268 xorl %eax,%eax # Clear LDT
25269@@ -512,8 +594,11 @@ setup_once:
25270 * relocation. Manually set base address in stack canary
25271 * segment descriptor.
25272 */
25273- movl $gdt_page,%eax
25274+ movl $cpu_gdt_table,%eax
25275 movl $stack_canary,%ecx
25276+#ifdef CONFIG_SMP
25277+ addl $__per_cpu_load,%ecx
25278+#endif
25279 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
25280 shrl $16, %ecx
25281 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
25282@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
25283 cmpl $2,(%esp) # X86_TRAP_NMI
25284 je is_nmi # Ignore NMI
25285
25286- cmpl $2,%ss:early_recursion_flag
25287+ cmpl $1,%ss:early_recursion_flag
25288 je hlt_loop
25289 incl %ss:early_recursion_flag
25290
25291@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
25292 pushl (20+6*4)(%esp) /* trapno */
25293 pushl $fault_msg
25294 call printk
25295-#endif
25296 call dump_stack
25297+#endif
25298 hlt_loop:
25299 hlt
25300 jmp hlt_loop
25301@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
25302 /* This is the default interrupt "handler" :-) */
25303 ALIGN
25304 ignore_int:
25305- cld
25306 #ifdef CONFIG_PRINTK
25307+ cmpl $2,%ss:early_recursion_flag
25308+ je hlt_loop
25309+ incl %ss:early_recursion_flag
25310+ cld
25311 pushl %eax
25312 pushl %ecx
25313 pushl %edx
25314@@ -617,9 +705,6 @@ ignore_int:
25315 movl $(__KERNEL_DS),%eax
25316 movl %eax,%ds
25317 movl %eax,%es
25318- cmpl $2,early_recursion_flag
25319- je hlt_loop
25320- incl early_recursion_flag
25321 pushl 16(%esp)
25322 pushl 24(%esp)
25323 pushl 32(%esp)
25324@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
25325 /*
25326 * BSS section
25327 */
25328-__PAGE_ALIGNED_BSS
25329- .align PAGE_SIZE
25330 #ifdef CONFIG_X86_PAE
25331+.section .initial_pg_pmd,"a",@progbits
25332 initial_pg_pmd:
25333 .fill 1024*KPMDS,4,0
25334 #else
25335+.section .initial_page_table,"a",@progbits
25336 ENTRY(initial_page_table)
25337 .fill 1024,4,0
25338 #endif
25339+.section .initial_pg_fixmap,"a",@progbits
25340 initial_pg_fixmap:
25341 .fill 1024,4,0
25342+.section .empty_zero_page,"a",@progbits
25343 ENTRY(empty_zero_page)
25344 .fill 4096,1,0
25345+.section .swapper_pg_dir,"a",@progbits
25346 ENTRY(swapper_pg_dir)
25347+#ifdef CONFIG_X86_PAE
25348+ .fill 4,8,0
25349+#else
25350 .fill 1024,4,0
25351+#endif
25352
25353 /*
25354 * This starts the data section.
25355 */
25356 #ifdef CONFIG_X86_PAE
25357-__PAGE_ALIGNED_DATA
25358- /* Page-aligned for the benefit of paravirt? */
25359- .align PAGE_SIZE
25360+.section .initial_page_table,"a",@progbits
25361 ENTRY(initial_page_table)
25362 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
25363 # if KPMDS == 3
25364@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
25365 # error "Kernel PMDs should be 1, 2 or 3"
25366 # endif
25367 .align PAGE_SIZE /* needs to be page-sized too */
25368+
25369+#ifdef CONFIG_PAX_PER_CPU_PGD
25370+ENTRY(cpu_pgd)
25371+ .rept 2*NR_CPUS
25372+ .fill 4,8,0
25373+ .endr
25374+#endif
25375+
25376 #endif
25377
25378 .data
25379 .balign 4
25380 ENTRY(stack_start)
25381- .long init_thread_union+THREAD_SIZE
25382+ .long init_thread_union+THREAD_SIZE-8
25383
25384 __INITRODATA
25385 int_msg:
25386@@ -727,7 +825,7 @@ fault_msg:
25387 * segment size, and 32-bit linear address value:
25388 */
25389
25390- .data
25391+.section .rodata,"a",@progbits
25392 .globl boot_gdt_descr
25393 .globl idt_descr
25394
25395@@ -736,7 +834,7 @@ fault_msg:
25396 .word 0 # 32 bit align gdt_desc.address
25397 boot_gdt_descr:
25398 .word __BOOT_DS+7
25399- .long boot_gdt - __PAGE_OFFSET
25400+ .long pa(boot_gdt)
25401
25402 .word 0 # 32-bit align idt_desc.address
25403 idt_descr:
25404@@ -747,7 +845,7 @@ idt_descr:
25405 .word 0 # 32 bit align gdt_desc.address
25406 ENTRY(early_gdt_descr)
25407 .word GDT_ENTRIES*8-1
25408- .long gdt_page /* Overwritten for secondary CPUs */
25409+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
25410
25411 /*
25412 * The boot_gdt must mirror the equivalent in setup.S and is
25413@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
25414 .align L1_CACHE_BYTES
25415 ENTRY(boot_gdt)
25416 .fill GDT_ENTRY_BOOT_CS,8,0
25417- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
25418- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
25419+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
25420+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
25421+
25422+ .align PAGE_SIZE_asm
25423+ENTRY(cpu_gdt_table)
25424+ .rept NR_CPUS
25425+ .quad 0x0000000000000000 /* NULL descriptor */
25426+ .quad 0x0000000000000000 /* 0x0b reserved */
25427+ .quad 0x0000000000000000 /* 0x13 reserved */
25428+ .quad 0x0000000000000000 /* 0x1b reserved */
25429+
25430+#ifdef CONFIG_PAX_KERNEXEC
25431+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
25432+#else
25433+ .quad 0x0000000000000000 /* 0x20 unused */
25434+#endif
25435+
25436+ .quad 0x0000000000000000 /* 0x28 unused */
25437+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
25438+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
25439+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
25440+ .quad 0x0000000000000000 /* 0x4b reserved */
25441+ .quad 0x0000000000000000 /* 0x53 reserved */
25442+ .quad 0x0000000000000000 /* 0x5b reserved */
25443+
25444+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
25445+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
25446+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
25447+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
25448+
25449+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
25450+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
25451+
25452+ /*
25453+ * Segments used for calling PnP BIOS have byte granularity.
25454+ * The code segments and data segments have fixed 64k limits,
25455+ * the transfer segment sizes are set at run time.
25456+ */
25457+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
25458+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
25459+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
25460+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
25461+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
25462+
25463+ /*
25464+ * The APM segments have byte granularity and their bases
25465+ * are set at run time. All have 64k limits.
25466+ */
25467+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
25468+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
25469+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
25470+
25471+ .quad 0x00c093000000ffff /* 0xd0 - ESPFIX SS */
25472+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
25473+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
25474+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
25475+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
25476+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
25477+
25478+ /* Be sure this is zeroed to avoid false validations in Xen */
25479+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
25480+ .endr
25481diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
25482index a468c0a..8b5a879 100644
25483--- a/arch/x86/kernel/head_64.S
25484+++ b/arch/x86/kernel/head_64.S
25485@@ -20,6 +20,8 @@
25486 #include <asm/processor-flags.h>
25487 #include <asm/percpu.h>
25488 #include <asm/nops.h>
25489+#include <asm/cpufeature.h>
25490+#include <asm/alternative-asm.h>
25491
25492 #ifdef CONFIG_PARAVIRT
25493 #include <asm/asm-offsets.h>
25494@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
25495 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
25496 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
25497 L3_START_KERNEL = pud_index(__START_KERNEL_map)
25498+L4_VMALLOC_START = pgd_index(VMALLOC_START)
25499+L3_VMALLOC_START = pud_index(VMALLOC_START)
25500+L4_VMALLOC_END = pgd_index(VMALLOC_END)
25501+L3_VMALLOC_END = pud_index(VMALLOC_END)
25502+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
25503+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
25504
25505 .text
25506 __HEAD
25507@@ -89,11 +97,24 @@ startup_64:
25508 * Fixup the physical addresses in the page table
25509 */
25510 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
25511+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
25512+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
25513+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
25514+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
25515+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
25516
25517- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
25518- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
25519+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
25520+#ifndef CONFIG_XEN
25521+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
25522+#endif
25523+
25524+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
25525+
25526+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
25527+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
25528
25529 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
25530+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
25531
25532 /*
25533 * Set up the identity mapping for the switchover. These
25534@@ -174,11 +195,12 @@ ENTRY(secondary_startup_64)
25535 * after the boot processor executes this code.
25536 */
25537
25538+ orq $-1, %rbp
25539 movq $(init_level4_pgt - __START_KERNEL_map), %rax
25540 1:
25541
25542- /* Enable PAE mode and PGE */
25543- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
25544+ /* Enable PAE mode and PSE/PGE */
25545+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
25546 movq %rcx, %cr4
25547
25548 /* Setup early boot stage 4 level pagetables. */
25549@@ -199,10 +221,19 @@ ENTRY(secondary_startup_64)
25550 movl $MSR_EFER, %ecx
25551 rdmsr
25552 btsl $_EFER_SCE, %eax /* Enable System Call */
25553- btl $20,%edi /* No Execute supported? */
25554+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
25555 jnc 1f
25556 btsl $_EFER_NX, %eax
25557+ cmpq $-1, %rbp
25558+ je 1f
25559 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
25560+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
25561+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
25562+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
25563+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
25564+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
25565+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
25566+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
25567 1: wrmsr /* Make changes effective */
25568
25569 /* Setup cr0 */
25570@@ -282,6 +313,7 @@ ENTRY(secondary_startup_64)
25571 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
25572 * address given in m16:64.
25573 */
25574+ pax_set_fptr_mask
25575 movq initial_code(%rip),%rax
25576 pushq $0 # fake return address to stop unwinder
25577 pushq $__KERNEL_CS # set correct cs
25578@@ -313,7 +345,7 @@ ENDPROC(start_cpu0)
25579 .quad INIT_PER_CPU_VAR(irq_stack_union)
25580
25581 GLOBAL(stack_start)
25582- .quad init_thread_union+THREAD_SIZE-8
25583+ .quad init_thread_union+THREAD_SIZE-16
25584 .word 0
25585 __FINITDATA
25586
25587@@ -391,7 +423,7 @@ ENTRY(early_idt_handler)
25588 call dump_stack
25589 #ifdef CONFIG_KALLSYMS
25590 leaq early_idt_ripmsg(%rip),%rdi
25591- movq 40(%rsp),%rsi # %rip again
25592+ movq 88(%rsp),%rsi # %rip again
25593 call __print_symbol
25594 #endif
25595 #endif /* EARLY_PRINTK */
25596@@ -420,6 +452,7 @@ ENDPROC(early_idt_handler)
25597 early_recursion_flag:
25598 .long 0
25599
25600+ .section .rodata,"a",@progbits
25601 #ifdef CONFIG_EARLY_PRINTK
25602 early_idt_msg:
25603 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
25604@@ -447,29 +480,52 @@ NEXT_PAGE(early_level4_pgt)
25605 NEXT_PAGE(early_dynamic_pgts)
25606 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
25607
25608- .data
25609+ .section .rodata,"a",@progbits
25610
25611-#ifndef CONFIG_XEN
25612 NEXT_PAGE(init_level4_pgt)
25613- .fill 512,8,0
25614-#else
25615-NEXT_PAGE(init_level4_pgt)
25616- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25617 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
25618 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25619+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
25620+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
25621+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
25622+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
25623+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
25624+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25625 .org init_level4_pgt + L4_START_KERNEL*8, 0
25626 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
25627 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
25628
25629+#ifdef CONFIG_PAX_PER_CPU_PGD
25630+NEXT_PAGE(cpu_pgd)
25631+ .rept 2*NR_CPUS
25632+ .fill 512,8,0
25633+ .endr
25634+#endif
25635+
25636 NEXT_PAGE(level3_ident_pgt)
25637 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
25638+#ifdef CONFIG_XEN
25639 .fill 511, 8, 0
25640+#else
25641+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
25642+ .fill 510,8,0
25643+#endif
25644+
25645+NEXT_PAGE(level3_vmalloc_start_pgt)
25646+ .fill 512,8,0
25647+
25648+NEXT_PAGE(level3_vmalloc_end_pgt)
25649+ .fill 512,8,0
25650+
25651+NEXT_PAGE(level3_vmemmap_pgt)
25652+ .fill L3_VMEMMAP_START,8,0
25653+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
25654+
25655 NEXT_PAGE(level2_ident_pgt)
25656- /* Since I easily can, map the first 1G.
25657+ /* Since I easily can, map the first 2G.
25658 * Don't set NX because code runs from these pages.
25659 */
25660- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
25661-#endif
25662+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
25663
25664 NEXT_PAGE(level3_kernel_pgt)
25665 .fill L3_START_KERNEL,8,0
25666@@ -477,6 +533,9 @@ NEXT_PAGE(level3_kernel_pgt)
25667 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
25668 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25669
25670+NEXT_PAGE(level2_vmemmap_pgt)
25671+ .fill 512,8,0
25672+
25673 NEXT_PAGE(level2_kernel_pgt)
25674 /*
25675 * 512 MB kernel mapping. We spend a full page on this pagetable
25676@@ -494,28 +553,64 @@ NEXT_PAGE(level2_kernel_pgt)
25677 NEXT_PAGE(level2_fixmap_pgt)
25678 .fill 506,8,0
25679 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
25680- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
25681- .fill 5,8,0
25682+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
25683+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
25684+ .fill 4,8,0
25685
25686 NEXT_PAGE(level1_fixmap_pgt)
25687 .fill 512,8,0
25688
25689+NEXT_PAGE(level1_vsyscall_pgt)
25690+ .fill 512,8,0
25691+
25692 #undef PMDS
25693
25694- .data
25695+ .align PAGE_SIZE
25696+ENTRY(cpu_gdt_table)
25697+ .rept NR_CPUS
25698+ .quad 0x0000000000000000 /* NULL descriptor */
25699+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
25700+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
25701+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
25702+ .quad 0x00cffb000000ffff /* __USER32_CS */
25703+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
25704+ .quad 0x00affb000000ffff /* __USER_CS */
25705+
25706+#ifdef CONFIG_PAX_KERNEXEC
25707+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
25708+#else
25709+ .quad 0x0 /* unused */
25710+#endif
25711+
25712+ .quad 0,0 /* TSS */
25713+ .quad 0,0 /* LDT */
25714+ .quad 0,0,0 /* three TLS descriptors */
25715+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
25716+ /* asm/segment.h:GDT_ENTRIES must match this */
25717+
25718+#ifdef CONFIG_PAX_MEMORY_UDEREF
25719+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
25720+#else
25721+ .quad 0x0 /* unused */
25722+#endif
25723+
25724+ /* zero the remaining page */
25725+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
25726+ .endr
25727+
25728 .align 16
25729 .globl early_gdt_descr
25730 early_gdt_descr:
25731 .word GDT_ENTRIES*8-1
25732 early_gdt_descr_base:
25733- .quad INIT_PER_CPU_VAR(gdt_page)
25734+ .quad cpu_gdt_table
25735
25736 ENTRY(phys_base)
25737 /* This must match the first entry in level2_kernel_pgt */
25738 .quad 0x0000000000000000
25739
25740 #include "../../x86/xen/xen-head.S"
25741-
25742- __PAGE_ALIGNED_BSS
25743+
25744+ .section .rodata,"a",@progbits
25745 NEXT_PAGE(empty_zero_page)
25746 .skip PAGE_SIZE
25747diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
25748index 05fd74f..c3548b1 100644
25749--- a/arch/x86/kernel/i386_ksyms_32.c
25750+++ b/arch/x86/kernel/i386_ksyms_32.c
25751@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
25752 EXPORT_SYMBOL(cmpxchg8b_emu);
25753 #endif
25754
25755+EXPORT_SYMBOL_GPL(cpu_gdt_table);
25756+
25757 /* Networking helper routines. */
25758 EXPORT_SYMBOL(csum_partial_copy_generic);
25759+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
25760+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
25761
25762 EXPORT_SYMBOL(__get_user_1);
25763 EXPORT_SYMBOL(__get_user_2);
25764@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
25765 EXPORT_SYMBOL(___preempt_schedule_context);
25766 #endif
25767 #endif
25768+
25769+#ifdef CONFIG_PAX_KERNEXEC
25770+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
25771+#endif
25772+
25773+#ifdef CONFIG_PAX_PER_CPU_PGD
25774+EXPORT_SYMBOL(cpu_pgd);
25775+#endif
25776diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
25777index a9a4229..6f4d476 100644
25778--- a/arch/x86/kernel/i387.c
25779+++ b/arch/x86/kernel/i387.c
25780@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
25781 static inline bool interrupted_user_mode(void)
25782 {
25783 struct pt_regs *regs = get_irq_regs();
25784- return regs && user_mode_vm(regs);
25785+ return regs && user_mode(regs);
25786 }
25787
25788 /*
25789diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
25790index 8af8171..f8c1169 100644
25791--- a/arch/x86/kernel/i8259.c
25792+++ b/arch/x86/kernel/i8259.c
25793@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
25794 static void make_8259A_irq(unsigned int irq)
25795 {
25796 disable_irq_nosync(irq);
25797- io_apic_irqs &= ~(1<<irq);
25798+ io_apic_irqs &= ~(1UL<<irq);
25799 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
25800 i8259A_chip.name);
25801 enable_irq(irq);
25802@@ -209,7 +209,7 @@ spurious_8259A_irq:
25803 "spurious 8259A interrupt: IRQ%d.\n", irq);
25804 spurious_irq_mask |= irqmask;
25805 }
25806- atomic_inc(&irq_err_count);
25807+ atomic_inc_unchecked(&irq_err_count);
25808 /*
25809 * Theoretically we do not have to handle this IRQ,
25810 * but in Linux this does not cause problems and is
25811@@ -350,14 +350,16 @@ static void init_8259A(int auto_eoi)
25812 /* (slave's support for AEOI in flat mode is to be investigated) */
25813 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
25814
25815+ pax_open_kernel();
25816 if (auto_eoi)
25817 /*
25818 * In AEOI mode we just have to mask the interrupt
25819 * when acking.
25820 */
25821- i8259A_chip.irq_mask_ack = disable_8259A_irq;
25822+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
25823 else
25824- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25825+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
25826+ pax_close_kernel();
25827
25828 udelay(100); /* wait for 8259A to initialize */
25829
25830diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
25831index a979b5b..1d6db75 100644
25832--- a/arch/x86/kernel/io_delay.c
25833+++ b/arch/x86/kernel/io_delay.c
25834@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
25835 * Quirk table for systems that misbehave (lock up, etc.) if port
25836 * 0x80 is used:
25837 */
25838-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
25839+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
25840 {
25841 .callback = dmi_io_delay_0xed_port,
25842 .ident = "Compaq Presario V6000",
25843diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
25844index 4ddaf66..49d5c18 100644
25845--- a/arch/x86/kernel/ioport.c
25846+++ b/arch/x86/kernel/ioport.c
25847@@ -6,6 +6,7 @@
25848 #include <linux/sched.h>
25849 #include <linux/kernel.h>
25850 #include <linux/capability.h>
25851+#include <linux/security.h>
25852 #include <linux/errno.h>
25853 #include <linux/types.h>
25854 #include <linux/ioport.h>
25855@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25856 return -EINVAL;
25857 if (turn_on && !capable(CAP_SYS_RAWIO))
25858 return -EPERM;
25859+#ifdef CONFIG_GRKERNSEC_IO
25860+ if (turn_on && grsec_disable_privio) {
25861+ gr_handle_ioperm();
25862+ return -ENODEV;
25863+ }
25864+#endif
25865
25866 /*
25867 * If it's the first ioperm() call in this thread's lifetime, set the
25868@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
25869 * because the ->io_bitmap_max value must match the bitmap
25870 * contents:
25871 */
25872- tss = &per_cpu(init_tss, get_cpu());
25873+ tss = init_tss + get_cpu();
25874
25875 if (turn_on)
25876 bitmap_clear(t->io_bitmap_ptr, from, num);
25877@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
25878 if (level > old) {
25879 if (!capable(CAP_SYS_RAWIO))
25880 return -EPERM;
25881+#ifdef CONFIG_GRKERNSEC_IO
25882+ if (grsec_disable_privio) {
25883+ gr_handle_iopl();
25884+ return -ENODEV;
25885+ }
25886+#endif
25887 }
25888 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
25889 t->iopl = level << 12;
25890diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
25891index 922d285..6d20692 100644
25892--- a/arch/x86/kernel/irq.c
25893+++ b/arch/x86/kernel/irq.c
25894@@ -22,7 +22,7 @@
25895 #define CREATE_TRACE_POINTS
25896 #include <asm/trace/irq_vectors.h>
25897
25898-atomic_t irq_err_count;
25899+atomic_unchecked_t irq_err_count;
25900
25901 /* Function pointer for generic interrupt vector handling */
25902 void (*x86_platform_ipi_callback)(void) = NULL;
25903@@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
25904 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
25905 seq_printf(p, " Hypervisor callback interrupts\n");
25906 #endif
25907- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
25908+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
25909 #if defined(CONFIG_X86_IO_APIC)
25910- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
25911+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
25912 #endif
25913 return 0;
25914 }
25915@@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
25916
25917 u64 arch_irq_stat(void)
25918 {
25919- u64 sum = atomic_read(&irq_err_count);
25920+ u64 sum = atomic_read_unchecked(&irq_err_count);
25921 return sum;
25922 }
25923
25924diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25925index 63ce838..2ea3e06 100644
25926--- a/arch/x86/kernel/irq_32.c
25927+++ b/arch/x86/kernel/irq_32.c
25928@@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25929
25930 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25931
25932+extern void gr_handle_kernel_exploit(void);
25933+
25934 int sysctl_panic_on_stackoverflow __read_mostly;
25935
25936 /* Debugging check for stack overflow: is there less than 1KB free? */
25937@@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25938 __asm__ __volatile__("andl %%esp,%0" :
25939 "=r" (sp) : "0" (THREAD_SIZE - 1));
25940
25941- return sp < (sizeof(struct thread_info) + STACK_WARN);
25942+ return sp < STACK_WARN;
25943 }
25944
25945 static void print_stack_overflow(void)
25946 {
25947 printk(KERN_WARNING "low stack detected by irq handler\n");
25948 dump_stack();
25949+ gr_handle_kernel_exploit();
25950 if (sysctl_panic_on_stackoverflow)
25951 panic("low stack detected by irq handler - check messages\n");
25952 }
25953@@ -84,10 +87,9 @@ static inline void *current_stack(void)
25954 static inline int
25955 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25956 {
25957- struct irq_stack *curstk, *irqstk;
25958+ struct irq_stack *irqstk;
25959 u32 *isp, *prev_esp, arg1, arg2;
25960
25961- curstk = (struct irq_stack *) current_stack();
25962 irqstk = __this_cpu_read(hardirq_stack);
25963
25964 /*
25965@@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25966 * handler) we can't do that and just have to keep using the
25967 * current stack (which is the irq stack already after all)
25968 */
25969- if (unlikely(curstk == irqstk))
25970+ if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25971 return 0;
25972
25973- isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25974+ isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25975
25976 /* Save the next esp at the bottom of the stack */
25977 prev_esp = (u32 *)irqstk;
25978 *prev_esp = current_stack_pointer;
25979
25980+#ifdef CONFIG_PAX_MEMORY_UDEREF
25981+ __set_fs(MAKE_MM_SEG(0));
25982+#endif
25983+
25984 if (unlikely(overflow))
25985 call_on_stack(print_stack_overflow, isp);
25986
25987@@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25988 : "0" (irq), "1" (desc), "2" (isp),
25989 "D" (desc->handle_irq)
25990 : "memory", "cc", "ecx");
25991+
25992+#ifdef CONFIG_PAX_MEMORY_UDEREF
25993+ __set_fs(current_thread_info()->addr_limit);
25994+#endif
25995+
25996 return 1;
25997 }
25998
25999@@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
26000 */
26001 void irq_ctx_init(int cpu)
26002 {
26003- struct irq_stack *irqstk;
26004-
26005 if (per_cpu(hardirq_stack, cpu))
26006 return;
26007
26008- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
26009- THREADINFO_GFP,
26010- THREAD_SIZE_ORDER));
26011- per_cpu(hardirq_stack, cpu) = irqstk;
26012-
26013- irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
26014- THREADINFO_GFP,
26015- THREAD_SIZE_ORDER));
26016- per_cpu(softirq_stack, cpu) = irqstk;
26017-
26018- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
26019- cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
26020+ per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
26021+ per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
26022 }
26023
26024 void do_softirq_own_stack(void)
26025 {
26026- struct thread_info *curstk;
26027 struct irq_stack *irqstk;
26028 u32 *isp, *prev_esp;
26029
26030- curstk = current_stack();
26031 irqstk = __this_cpu_read(softirq_stack);
26032
26033 /* build the stack frame on the softirq stack */
26034@@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
26035 prev_esp = (u32 *)irqstk;
26036 *prev_esp = current_stack_pointer;
26037
26038+#ifdef CONFIG_PAX_MEMORY_UDEREF
26039+ __set_fs(MAKE_MM_SEG(0));
26040+#endif
26041+
26042 call_on_stack(__do_softirq, isp);
26043+
26044+#ifdef CONFIG_PAX_MEMORY_UDEREF
26045+ __set_fs(current_thread_info()->addr_limit);
26046+#endif
26047+
26048 }
26049
26050 bool handle_irq(unsigned irq, struct pt_regs *regs)
26051@@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
26052 if (unlikely(!desc))
26053 return false;
26054
26055- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
26056+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
26057 if (unlikely(overflow))
26058 print_stack_overflow();
26059 desc->handle_irq(irq, desc);
26060diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
26061index 4d1c746..55a22d6 100644
26062--- a/arch/x86/kernel/irq_64.c
26063+++ b/arch/x86/kernel/irq_64.c
26064@@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
26065 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
26066 EXPORT_PER_CPU_SYMBOL(irq_regs);
26067
26068+extern void gr_handle_kernel_exploit(void);
26069+
26070 int sysctl_panic_on_stackoverflow;
26071
26072 /*
26073@@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
26074 u64 estack_top, estack_bottom;
26075 u64 curbase = (u64)task_stack_page(current);
26076
26077- if (user_mode_vm(regs))
26078+ if (user_mode(regs))
26079 return;
26080
26081 if (regs->sp >= curbase + sizeof(struct thread_info) +
26082@@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
26083 irq_stack_top, irq_stack_bottom,
26084 estack_top, estack_bottom);
26085
26086+ gr_handle_kernel_exploit();
26087+
26088 if (sysctl_panic_on_stackoverflow)
26089 panic("low stack detected by irq handler - check messages\n");
26090 #endif
26091diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
26092index 26d5a55..a01160a 100644
26093--- a/arch/x86/kernel/jump_label.c
26094+++ b/arch/x86/kernel/jump_label.c
26095@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
26096 * Jump label is enabled for the first time.
26097 * So we expect a default_nop...
26098 */
26099- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
26100+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
26101 != 0))
26102 bug_at((void *)entry->code, __LINE__);
26103 } else {
26104@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
26105 * ...otherwise expect an ideal_nop. Otherwise
26106 * something went horribly wrong.
26107 */
26108- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
26109+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
26110 != 0))
26111 bug_at((void *)entry->code, __LINE__);
26112 }
26113@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
26114 * are converting the default nop to the ideal nop.
26115 */
26116 if (init) {
26117- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
26118+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
26119 bug_at((void *)entry->code, __LINE__);
26120 } else {
26121 code.jump = 0xe9;
26122 code.offset = entry->target -
26123 (entry->code + JUMP_LABEL_NOP_SIZE);
26124- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
26125+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
26126 bug_at((void *)entry->code, __LINE__);
26127 }
26128 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
26129diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
26130index 7ec1d5f..5a7d130 100644
26131--- a/arch/x86/kernel/kgdb.c
26132+++ b/arch/x86/kernel/kgdb.c
26133@@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
26134 #ifdef CONFIG_X86_32
26135 switch (regno) {
26136 case GDB_SS:
26137- if (!user_mode_vm(regs))
26138+ if (!user_mode(regs))
26139 *(unsigned long *)mem = __KERNEL_DS;
26140 break;
26141 case GDB_SP:
26142- if (!user_mode_vm(regs))
26143+ if (!user_mode(regs))
26144 *(unsigned long *)mem = kernel_stack_pointer(regs);
26145 break;
26146 case GDB_GS:
26147@@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
26148 bp->attr.bp_addr = breakinfo[breakno].addr;
26149 bp->attr.bp_len = breakinfo[breakno].len;
26150 bp->attr.bp_type = breakinfo[breakno].type;
26151- info->address = breakinfo[breakno].addr;
26152+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
26153+ info->address = ktla_ktva(breakinfo[breakno].addr);
26154+ else
26155+ info->address = breakinfo[breakno].addr;
26156 info->len = breakinfo[breakno].len;
26157 info->type = breakinfo[breakno].type;
26158 val = arch_install_hw_breakpoint(bp);
26159@@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
26160 case 'k':
26161 /* clear the trace bit */
26162 linux_regs->flags &= ~X86_EFLAGS_TF;
26163- atomic_set(&kgdb_cpu_doing_single_step, -1);
26164+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
26165
26166 /* set the trace bit if we're stepping */
26167 if (remcomInBuffer[0] == 's') {
26168 linux_regs->flags |= X86_EFLAGS_TF;
26169- atomic_set(&kgdb_cpu_doing_single_step,
26170+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
26171 raw_smp_processor_id());
26172 }
26173
26174@@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
26175
26176 switch (cmd) {
26177 case DIE_DEBUG:
26178- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
26179+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
26180 if (user_mode(regs))
26181 return single_step_cont(regs, args);
26182 break;
26183@@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
26184 #endif /* CONFIG_DEBUG_RODATA */
26185
26186 bpt->type = BP_BREAKPOINT;
26187- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
26188+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
26189 BREAK_INSTR_SIZE);
26190 if (err)
26191 return err;
26192- err = probe_kernel_write((char *)bpt->bpt_addr,
26193+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
26194 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
26195 #ifdef CONFIG_DEBUG_RODATA
26196 if (!err)
26197@@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
26198 return -EBUSY;
26199 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
26200 BREAK_INSTR_SIZE);
26201- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
26202+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
26203 if (err)
26204 return err;
26205 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
26206@@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
26207 if (mutex_is_locked(&text_mutex))
26208 goto knl_write;
26209 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
26210- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
26211+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
26212 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
26213 goto knl_write;
26214 return err;
26215 knl_write:
26216 #endif /* CONFIG_DEBUG_RODATA */
26217- return probe_kernel_write((char *)bpt->bpt_addr,
26218+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
26219 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
26220 }
26221
26222diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
26223index 67e6d19..731ed28 100644
26224--- a/arch/x86/kernel/kprobes/core.c
26225+++ b/arch/x86/kernel/kprobes/core.c
26226@@ -120,9 +120,12 @@ __synthesize_relative_insn(void *from, void *to, u8 op)
26227 s32 raddr;
26228 } __packed *insn;
26229
26230- insn = (struct __arch_relative_insn *)from;
26231+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
26232+
26233+ pax_open_kernel();
26234 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
26235 insn->op = op;
26236+ pax_close_kernel();
26237 }
26238
26239 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
26240@@ -168,7 +171,7 @@ int can_boost(kprobe_opcode_t *opcodes)
26241 kprobe_opcode_t opcode;
26242 kprobe_opcode_t *orig_opcodes = opcodes;
26243
26244- if (search_exception_tables((unsigned long)opcodes))
26245+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
26246 return 0; /* Page fault may occur on this address. */
26247
26248 retry:
26249@@ -242,9 +245,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
26250 * for the first byte, we can recover the original instruction
26251 * from it and kp->opcode.
26252 */
26253- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
26254+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
26255 buf[0] = kp->opcode;
26256- return (unsigned long)buf;
26257+ return ktva_ktla((unsigned long)buf);
26258 }
26259
26260 /*
26261@@ -336,7 +339,9 @@ int __copy_instruction(u8 *dest, u8 *src)
26262 /* Another subsystem puts a breakpoint, failed to recover */
26263 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
26264 return 0;
26265+ pax_open_kernel();
26266 memcpy(dest, insn.kaddr, insn.length);
26267+ pax_close_kernel();
26268
26269 #ifdef CONFIG_X86_64
26270 if (insn_rip_relative(&insn)) {
26271@@ -363,7 +368,9 @@ int __copy_instruction(u8 *dest, u8 *src)
26272 return 0;
26273 }
26274 disp = (u8 *) dest + insn_offset_displacement(&insn);
26275+ pax_open_kernel();
26276 *(s32 *) disp = (s32) newdisp;
26277+ pax_close_kernel();
26278 }
26279 #endif
26280 return insn.length;
26281@@ -505,7 +512,7 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
26282 * nor set current_kprobe, because it doesn't use single
26283 * stepping.
26284 */
26285- regs->ip = (unsigned long)p->ainsn.insn;
26286+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
26287 preempt_enable_no_resched();
26288 return;
26289 }
26290@@ -522,9 +529,9 @@ static void setup_singlestep(struct kprobe *p, struct pt_regs *regs,
26291 regs->flags &= ~X86_EFLAGS_IF;
26292 /* single step inline if the instruction is an int3 */
26293 if (p->opcode == BREAKPOINT_INSTRUCTION)
26294- regs->ip = (unsigned long)p->addr;
26295+ regs->ip = ktla_ktva((unsigned long)p->addr);
26296 else
26297- regs->ip = (unsigned long)p->ainsn.insn;
26298+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
26299 }
26300 NOKPROBE_SYMBOL(setup_singlestep);
26301
26302@@ -574,7 +581,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
26303 struct kprobe *p;
26304 struct kprobe_ctlblk *kcb;
26305
26306- if (user_mode_vm(regs))
26307+ if (user_mode(regs))
26308 return 0;
26309
26310 addr = (kprobe_opcode_t *)(regs->ip - sizeof(kprobe_opcode_t));
26311@@ -609,7 +616,7 @@ int kprobe_int3_handler(struct pt_regs *regs)
26312 setup_singlestep(p, regs, kcb, 0);
26313 return 1;
26314 }
26315- } else if (*addr != BREAKPOINT_INSTRUCTION) {
26316+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
26317 /*
26318 * The breakpoint instruction was removed right
26319 * after we hit it. Another cpu has removed
26320@@ -656,6 +663,9 @@ static void __used kretprobe_trampoline_holder(void)
26321 " movq %rax, 152(%rsp)\n"
26322 RESTORE_REGS_STRING
26323 " popfq\n"
26324+#ifdef KERNEXEC_PLUGIN
26325+ " btsq $63,(%rsp)\n"
26326+#endif
26327 #else
26328 " pushf\n"
26329 SAVE_REGS_STRING
26330@@ -796,7 +806,7 @@ static void resume_execution(struct kprobe *p, struct pt_regs *regs,
26331 struct kprobe_ctlblk *kcb)
26332 {
26333 unsigned long *tos = stack_addr(regs);
26334- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
26335+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
26336 unsigned long orig_ip = (unsigned long)p->addr;
26337 kprobe_opcode_t *insn = p->ainsn.insn;
26338
26339@@ -979,7 +989,7 @@ int kprobe_exceptions_notify(struct notifier_block *self, unsigned long val,
26340 struct die_args *args = data;
26341 int ret = NOTIFY_DONE;
26342
26343- if (args->regs && user_mode_vm(args->regs))
26344+ if (args->regs && user_mode(args->regs))
26345 return ret;
26346
26347 if (val == DIE_GPF) {
26348diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
26349index f1314d0..15f3154 100644
26350--- a/arch/x86/kernel/kprobes/opt.c
26351+++ b/arch/x86/kernel/kprobes/opt.c
26352@@ -79,6 +79,7 @@ found:
26353 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
26354 static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
26355 {
26356+ pax_open_kernel();
26357 #ifdef CONFIG_X86_64
26358 *addr++ = 0x48;
26359 *addr++ = 0xbf;
26360@@ -86,6 +87,7 @@ static void synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
26361 *addr++ = 0xb8;
26362 #endif
26363 *(unsigned long *)addr = val;
26364+ pax_close_kernel();
26365 }
26366
26367 asm (
26368@@ -337,7 +339,7 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
26369 * Verify if the address gap is in 2GB range, because this uses
26370 * a relative jump.
26371 */
26372- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
26373+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
26374 if (abs(rel) > 0x7fffffff) {
26375 __arch_remove_optimized_kprobe(op, 0);
26376 return -ERANGE;
26377@@ -354,16 +356,18 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
26378 op->optinsn.size = ret;
26379
26380 /* Copy arch-dep-instance from template */
26381- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
26382+ pax_open_kernel();
26383+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
26384+ pax_close_kernel();
26385
26386 /* Set probe information */
26387 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
26388
26389 /* Set probe function call */
26390- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
26391+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
26392
26393 /* Set returning jmp instruction at the tail of out-of-line buffer */
26394- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
26395+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
26396 (u8 *)op->kp.addr + op->optinsn.size);
26397
26398 flush_icache_range((unsigned long) buf,
26399@@ -388,7 +392,7 @@ void arch_optimize_kprobes(struct list_head *oplist)
26400 WARN_ON(kprobe_disabled(&op->kp));
26401
26402 /* Backup instructions which will be replaced by jump address */
26403- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
26404+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
26405 RELATIVE_ADDR_SIZE);
26406
26407 insn_buf[0] = RELATIVEJUMP_OPCODE;
26408@@ -436,7 +440,7 @@ int setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
26409 /* This kprobe is really able to run optimized path. */
26410 op = container_of(p, struct optimized_kprobe, kp);
26411 /* Detour through copied instructions */
26412- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
26413+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
26414 if (!reenter)
26415 reset_current_kprobe();
26416 preempt_enable_no_resched();
26417diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
26418index c2bedae..25e7ab60 100644
26419--- a/arch/x86/kernel/ksysfs.c
26420+++ b/arch/x86/kernel/ksysfs.c
26421@@ -184,7 +184,7 @@ out:
26422
26423 static struct kobj_attribute type_attr = __ATTR_RO(type);
26424
26425-static struct bin_attribute data_attr = {
26426+static bin_attribute_no_const data_attr __read_only = {
26427 .attr = {
26428 .name = "data",
26429 .mode = S_IRUGO,
26430diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
26431index c37886d..d851d32 100644
26432--- a/arch/x86/kernel/ldt.c
26433+++ b/arch/x86/kernel/ldt.c
26434@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
26435 if (reload) {
26436 #ifdef CONFIG_SMP
26437 preempt_disable();
26438- load_LDT(pc);
26439+ load_LDT_nolock(pc);
26440 if (!cpumask_equal(mm_cpumask(current->mm),
26441 cpumask_of(smp_processor_id())))
26442 smp_call_function(flush_ldt, current->mm, 1);
26443 preempt_enable();
26444 #else
26445- load_LDT(pc);
26446+ load_LDT_nolock(pc);
26447 #endif
26448 }
26449 if (oldsize) {
26450@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
26451 return err;
26452
26453 for (i = 0; i < old->size; i++)
26454- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
26455+ write_ldt_entry(new->ldt, i, old->ldt + i);
26456 return 0;
26457 }
26458
26459@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
26460 retval = copy_ldt(&mm->context, &old_mm->context);
26461 mutex_unlock(&old_mm->context.lock);
26462 }
26463+
26464+ if (tsk == current) {
26465+ mm->context.vdso = 0;
26466+
26467+#ifdef CONFIG_X86_32
26468+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
26469+ mm->context.user_cs_base = 0UL;
26470+ mm->context.user_cs_limit = ~0UL;
26471+
26472+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
26473+ cpus_clear(mm->context.cpu_user_cs_mask);
26474+#endif
26475+
26476+#endif
26477+#endif
26478+
26479+ }
26480+
26481 return retval;
26482 }
26483
26484@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
26485 }
26486 }
26487
26488+#ifdef CONFIG_PAX_SEGMEXEC
26489+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
26490+ error = -EINVAL;
26491+ goto out_unlock;
26492+ }
26493+#endif
26494+
26495 if (!IS_ENABLED(CONFIG_X86_16BIT) && !ldt_info.seg_32bit) {
26496 error = -EINVAL;
26497 goto out_unlock;
26498diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
26499index 1667b1d..16492c5 100644
26500--- a/arch/x86/kernel/machine_kexec_32.c
26501+++ b/arch/x86/kernel/machine_kexec_32.c
26502@@ -25,7 +25,7 @@
26503 #include <asm/cacheflush.h>
26504 #include <asm/debugreg.h>
26505
26506-static void set_idt(void *newidt, __u16 limit)
26507+static void set_idt(struct desc_struct *newidt, __u16 limit)
26508 {
26509 struct desc_ptr curidt;
26510
26511@@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
26512 }
26513
26514
26515-static void set_gdt(void *newgdt, __u16 limit)
26516+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
26517 {
26518 struct desc_ptr curgdt;
26519
26520@@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
26521 }
26522
26523 control_page = page_address(image->control_code_page);
26524- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
26525+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
26526
26527 relocate_kernel_ptr = control_page;
26528 page_list[PA_CONTROL_PAGE] = __pa(control_page);
26529diff --git a/arch/x86/kernel/mcount_64.S b/arch/x86/kernel/mcount_64.S
26530index c73aecf..4c63630 100644
26531--- a/arch/x86/kernel/mcount_64.S
26532+++ b/arch/x86/kernel/mcount_64.S
26533@@ -7,7 +7,7 @@
26534 #include <linux/linkage.h>
26535 #include <asm/ptrace.h>
26536 #include <asm/ftrace.h>
26537-
26538+#include <asm/alternative-asm.h>
26539
26540 .code64
26541 .section .entry.text, "ax"
26542@@ -24,8 +24,9 @@
26543 #ifdef CONFIG_DYNAMIC_FTRACE
26544
26545 ENTRY(function_hook)
26546+ pax_force_retaddr
26547 retq
26548-END(function_hook)
26549+ENDPROC(function_hook)
26550
26551 /* skip is set if stack has been adjusted */
26552 .macro ftrace_caller_setup skip=0
26553@@ -62,8 +63,9 @@ GLOBAL(ftrace_graph_call)
26554 #endif
26555
26556 GLOBAL(ftrace_stub)
26557+ pax_force_retaddr
26558 retq
26559-END(ftrace_caller)
26560+ENDPROC(ftrace_caller)
26561
26562 ENTRY(ftrace_regs_caller)
26563 /* Save the current flags before compare (in SS location)*/
26564@@ -127,7 +129,7 @@ GLOBAL(ftrace_regs_call)
26565 popfq
26566 jmp ftrace_stub
26567
26568-END(ftrace_regs_caller)
26569+ENDPROC(ftrace_regs_caller)
26570
26571
26572 #else /* ! CONFIG_DYNAMIC_FTRACE */
26573@@ -145,6 +147,7 @@ ENTRY(function_hook)
26574 #endif
26575
26576 GLOBAL(ftrace_stub)
26577+ pax_force_retaddr
26578 retq
26579
26580 trace:
26581@@ -158,12 +161,13 @@ trace:
26582 #endif
26583 subq $MCOUNT_INSN_SIZE, %rdi
26584
26585+ pax_force_fptr ftrace_trace_function
26586 call *ftrace_trace_function
26587
26588 MCOUNT_RESTORE_FRAME
26589
26590 jmp ftrace_stub
26591-END(function_hook)
26592+ENDPROC(function_hook)
26593 #endif /* CONFIG_DYNAMIC_FTRACE */
26594 #endif /* CONFIG_FUNCTION_TRACER */
26595
26596@@ -185,8 +189,9 @@ ENTRY(ftrace_graph_caller)
26597
26598 MCOUNT_RESTORE_FRAME
26599
26600+ pax_force_retaddr
26601 retq
26602-END(ftrace_graph_caller)
26603+ENDPROC(ftrace_graph_caller)
26604
26605 GLOBAL(return_to_handler)
26606 subq $24, %rsp
26607@@ -202,5 +207,7 @@ GLOBAL(return_to_handler)
26608 movq 8(%rsp), %rdx
26609 movq (%rsp), %rax
26610 addq $24, %rsp
26611+ pax_force_fptr %rdi
26612 jmp *%rdi
26613+ENDPROC(return_to_handler)
26614 #endif
26615diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
26616index e69f988..da078ea 100644
26617--- a/arch/x86/kernel/module.c
26618+++ b/arch/x86/kernel/module.c
26619@@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
26620 }
26621 #endif
26622
26623-void *module_alloc(unsigned long size)
26624+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
26625 {
26626- if (PAGE_ALIGN(size) > MODULES_LEN)
26627+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
26628 return NULL;
26629 return __vmalloc_node_range(size, 1,
26630 MODULES_VADDR + get_module_load_offset(),
26631- MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
26632- PAGE_KERNEL_EXEC, NUMA_NO_NODE,
26633+ MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
26634+ prot, NUMA_NO_NODE,
26635 __builtin_return_address(0));
26636 }
26637
26638+void *module_alloc(unsigned long size)
26639+{
26640+
26641+#ifdef CONFIG_PAX_KERNEXEC
26642+ return __module_alloc(size, PAGE_KERNEL);
26643+#else
26644+ return __module_alloc(size, PAGE_KERNEL_EXEC);
26645+#endif
26646+
26647+}
26648+
26649+#ifdef CONFIG_PAX_KERNEXEC
26650+#ifdef CONFIG_X86_32
26651+void *module_alloc_exec(unsigned long size)
26652+{
26653+ struct vm_struct *area;
26654+
26655+ if (size == 0)
26656+ return NULL;
26657+
26658+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
26659+return area ? area->addr : NULL;
26660+}
26661+EXPORT_SYMBOL(module_alloc_exec);
26662+
26663+void module_free_exec(struct module *mod, void *module_region)
26664+{
26665+ vunmap(module_region);
26666+}
26667+EXPORT_SYMBOL(module_free_exec);
26668+#else
26669+void module_free_exec(struct module *mod, void *module_region)
26670+{
26671+ module_free(mod, module_region);
26672+}
26673+EXPORT_SYMBOL(module_free_exec);
26674+
26675+void *module_alloc_exec(unsigned long size)
26676+{
26677+ return __module_alloc(size, PAGE_KERNEL_RX);
26678+}
26679+EXPORT_SYMBOL(module_alloc_exec);
26680+#endif
26681+#endif
26682+
26683 #ifdef CONFIG_X86_32
26684 int apply_relocate(Elf32_Shdr *sechdrs,
26685 const char *strtab,
26686@@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26687 unsigned int i;
26688 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
26689 Elf32_Sym *sym;
26690- uint32_t *location;
26691+ uint32_t *plocation, location;
26692
26693 DEBUGP("Applying relocate section %u to %u\n",
26694 relsec, sechdrs[relsec].sh_info);
26695 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
26696 /* This is where to make the change */
26697- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
26698- + rel[i].r_offset;
26699+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
26700+ location = (uint32_t)plocation;
26701+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
26702+ plocation = ktla_ktva((void *)plocation);
26703 /* This is the symbol it is referring to. Note that all
26704 undefined symbols have been resolved. */
26705 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
26706@@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
26707 switch (ELF32_R_TYPE(rel[i].r_info)) {
26708 case R_386_32:
26709 /* We add the value into the location given */
26710- *location += sym->st_value;
26711+ pax_open_kernel();
26712+ *plocation += sym->st_value;
26713+ pax_close_kernel();
26714 break;
26715 case R_386_PC32:
26716 /* Add the value, subtract its position */
26717- *location += sym->st_value - (uint32_t)location;
26718+ pax_open_kernel();
26719+ *plocation += sym->st_value - location;
26720+ pax_close_kernel();
26721 break;
26722 default:
26723 pr_err("%s: Unknown relocation: %u\n",
26724@@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
26725 case R_X86_64_NONE:
26726 break;
26727 case R_X86_64_64:
26728+ pax_open_kernel();
26729 *(u64 *)loc = val;
26730+ pax_close_kernel();
26731 break;
26732 case R_X86_64_32:
26733+ pax_open_kernel();
26734 *(u32 *)loc = val;
26735+ pax_close_kernel();
26736 if (val != *(u32 *)loc)
26737 goto overflow;
26738 break;
26739 case R_X86_64_32S:
26740+ pax_open_kernel();
26741 *(s32 *)loc = val;
26742+ pax_close_kernel();
26743 if ((s64)val != *(s32 *)loc)
26744 goto overflow;
26745 break;
26746 case R_X86_64_PC32:
26747 val -= (u64)loc;
26748+ pax_open_kernel();
26749 *(u32 *)loc = val;
26750+ pax_close_kernel();
26751+
26752 #if 0
26753 if ((s64)val != *(s32 *)loc)
26754 goto overflow;
26755diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
26756index c9603ac..9f88728 100644
26757--- a/arch/x86/kernel/msr.c
26758+++ b/arch/x86/kernel/msr.c
26759@@ -37,6 +37,7 @@
26760 #include <linux/notifier.h>
26761 #include <linux/uaccess.h>
26762 #include <linux/gfp.h>
26763+#include <linux/grsecurity.h>
26764
26765 #include <asm/processor.h>
26766 #include <asm/msr.h>
26767@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
26768 int err = 0;
26769 ssize_t bytes = 0;
26770
26771+#ifdef CONFIG_GRKERNSEC_KMEM
26772+ gr_handle_msr_write();
26773+ return -EPERM;
26774+#endif
26775+
26776 if (count % 8)
26777 return -EINVAL; /* Invalid chunk size */
26778
26779@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
26780 err = -EBADF;
26781 break;
26782 }
26783+#ifdef CONFIG_GRKERNSEC_KMEM
26784+ gr_handle_msr_write();
26785+ return -EPERM;
26786+#endif
26787 if (copy_from_user(&regs, uregs, sizeof regs)) {
26788 err = -EFAULT;
26789 break;
26790@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
26791 return notifier_from_errno(err);
26792 }
26793
26794-static struct notifier_block __refdata msr_class_cpu_notifier = {
26795+static struct notifier_block msr_class_cpu_notifier = {
26796 .notifier_call = msr_class_cpu_callback,
26797 };
26798
26799diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
26800index c3e985d..110a36a 100644
26801--- a/arch/x86/kernel/nmi.c
26802+++ b/arch/x86/kernel/nmi.c
26803@@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
26804
26805 static void nmi_max_handler(struct irq_work *w)
26806 {
26807- struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
26808+ struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
26809 int remainder_ns, decimal_msecs;
26810- u64 whole_msecs = ACCESS_ONCE(a->max_duration);
26811+ u64 whole_msecs = ACCESS_ONCE(n->max_duration);
26812
26813 remainder_ns = do_div(whole_msecs, (1000 * 1000));
26814 decimal_msecs = remainder_ns / 1000;
26815
26816 printk_ratelimited(KERN_INFO
26817 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
26818- a->handler, whole_msecs, decimal_msecs);
26819+ n->action->handler, whole_msecs, decimal_msecs);
26820 }
26821
26822 static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26823@@ -134,11 +134,11 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26824 delta = sched_clock() - delta;
26825 trace_nmi_handler(a->handler, (int)delta, thishandled);
26826
26827- if (delta < nmi_longest_ns || delta < a->max_duration)
26828+ if (delta < nmi_longest_ns || delta < a->work->max_duration)
26829 continue;
26830
26831- a->max_duration = delta;
26832- irq_work_queue(&a->irq_work);
26833+ a->work->max_duration = delta;
26834+ irq_work_queue(&a->work->irq_work);
26835 }
26836
26837 rcu_read_unlock();
26838@@ -148,7 +148,7 @@ static int nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
26839 }
26840 NOKPROBE_SYMBOL(nmi_handle);
26841
26842-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26843+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
26844 {
26845 struct nmi_desc *desc = nmi_to_desc(type);
26846 unsigned long flags;
26847@@ -156,7 +156,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26848 if (!action->handler)
26849 return -EINVAL;
26850
26851- init_irq_work(&action->irq_work, nmi_max_handler);
26852+ action->work->action = action;
26853+ init_irq_work(&action->work->irq_work, nmi_max_handler);
26854
26855 spin_lock_irqsave(&desc->lock, flags);
26856
26857@@ -174,9 +175,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
26858 * event confuses some handlers (kdump uses this flag)
26859 */
26860 if (action->flags & NMI_FLAG_FIRST)
26861- list_add_rcu(&action->list, &desc->head);
26862+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
26863 else
26864- list_add_tail_rcu(&action->list, &desc->head);
26865+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
26866
26867 spin_unlock_irqrestore(&desc->lock, flags);
26868 return 0;
26869@@ -199,7 +200,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
26870 if (!strcmp(n->name, name)) {
26871 WARN(in_nmi(),
26872 "Trying to free NMI (%s) from NMI context!\n", n->name);
26873- list_del_rcu(&n->list);
26874+ pax_list_del_rcu((struct list_head *)&n->list);
26875 break;
26876 }
26877 }
26878@@ -528,6 +529,17 @@ static inline void nmi_nesting_postprocess(void)
26879 dotraplinkage notrace void
26880 do_nmi(struct pt_regs *regs, long error_code)
26881 {
26882+
26883+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26884+ if (!user_mode(regs)) {
26885+ unsigned long cs = regs->cs & 0xFFFF;
26886+ unsigned long ip = ktva_ktla(regs->ip);
26887+
26888+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
26889+ regs->ip = ip;
26890+ }
26891+#endif
26892+
26893 nmi_nesting_preprocess(regs);
26894
26895 nmi_enter();
26896diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
26897index 6d9582e..f746287 100644
26898--- a/arch/x86/kernel/nmi_selftest.c
26899+++ b/arch/x86/kernel/nmi_selftest.c
26900@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
26901 {
26902 /* trap all the unknown NMIs we may generate */
26903 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
26904- __initdata);
26905+ __initconst);
26906 }
26907
26908 static void __init cleanup_nmi_testsuite(void)
26909@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
26910 unsigned long timeout;
26911
26912 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
26913- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
26914+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
26915 nmi_fail = FAILURE;
26916 return;
26917 }
26918diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
26919index bbb6c73..24a58ef 100644
26920--- a/arch/x86/kernel/paravirt-spinlocks.c
26921+++ b/arch/x86/kernel/paravirt-spinlocks.c
26922@@ -8,7 +8,7 @@
26923
26924 #include <asm/paravirt.h>
26925
26926-struct pv_lock_ops pv_lock_ops = {
26927+struct pv_lock_ops pv_lock_ops __read_only = {
26928 #ifdef CONFIG_SMP
26929 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
26930 .unlock_kick = paravirt_nop,
26931diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
26932index 548d25f..f8fb99c 100644
26933--- a/arch/x86/kernel/paravirt.c
26934+++ b/arch/x86/kernel/paravirt.c
26935@@ -56,6 +56,9 @@ u64 _paravirt_ident_64(u64 x)
26936 {
26937 return x;
26938 }
26939+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26940+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
26941+#endif
26942
26943 void __init default_banner(void)
26944 {
26945@@ -142,16 +145,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
26946
26947 if (opfunc == NULL)
26948 /* If there's no function, patch it with a ud2a (BUG) */
26949- ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
26950- else if (opfunc == _paravirt_nop)
26951+ ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
26952+ else if (opfunc == (void *)_paravirt_nop)
26953 /* If the operation is a nop, then nop the callsite */
26954 ret = paravirt_patch_nop();
26955
26956 /* identity functions just return their single argument */
26957- else if (opfunc == _paravirt_ident_32)
26958+ else if (opfunc == (void *)_paravirt_ident_32)
26959 ret = paravirt_patch_ident_32(insnbuf, len);
26960- else if (opfunc == _paravirt_ident_64)
26961+ else if (opfunc == (void *)_paravirt_ident_64)
26962 ret = paravirt_patch_ident_64(insnbuf, len);
26963+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
26964+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
26965+ ret = paravirt_patch_ident_64(insnbuf, len);
26966+#endif
26967
26968 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
26969 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
26970@@ -176,7 +183,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
26971 if (insn_len > len || start == NULL)
26972 insn_len = len;
26973 else
26974- memcpy(insnbuf, start, insn_len);
26975+ memcpy(insnbuf, ktla_ktva(start), insn_len);
26976
26977 return insn_len;
26978 }
26979@@ -300,7 +307,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
26980 return this_cpu_read(paravirt_lazy_mode);
26981 }
26982
26983-struct pv_info pv_info = {
26984+struct pv_info pv_info __read_only = {
26985 .name = "bare hardware",
26986 .paravirt_enabled = 0,
26987 .kernel_rpl = 0,
26988@@ -311,16 +318,16 @@ struct pv_info pv_info = {
26989 #endif
26990 };
26991
26992-struct pv_init_ops pv_init_ops = {
26993+struct pv_init_ops pv_init_ops __read_only = {
26994 .patch = native_patch,
26995 };
26996
26997-struct pv_time_ops pv_time_ops = {
26998+struct pv_time_ops pv_time_ops __read_only = {
26999 .sched_clock = native_sched_clock,
27000 .steal_clock = native_steal_clock,
27001 };
27002
27003-__visible struct pv_irq_ops pv_irq_ops = {
27004+__visible struct pv_irq_ops pv_irq_ops __read_only = {
27005 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
27006 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
27007 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
27008@@ -332,7 +339,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
27009 #endif
27010 };
27011
27012-__visible struct pv_cpu_ops pv_cpu_ops = {
27013+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
27014 .cpuid = native_cpuid,
27015 .get_debugreg = native_get_debugreg,
27016 .set_debugreg = native_set_debugreg,
27017@@ -395,21 +402,26 @@ NOKPROBE_SYMBOL(native_get_debugreg);
27018 NOKPROBE_SYMBOL(native_set_debugreg);
27019 NOKPROBE_SYMBOL(native_load_idt);
27020
27021-struct pv_apic_ops pv_apic_ops = {
27022+struct pv_apic_ops pv_apic_ops __read_only= {
27023 #ifdef CONFIG_X86_LOCAL_APIC
27024 .startup_ipi_hook = paravirt_nop,
27025 #endif
27026 };
27027
27028-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
27029+#ifdef CONFIG_X86_32
27030+#ifdef CONFIG_X86_PAE
27031+/* 64-bit pagetable entries */
27032+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
27033+#else
27034 /* 32-bit pagetable entries */
27035 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
27036+#endif
27037 #else
27038 /* 64-bit pagetable entries */
27039 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
27040 #endif
27041
27042-struct pv_mmu_ops pv_mmu_ops = {
27043+struct pv_mmu_ops pv_mmu_ops __read_only = {
27044
27045 .read_cr2 = native_read_cr2,
27046 .write_cr2 = native_write_cr2,
27047@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
27048 .make_pud = PTE_IDENT,
27049
27050 .set_pgd = native_set_pgd,
27051+ .set_pgd_batched = native_set_pgd_batched,
27052 #endif
27053 #endif /* PAGETABLE_LEVELS >= 3 */
27054
27055@@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
27056 },
27057
27058 .set_fixmap = native_set_fixmap,
27059+
27060+#ifdef CONFIG_PAX_KERNEXEC
27061+ .pax_open_kernel = native_pax_open_kernel,
27062+ .pax_close_kernel = native_pax_close_kernel,
27063+#endif
27064+
27065 };
27066
27067 EXPORT_SYMBOL_GPL(pv_time_ops);
27068diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
27069index 0497f71..7186c0d 100644
27070--- a/arch/x86/kernel/pci-calgary_64.c
27071+++ b/arch/x86/kernel/pci-calgary_64.c
27072@@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
27073 tce_space = be64_to_cpu(readq(target));
27074 tce_space = tce_space & TAR_SW_BITS;
27075
27076- tce_space = tce_space & (~specified_table_size);
27077+ tce_space = tce_space & (~(unsigned long)specified_table_size);
27078 info->tce_space = (u64 *)__va(tce_space);
27079 }
27080 }
27081diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
27082index 35ccf75..7a15747 100644
27083--- a/arch/x86/kernel/pci-iommu_table.c
27084+++ b/arch/x86/kernel/pci-iommu_table.c
27085@@ -2,7 +2,7 @@
27086 #include <asm/iommu_table.h>
27087 #include <linux/string.h>
27088 #include <linux/kallsyms.h>
27089-
27090+#include <linux/sched.h>
27091
27092 #define DEBUG 1
27093
27094diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
27095index 77dd0ad..9ec4723 100644
27096--- a/arch/x86/kernel/pci-swiotlb.c
27097+++ b/arch/x86/kernel/pci-swiotlb.c
27098@@ -33,7 +33,7 @@ void x86_swiotlb_free_coherent(struct device *dev, size_t size,
27099 struct dma_attrs *attrs)
27100 {
27101 if (is_swiotlb_buffer(dma_to_phys(dev, dma_addr)))
27102- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
27103+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
27104 else
27105 dma_generic_free_coherent(dev, size, vaddr, dma_addr, attrs);
27106 }
27107diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
27108index ca7f0d5..8996469 100644
27109--- a/arch/x86/kernel/preempt.S
27110+++ b/arch/x86/kernel/preempt.S
27111@@ -3,12 +3,14 @@
27112 #include <asm/dwarf2.h>
27113 #include <asm/asm.h>
27114 #include <asm/calling.h>
27115+#include <asm/alternative-asm.h>
27116
27117 ENTRY(___preempt_schedule)
27118 CFI_STARTPROC
27119 SAVE_ALL
27120 call preempt_schedule
27121 RESTORE_ALL
27122+ pax_force_retaddr
27123 ret
27124 CFI_ENDPROC
27125
27126@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
27127 SAVE_ALL
27128 call preempt_schedule_context
27129 RESTORE_ALL
27130+ pax_force_retaddr
27131 ret
27132 CFI_ENDPROC
27133
27134diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
27135index f804dc9..7c62095 100644
27136--- a/arch/x86/kernel/process.c
27137+++ b/arch/x86/kernel/process.c
27138@@ -36,7 +36,8 @@
27139 * section. Since TSS's are completely CPU-local, we want them
27140 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
27141 */
27142-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
27143+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
27144+EXPORT_SYMBOL(init_tss);
27145
27146 #ifdef CONFIG_X86_64
27147 static DEFINE_PER_CPU(unsigned char, is_idle);
27148@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
27149 task_xstate_cachep =
27150 kmem_cache_create("task_xstate", xstate_size,
27151 __alignof__(union thread_xstate),
27152- SLAB_PANIC | SLAB_NOTRACK, NULL);
27153+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
27154 setup_xstate_comp();
27155 }
27156
27157@@ -106,7 +107,7 @@ void exit_thread(void)
27158 unsigned long *bp = t->io_bitmap_ptr;
27159
27160 if (bp) {
27161- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
27162+ struct tss_struct *tss = init_tss + get_cpu();
27163
27164 t->io_bitmap_ptr = NULL;
27165 clear_thread_flag(TIF_IO_BITMAP);
27166@@ -126,6 +127,9 @@ void flush_thread(void)
27167 {
27168 struct task_struct *tsk = current;
27169
27170+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
27171+ loadsegment(gs, 0);
27172+#endif
27173 flush_ptrace_hw_breakpoint(tsk);
27174 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
27175 drop_init_fpu(tsk);
27176@@ -272,7 +276,7 @@ static void __exit_idle(void)
27177 void exit_idle(void)
27178 {
27179 /* idle loop has pid 0 */
27180- if (current->pid)
27181+ if (task_pid_nr(current))
27182 return;
27183 __exit_idle();
27184 }
27185@@ -325,7 +329,7 @@ bool xen_set_default_idle(void)
27186 return ret;
27187 }
27188 #endif
27189-void stop_this_cpu(void *dummy)
27190+__noreturn void stop_this_cpu(void *dummy)
27191 {
27192 local_irq_disable();
27193 /*
27194@@ -454,16 +458,37 @@ static int __init idle_setup(char *str)
27195 }
27196 early_param("idle", idle_setup);
27197
27198-unsigned long arch_align_stack(unsigned long sp)
27199+#ifdef CONFIG_PAX_RANDKSTACK
27200+void pax_randomize_kstack(struct pt_regs *regs)
27201 {
27202- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
27203- sp -= get_random_int() % 8192;
27204- return sp & ~0xf;
27205-}
27206+ struct thread_struct *thread = &current->thread;
27207+ unsigned long time;
27208
27209-unsigned long arch_randomize_brk(struct mm_struct *mm)
27210-{
27211- unsigned long range_end = mm->brk + 0x02000000;
27212- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
27213-}
27214+ if (!randomize_va_space)
27215+ return;
27216+
27217+ if (v8086_mode(regs))
27218+ return;
27219
27220+ rdtscl(time);
27221+
27222+ /* P4 seems to return a 0 LSB, ignore it */
27223+#ifdef CONFIG_MPENTIUM4
27224+ time &= 0x3EUL;
27225+ time <<= 2;
27226+#elif defined(CONFIG_X86_64)
27227+ time &= 0xFUL;
27228+ time <<= 4;
27229+#else
27230+ time &= 0x1FUL;
27231+ time <<= 3;
27232+#endif
27233+
27234+ thread->sp0 ^= time;
27235+ load_sp0(init_tss + smp_processor_id(), thread);
27236+
27237+#ifdef CONFIG_X86_64
27238+ this_cpu_write(kernel_stack, thread->sp0);
27239+#endif
27240+}
27241+#endif
27242diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
27243index 7bc86bb..0ea06e8 100644
27244--- a/arch/x86/kernel/process_32.c
27245+++ b/arch/x86/kernel/process_32.c
27246@@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
27247 unsigned long thread_saved_pc(struct task_struct *tsk)
27248 {
27249 return ((unsigned long *)tsk->thread.sp)[3];
27250+//XXX return tsk->thread.eip;
27251 }
27252
27253 void __show_regs(struct pt_regs *regs, int all)
27254@@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
27255 unsigned long sp;
27256 unsigned short ss, gs;
27257
27258- if (user_mode_vm(regs)) {
27259+ if (user_mode(regs)) {
27260 sp = regs->sp;
27261 ss = regs->ss & 0xffff;
27262- gs = get_user_gs(regs);
27263 } else {
27264 sp = kernel_stack_pointer(regs);
27265 savesegment(ss, ss);
27266- savesegment(gs, gs);
27267 }
27268+ gs = get_user_gs(regs);
27269
27270 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
27271 (u16)regs->cs, regs->ip, regs->flags,
27272- smp_processor_id());
27273+ raw_smp_processor_id());
27274 print_symbol("EIP is at %s\n", regs->ip);
27275
27276 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
27277@@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
27278 int copy_thread(unsigned long clone_flags, unsigned long sp,
27279 unsigned long arg, struct task_struct *p)
27280 {
27281- struct pt_regs *childregs = task_pt_regs(p);
27282+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
27283 struct task_struct *tsk;
27284 int err;
27285
27286 p->thread.sp = (unsigned long) childregs;
27287 p->thread.sp0 = (unsigned long) (childregs+1);
27288+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
27289
27290 if (unlikely(p->flags & PF_KTHREAD)) {
27291 /* kernel thread */
27292 memset(childregs, 0, sizeof(struct pt_regs));
27293 p->thread.ip = (unsigned long) ret_from_kernel_thread;
27294- task_user_gs(p) = __KERNEL_STACK_CANARY;
27295- childregs->ds = __USER_DS;
27296- childregs->es = __USER_DS;
27297+ savesegment(gs, childregs->gs);
27298+ childregs->ds = __KERNEL_DS;
27299+ childregs->es = __KERNEL_DS;
27300 childregs->fs = __KERNEL_PERCPU;
27301 childregs->bx = sp; /* function */
27302 childregs->bp = arg;
27303@@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27304 struct thread_struct *prev = &prev_p->thread,
27305 *next = &next_p->thread;
27306 int cpu = smp_processor_id();
27307- struct tss_struct *tss = &per_cpu(init_tss, cpu);
27308+ struct tss_struct *tss = init_tss + cpu;
27309 fpu_switch_t fpu;
27310
27311 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
27312@@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27313 */
27314 lazy_save_gs(prev->gs);
27315
27316+#ifdef CONFIG_PAX_MEMORY_UDEREF
27317+ __set_fs(task_thread_info(next_p)->addr_limit);
27318+#endif
27319+
27320 /*
27321 * Load the per-thread Thread-Local Storage descriptor.
27322 */
27323@@ -314,9 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27324 */
27325 arch_end_context_switch(next_p);
27326
27327- this_cpu_write(kernel_stack,
27328- (unsigned long)task_stack_page(next_p) +
27329- THREAD_SIZE - KERNEL_STACK_OFFSET);
27330+ this_cpu_write(current_task, next_p);
27331+ this_cpu_write(current_tinfo, &next_p->tinfo);
27332+ this_cpu_write(kernel_stack, next->sp0);
27333
27334 /*
27335 * Restore %gs if needed (which is common)
27336@@ -326,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27337
27338 switch_fpu_finish(next_p, fpu);
27339
27340- this_cpu_write(current_task, next_p);
27341-
27342 return prev_p;
27343 }
27344
27345@@ -357,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
27346 } while (count++ < 16);
27347 return 0;
27348 }
27349-
27350diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
27351index ca5b02d..c0b2f6a 100644
27352--- a/arch/x86/kernel/process_64.c
27353+++ b/arch/x86/kernel/process_64.c
27354@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
27355 struct pt_regs *childregs;
27356 struct task_struct *me = current;
27357
27358- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
27359+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
27360 childregs = task_pt_regs(p);
27361 p->thread.sp = (unsigned long) childregs;
27362 p->thread.usersp = me->thread.usersp;
27363+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
27364 set_tsk_thread_flag(p, TIF_FORK);
27365 p->thread.fpu_counter = 0;
27366 p->thread.io_bitmap_ptr = NULL;
27367@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
27368 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
27369 savesegment(es, p->thread.es);
27370 savesegment(ds, p->thread.ds);
27371+ savesegment(ss, p->thread.ss);
27372+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
27373 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
27374
27375 if (unlikely(p->flags & PF_KTHREAD)) {
27376@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27377 struct thread_struct *prev = &prev_p->thread;
27378 struct thread_struct *next = &next_p->thread;
27379 int cpu = smp_processor_id();
27380- struct tss_struct *tss = &per_cpu(init_tss, cpu);
27381+ struct tss_struct *tss = init_tss + cpu;
27382 unsigned fsindex, gsindex;
27383 fpu_switch_t fpu;
27384
27385@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27386 if (unlikely(next->ds | prev->ds))
27387 loadsegment(ds, next->ds);
27388
27389+ savesegment(ss, prev->ss);
27390+ if (unlikely(next->ss != prev->ss))
27391+ loadsegment(ss, next->ss);
27392
27393 /* We must save %fs and %gs before load_TLS() because
27394 * %fs and %gs may be cleared by load_TLS().
27395@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27396 prev->usersp = this_cpu_read(old_rsp);
27397 this_cpu_write(old_rsp, next->usersp);
27398 this_cpu_write(current_task, next_p);
27399+ this_cpu_write(current_tinfo, &next_p->tinfo);
27400
27401 /*
27402 * If it were not for PREEMPT_ACTIVE we could guarantee that the
27403@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
27404 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
27405 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
27406
27407- this_cpu_write(kernel_stack,
27408- (unsigned long)task_stack_page(next_p) +
27409- THREAD_SIZE - KERNEL_STACK_OFFSET);
27410+ this_cpu_write(kernel_stack, next->sp0);
27411
27412 /*
27413 * Now maybe reload the debug registers and handle I/O bitmaps
27414@@ -443,12 +448,11 @@ unsigned long get_wchan(struct task_struct *p)
27415 if (!p || p == current || p->state == TASK_RUNNING)
27416 return 0;
27417 stack = (unsigned long)task_stack_page(p);
27418- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
27419+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
27420 return 0;
27421 fp = *(u64 *)(p->thread.sp);
27422 do {
27423- if (fp < (unsigned long)stack ||
27424- fp >= (unsigned long)stack+THREAD_SIZE)
27425+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
27426 return 0;
27427 ip = *(u64 *)(fp+8);
27428 if (!in_sched_functions(ip))
27429diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
27430index 678c0ad..2fc2a7b 100644
27431--- a/arch/x86/kernel/ptrace.c
27432+++ b/arch/x86/kernel/ptrace.c
27433@@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
27434 unsigned long sp = (unsigned long)&regs->sp;
27435 u32 *prev_esp;
27436
27437- if (context == (sp & ~(THREAD_SIZE - 1)))
27438+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
27439 return sp;
27440
27441- prev_esp = (u32 *)(context);
27442+ prev_esp = *(u32 **)(context);
27443 if (prev_esp)
27444 return (unsigned long)prev_esp;
27445
27446@@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
27447 if (child->thread.gs != value)
27448 return do_arch_prctl(child, ARCH_SET_GS, value);
27449 return 0;
27450+
27451+ case offsetof(struct user_regs_struct,ip):
27452+ /*
27453+ * Protect against any attempt to set ip to an
27454+ * impossible address. There are dragons lurking if the
27455+ * address is noncanonical. (This explicitly allows
27456+ * setting ip to TASK_SIZE_MAX, because user code can do
27457+ * that all by itself by running off the end of its
27458+ * address space.
27459+ */
27460+ if (value > TASK_SIZE_MAX)
27461+ return -EIO;
27462+ break;
27463+
27464 #endif
27465 }
27466
27467@@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
27468 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
27469 {
27470 int i;
27471- int dr7 = 0;
27472+ unsigned long dr7 = 0;
27473 struct arch_hw_breakpoint *info;
27474
27475 for (i = 0; i < HBP_NUM; i++) {
27476@@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
27477 unsigned long addr, unsigned long data)
27478 {
27479 int ret;
27480- unsigned long __user *datap = (unsigned long __user *)data;
27481+ unsigned long __user *datap = (__force unsigned long __user *)data;
27482
27483 switch (request) {
27484 /* read the word at location addr in the USER area. */
27485@@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
27486 if ((int) addr < 0)
27487 return -EIO;
27488 ret = do_get_thread_area(child, addr,
27489- (struct user_desc __user *)data);
27490+ (__force struct user_desc __user *) data);
27491 break;
27492
27493 case PTRACE_SET_THREAD_AREA:
27494 if ((int) addr < 0)
27495 return -EIO;
27496 ret = do_set_thread_area(child, addr,
27497- (struct user_desc __user *)data, 0);
27498+ (__force struct user_desc __user *) data, 0);
27499 break;
27500 #endif
27501
27502@@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
27503
27504 #ifdef CONFIG_X86_64
27505
27506-static struct user_regset x86_64_regsets[] __read_mostly = {
27507+static user_regset_no_const x86_64_regsets[] __read_only = {
27508 [REGSET_GENERAL] = {
27509 .core_note_type = NT_PRSTATUS,
27510 .n = sizeof(struct user_regs_struct) / sizeof(long),
27511@@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
27512 #endif /* CONFIG_X86_64 */
27513
27514 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
27515-static struct user_regset x86_32_regsets[] __read_mostly = {
27516+static user_regset_no_const x86_32_regsets[] __read_only = {
27517 [REGSET_GENERAL] = {
27518 .core_note_type = NT_PRSTATUS,
27519 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
27520@@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
27521 */
27522 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
27523
27524-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27525+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
27526 {
27527 #ifdef CONFIG_X86_64
27528 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
27529@@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
27530 memset(info, 0, sizeof(*info));
27531 info->si_signo = SIGTRAP;
27532 info->si_code = si_code;
27533- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
27534+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
27535 }
27536
27537 void user_single_step_siginfo(struct task_struct *tsk,
27538@@ -1450,6 +1464,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
27539 # define IS_IA32 0
27540 #endif
27541
27542+#ifdef CONFIG_GRKERNSEC_SETXID
27543+extern void gr_delayed_cred_worker(void);
27544+#endif
27545+
27546 /*
27547 * We must return the syscall number to actually look up in the table.
27548 * This can be -1L to skip running any syscall at all.
27549@@ -1460,6 +1478,11 @@ long syscall_trace_enter(struct pt_regs *regs)
27550
27551 user_exit();
27552
27553+#ifdef CONFIG_GRKERNSEC_SETXID
27554+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27555+ gr_delayed_cred_worker();
27556+#endif
27557+
27558 /*
27559 * If we stepped into a sysenter/syscall insn, it trapped in
27560 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
27561@@ -1515,6 +1538,11 @@ void syscall_trace_leave(struct pt_regs *regs)
27562 */
27563 user_exit();
27564
27565+#ifdef CONFIG_GRKERNSEC_SETXID
27566+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
27567+ gr_delayed_cred_worker();
27568+#endif
27569+
27570 audit_syscall_exit(regs);
27571
27572 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
27573diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
27574index 2f355d2..e75ed0a 100644
27575--- a/arch/x86/kernel/pvclock.c
27576+++ b/arch/x86/kernel/pvclock.c
27577@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
27578 reset_hung_task_detector();
27579 }
27580
27581-static atomic64_t last_value = ATOMIC64_INIT(0);
27582+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
27583
27584 void pvclock_resume(void)
27585 {
27586- atomic64_set(&last_value, 0);
27587+ atomic64_set_unchecked(&last_value, 0);
27588 }
27589
27590 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
27591@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
27592 * updating at the same time, and one of them could be slightly behind,
27593 * making the assumption that last_value always go forward fail to hold.
27594 */
27595- last = atomic64_read(&last_value);
27596+ last = atomic64_read_unchecked(&last_value);
27597 do {
27598 if (ret < last)
27599 return last;
27600- last = atomic64_cmpxchg(&last_value, last, ret);
27601+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
27602 } while (unlikely(last != ret));
27603
27604 return ret;
27605diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
27606index 17962e6..47f55db 100644
27607--- a/arch/x86/kernel/reboot.c
27608+++ b/arch/x86/kernel/reboot.c
27609@@ -69,6 +69,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
27610
27611 void __noreturn machine_real_restart(unsigned int type)
27612 {
27613+
27614+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
27615+ struct desc_struct *gdt;
27616+#endif
27617+
27618 local_irq_disable();
27619
27620 /*
27621@@ -96,7 +101,29 @@ void __noreturn machine_real_restart(unsigned int type)
27622
27623 /* Jump to the identity-mapped low memory code */
27624 #ifdef CONFIG_X86_32
27625- asm volatile("jmpl *%0" : :
27626+
27627+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
27628+ gdt = get_cpu_gdt_table(smp_processor_id());
27629+ pax_open_kernel();
27630+#ifdef CONFIG_PAX_MEMORY_UDEREF
27631+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
27632+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
27633+ loadsegment(ds, __KERNEL_DS);
27634+ loadsegment(es, __KERNEL_DS);
27635+ loadsegment(ss, __KERNEL_DS);
27636+#endif
27637+#ifdef CONFIG_PAX_KERNEXEC
27638+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
27639+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
27640+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
27641+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
27642+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
27643+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
27644+#endif
27645+ pax_close_kernel();
27646+#endif
27647+
27648+ asm volatile("ljmpl *%0" : :
27649 "rm" (real_mode_header->machine_real_restart_asm),
27650 "a" (type));
27651 #else
27652@@ -500,7 +527,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
27653 * This means that this function can never return, it can misbehave
27654 * by not rebooting properly and hanging.
27655 */
27656-static void native_machine_emergency_restart(void)
27657+static void __noreturn native_machine_emergency_restart(void)
27658 {
27659 int i;
27660 int attempt = 0;
27661@@ -620,13 +647,13 @@ void native_machine_shutdown(void)
27662 #endif
27663 }
27664
27665-static void __machine_emergency_restart(int emergency)
27666+static void __noreturn __machine_emergency_restart(int emergency)
27667 {
27668 reboot_emergency = emergency;
27669 machine_ops.emergency_restart();
27670 }
27671
27672-static void native_machine_restart(char *__unused)
27673+static void __noreturn native_machine_restart(char *__unused)
27674 {
27675 pr_notice("machine restart\n");
27676
27677@@ -635,7 +662,7 @@ static void native_machine_restart(char *__unused)
27678 __machine_emergency_restart(0);
27679 }
27680
27681-static void native_machine_halt(void)
27682+static void __noreturn native_machine_halt(void)
27683 {
27684 /* Stop other cpus and apics */
27685 machine_shutdown();
27686@@ -645,7 +672,7 @@ static void native_machine_halt(void)
27687 stop_this_cpu(NULL);
27688 }
27689
27690-static void native_machine_power_off(void)
27691+static void __noreturn native_machine_power_off(void)
27692 {
27693 if (pm_power_off) {
27694 if (!reboot_force)
27695@@ -654,9 +681,10 @@ static void native_machine_power_off(void)
27696 }
27697 /* A fallback in case there is no PM info available */
27698 tboot_shutdown(TB_SHUTDOWN_HALT);
27699+ unreachable();
27700 }
27701
27702-struct machine_ops machine_ops = {
27703+struct machine_ops machine_ops __read_only = {
27704 .power_off = native_machine_power_off,
27705 .shutdown = native_machine_shutdown,
27706 .emergency_restart = native_machine_emergency_restart,
27707diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
27708index c8e41e9..64049ef 100644
27709--- a/arch/x86/kernel/reboot_fixups_32.c
27710+++ b/arch/x86/kernel/reboot_fixups_32.c
27711@@ -57,7 +57,7 @@ struct device_fixup {
27712 unsigned int vendor;
27713 unsigned int device;
27714 void (*reboot_fixup)(struct pci_dev *);
27715-};
27716+} __do_const;
27717
27718 /*
27719 * PCI ids solely used for fixups_table go here
27720diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
27721index 3fd2c69..a444264 100644
27722--- a/arch/x86/kernel/relocate_kernel_64.S
27723+++ b/arch/x86/kernel/relocate_kernel_64.S
27724@@ -96,8 +96,7 @@ relocate_kernel:
27725
27726 /* jump to identity mapped page */
27727 addq $(identity_mapped - relocate_kernel), %r8
27728- pushq %r8
27729- ret
27730+ jmp *%r8
27731
27732 identity_mapped:
27733 /* set return address to 0 if not preserving context */
27734diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
27735index 41ead8d..7ccde23 100644
27736--- a/arch/x86/kernel/setup.c
27737+++ b/arch/x86/kernel/setup.c
27738@@ -110,6 +110,7 @@
27739 #include <asm/mce.h>
27740 #include <asm/alternative.h>
27741 #include <asm/prom.h>
27742+#include <asm/boot.h>
27743
27744 /*
27745 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
27746@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
27747 #endif
27748
27749
27750-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
27751-__visible unsigned long mmu_cr4_features;
27752+#ifdef CONFIG_X86_64
27753+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
27754+#elif defined(CONFIG_X86_PAE)
27755+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
27756 #else
27757-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
27758+__visible unsigned long mmu_cr4_features __read_only;
27759 #endif
27760
27761+void set_in_cr4(unsigned long mask)
27762+{
27763+ unsigned long cr4 = read_cr4();
27764+
27765+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
27766+ return;
27767+
27768+ pax_open_kernel();
27769+ mmu_cr4_features |= mask;
27770+ pax_close_kernel();
27771+
27772+ if (trampoline_cr4_features)
27773+ *trampoline_cr4_features = mmu_cr4_features;
27774+ cr4 |= mask;
27775+ write_cr4(cr4);
27776+}
27777+EXPORT_SYMBOL(set_in_cr4);
27778+
27779+void clear_in_cr4(unsigned long mask)
27780+{
27781+ unsigned long cr4 = read_cr4();
27782+
27783+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
27784+ return;
27785+
27786+ pax_open_kernel();
27787+ mmu_cr4_features &= ~mask;
27788+ pax_close_kernel();
27789+
27790+ if (trampoline_cr4_features)
27791+ *trampoline_cr4_features = mmu_cr4_features;
27792+ cr4 &= ~mask;
27793+ write_cr4(cr4);
27794+}
27795+EXPORT_SYMBOL(clear_in_cr4);
27796+
27797 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
27798 int bootloader_type, bootloader_version;
27799
27800@@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
27801 * area (640->1Mb) as ram even though it is not.
27802 * take them out.
27803 */
27804- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
27805+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
27806
27807 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
27808 }
27809@@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
27810 /* called before trim_bios_range() to spare extra sanitize */
27811 static void __init e820_add_kernel_range(void)
27812 {
27813- u64 start = __pa_symbol(_text);
27814+ u64 start = __pa_symbol(ktla_ktva(_text));
27815 u64 size = __pa_symbol(_end) - start;
27816
27817 /*
27818@@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
27819
27820 void __init setup_arch(char **cmdline_p)
27821 {
27822+#ifdef CONFIG_X86_32
27823+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
27824+#else
27825 memblock_reserve(__pa_symbol(_text),
27826 (unsigned long)__bss_stop - (unsigned long)_text);
27827+#endif
27828
27829 early_reserve_initrd();
27830
27831@@ -946,14 +989,14 @@ void __init setup_arch(char **cmdline_p)
27832
27833 if (!boot_params.hdr.root_flags)
27834 root_mountflags &= ~MS_RDONLY;
27835- init_mm.start_code = (unsigned long) _text;
27836- init_mm.end_code = (unsigned long) _etext;
27837+ init_mm.start_code = ktla_ktva((unsigned long) _text);
27838+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
27839 init_mm.end_data = (unsigned long) _edata;
27840 init_mm.brk = _brk_end;
27841
27842- code_resource.start = __pa_symbol(_text);
27843- code_resource.end = __pa_symbol(_etext)-1;
27844- data_resource.start = __pa_symbol(_etext);
27845+ code_resource.start = __pa_symbol(ktla_ktva(_text));
27846+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
27847+ data_resource.start = __pa_symbol(_sdata);
27848 data_resource.end = __pa_symbol(_edata)-1;
27849 bss_resource.start = __pa_symbol(__bss_start);
27850 bss_resource.end = __pa_symbol(__bss_stop)-1;
27851diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
27852index 5cdff03..80fa283 100644
27853--- a/arch/x86/kernel/setup_percpu.c
27854+++ b/arch/x86/kernel/setup_percpu.c
27855@@ -21,19 +21,17 @@
27856 #include <asm/cpu.h>
27857 #include <asm/stackprotector.h>
27858
27859-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
27860+#ifdef CONFIG_SMP
27861+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
27862 EXPORT_PER_CPU_SYMBOL(cpu_number);
27863+#endif
27864
27865-#ifdef CONFIG_X86_64
27866 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
27867-#else
27868-#define BOOT_PERCPU_OFFSET 0
27869-#endif
27870
27871 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
27872 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
27873
27874-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
27875+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
27876 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
27877 };
27878 EXPORT_SYMBOL(__per_cpu_offset);
27879@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
27880 {
27881 #ifdef CONFIG_NEED_MULTIPLE_NODES
27882 pg_data_t *last = NULL;
27883- unsigned int cpu;
27884+ int cpu;
27885
27886 for_each_possible_cpu(cpu) {
27887 int node = early_cpu_to_node(cpu);
27888@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
27889 {
27890 #ifdef CONFIG_X86_32
27891 struct desc_struct gdt;
27892+ unsigned long base = per_cpu_offset(cpu);
27893
27894- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
27895- 0x2 | DESCTYPE_S, 0x8);
27896- gdt.s = 1;
27897+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
27898+ 0x83 | DESCTYPE_S, 0xC);
27899 write_gdt_entry(get_cpu_gdt_table(cpu),
27900 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
27901 #endif
27902@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
27903 /* alrighty, percpu areas up and running */
27904 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
27905 for_each_possible_cpu(cpu) {
27906+#ifdef CONFIG_CC_STACKPROTECTOR
27907+#ifdef CONFIG_X86_32
27908+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
27909+#endif
27910+#endif
27911 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
27912 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
27913 per_cpu(cpu_number, cpu) = cpu;
27914@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
27915 */
27916 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
27917 #endif
27918+#ifdef CONFIG_CC_STACKPROTECTOR
27919+#ifdef CONFIG_X86_32
27920+ if (!cpu)
27921+ per_cpu(stack_canary.canary, cpu) = canary;
27922+#endif
27923+#endif
27924 /*
27925 * Up to this point, the boot CPU has been using .init.data
27926 * area. Reload any changed state for the boot CPU.
27927diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
27928index ed37a76..39f936e 100644
27929--- a/arch/x86/kernel/signal.c
27930+++ b/arch/x86/kernel/signal.c
27931@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
27932 * Align the stack pointer according to the i386 ABI,
27933 * i.e. so that on function entry ((sp + 4) & 15) == 0.
27934 */
27935- sp = ((sp + 4) & -16ul) - 4;
27936+ sp = ((sp - 12) & -16ul) - 4;
27937 #else /* !CONFIG_X86_32 */
27938 sp = round_down(sp, 16) - 8;
27939 #endif
27940@@ -298,10 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27941 }
27942
27943 if (current->mm->context.vdso)
27944- restorer = current->mm->context.vdso +
27945- selected_vdso32->sym___kernel_sigreturn;
27946+ restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_sigreturn);
27947 else
27948- restorer = &frame->retcode;
27949+ restorer = (void __user *)&frame->retcode;
27950 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27951 restorer = ksig->ka.sa.sa_restorer;
27952
27953@@ -315,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
27954 * reasons and because gdb uses it as a signature to notice
27955 * signal handler stack frames.
27956 */
27957- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
27958+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
27959
27960 if (err)
27961 return -EFAULT;
27962@@ -362,8 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27963 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
27964
27965 /* Set up to return from userspace. */
27966- restorer = current->mm->context.vdso +
27967- selected_vdso32->sym___kernel_rt_sigreturn;
27968+ if (current->mm->context.vdso)
27969+ restorer = (void __force_user *)(current->mm->context.vdso + selected_vdso32->sym___kernel_rt_sigreturn);
27970+ else
27971+ restorer = (void __user *)&frame->retcode;
27972 if (ksig->ka.sa.sa_flags & SA_RESTORER)
27973 restorer = ksig->ka.sa.sa_restorer;
27974 put_user_ex(restorer, &frame->pretcode);
27975@@ -375,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
27976 * reasons and because gdb uses it as a signature to notice
27977 * signal handler stack frames.
27978 */
27979- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
27980+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
27981 } put_user_catch(err);
27982
27983 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
27984@@ -611,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27985 {
27986 int usig = signr_convert(ksig->sig);
27987 sigset_t *set = sigmask_to_save();
27988- compat_sigset_t *cset = (compat_sigset_t *) set;
27989+ sigset_t sigcopy;
27990+ compat_sigset_t *cset;
27991+
27992+ sigcopy = *set;
27993+
27994+ cset = (compat_sigset_t *) &sigcopy;
27995
27996 /* Set up the stack frame */
27997 if (is_ia32_frame()) {
27998@@ -622,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
27999 } else if (is_x32_frame()) {
28000 return x32_setup_rt_frame(ksig, cset, regs);
28001 } else {
28002- return __setup_rt_frame(ksig->sig, ksig, set, regs);
28003+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
28004 }
28005 }
28006
28007diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
28008index be8e1bd..a3d93fa 100644
28009--- a/arch/x86/kernel/smp.c
28010+++ b/arch/x86/kernel/smp.c
28011@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
28012
28013 __setup("nonmi_ipi", nonmi_ipi_setup);
28014
28015-struct smp_ops smp_ops = {
28016+struct smp_ops smp_ops __read_only = {
28017 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
28018 .smp_prepare_cpus = native_smp_prepare_cpus,
28019 .smp_cpus_done = native_smp_cpus_done,
28020diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
28021index 42a2dca..35a07aa 100644
28022--- a/arch/x86/kernel/smpboot.c
28023+++ b/arch/x86/kernel/smpboot.c
28024@@ -226,14 +226,17 @@ static void notrace start_secondary(void *unused)
28025
28026 enable_start_cpu0 = 0;
28027
28028-#ifdef CONFIG_X86_32
28029+ /* otherwise gcc will move up smp_processor_id before the cpu_init */
28030+ barrier();
28031+
28032 /* switch away from the initial page table */
28033+#ifdef CONFIG_PAX_PER_CPU_PGD
28034+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
28035+#else
28036 load_cr3(swapper_pg_dir);
28037+#endif
28038 __flush_tlb_all();
28039-#endif
28040
28041- /* otherwise gcc will move up smp_processor_id before the cpu_init */
28042- barrier();
28043 /*
28044 * Check TSC synchronization with the BP:
28045 */
28046@@ -760,8 +763,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
28047 alternatives_enable_smp();
28048
28049 idle->thread.sp = (unsigned long) (((struct pt_regs *)
28050- (THREAD_SIZE + task_stack_page(idle))) - 1);
28051+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
28052 per_cpu(current_task, cpu) = idle;
28053+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
28054
28055 #ifdef CONFIG_X86_32
28056 /* Stack for startup_32 can be just as for start_secondary onwards */
28057@@ -770,10 +774,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
28058 clear_tsk_thread_flag(idle, TIF_FORK);
28059 initial_gs = per_cpu_offset(cpu);
28060 #endif
28061- per_cpu(kernel_stack, cpu) =
28062- (unsigned long)task_stack_page(idle) -
28063- KERNEL_STACK_OFFSET + THREAD_SIZE;
28064+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
28065+ pax_open_kernel();
28066 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
28067+ pax_close_kernel();
28068 initial_code = (unsigned long)start_secondary;
28069 stack_start = idle->thread.sp;
28070
28071@@ -919,6 +923,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
28072 /* the FPU context is blank, nobody can own it */
28073 __cpu_disable_lazy_restore(cpu);
28074
28075+#ifdef CONFIG_PAX_PER_CPU_PGD
28076+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
28077+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28078+ KERNEL_PGD_PTRS);
28079+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
28080+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28081+ KERNEL_PGD_PTRS);
28082+#endif
28083+
28084 err = do_boot_cpu(apicid, cpu, tidle);
28085 if (err) {
28086 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
28087diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
28088index 9b4d51d..5d28b58 100644
28089--- a/arch/x86/kernel/step.c
28090+++ b/arch/x86/kernel/step.c
28091@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
28092 struct desc_struct *desc;
28093 unsigned long base;
28094
28095- seg &= ~7UL;
28096+ seg >>= 3;
28097
28098 mutex_lock(&child->mm->context.lock);
28099- if (unlikely((seg >> 3) >= child->mm->context.size))
28100+ if (unlikely(seg >= child->mm->context.size))
28101 addr = -1L; /* bogus selector, access would fault */
28102 else {
28103 desc = child->mm->context.ldt + seg;
28104@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
28105 addr += base;
28106 }
28107 mutex_unlock(&child->mm->context.lock);
28108- }
28109+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
28110+ addr = ktla_ktva(addr);
28111
28112 return addr;
28113 }
28114@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
28115 unsigned char opcode[15];
28116 unsigned long addr = convert_ip_to_linear(child, regs);
28117
28118+ if (addr == -EINVAL)
28119+ return 0;
28120+
28121 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
28122 for (i = 0; i < copied; i++) {
28123 switch (opcode[i]) {
28124diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
28125new file mode 100644
28126index 0000000..5877189
28127--- /dev/null
28128+++ b/arch/x86/kernel/sys_i386_32.c
28129@@ -0,0 +1,189 @@
28130+/*
28131+ * This file contains various random system calls that
28132+ * have a non-standard calling sequence on the Linux/i386
28133+ * platform.
28134+ */
28135+
28136+#include <linux/errno.h>
28137+#include <linux/sched.h>
28138+#include <linux/mm.h>
28139+#include <linux/fs.h>
28140+#include <linux/smp.h>
28141+#include <linux/sem.h>
28142+#include <linux/msg.h>
28143+#include <linux/shm.h>
28144+#include <linux/stat.h>
28145+#include <linux/syscalls.h>
28146+#include <linux/mman.h>
28147+#include <linux/file.h>
28148+#include <linux/utsname.h>
28149+#include <linux/ipc.h>
28150+#include <linux/elf.h>
28151+
28152+#include <linux/uaccess.h>
28153+#include <linux/unistd.h>
28154+
28155+#include <asm/syscalls.h>
28156+
28157+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
28158+{
28159+ unsigned long pax_task_size = TASK_SIZE;
28160+
28161+#ifdef CONFIG_PAX_SEGMEXEC
28162+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
28163+ pax_task_size = SEGMEXEC_TASK_SIZE;
28164+#endif
28165+
28166+ if (flags & MAP_FIXED)
28167+ if (len > pax_task_size || addr > pax_task_size - len)
28168+ return -EINVAL;
28169+
28170+ return 0;
28171+}
28172+
28173+/*
28174+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
28175+ */
28176+static unsigned long get_align_mask(void)
28177+{
28178+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
28179+ return 0;
28180+
28181+ if (!(current->flags & PF_RANDOMIZE))
28182+ return 0;
28183+
28184+ return va_align.mask;
28185+}
28186+
28187+unsigned long
28188+arch_get_unmapped_area(struct file *filp, unsigned long addr,
28189+ unsigned long len, unsigned long pgoff, unsigned long flags)
28190+{
28191+ struct mm_struct *mm = current->mm;
28192+ struct vm_area_struct *vma;
28193+ unsigned long pax_task_size = TASK_SIZE;
28194+ struct vm_unmapped_area_info info;
28195+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28196+
28197+#ifdef CONFIG_PAX_SEGMEXEC
28198+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28199+ pax_task_size = SEGMEXEC_TASK_SIZE;
28200+#endif
28201+
28202+ pax_task_size -= PAGE_SIZE;
28203+
28204+ if (len > pax_task_size)
28205+ return -ENOMEM;
28206+
28207+ if (flags & MAP_FIXED)
28208+ return addr;
28209+
28210+#ifdef CONFIG_PAX_RANDMMAP
28211+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28212+#endif
28213+
28214+ if (addr) {
28215+ addr = PAGE_ALIGN(addr);
28216+ if (pax_task_size - len >= addr) {
28217+ vma = find_vma(mm, addr);
28218+ if (check_heap_stack_gap(vma, addr, len, offset))
28219+ return addr;
28220+ }
28221+ }
28222+
28223+ info.flags = 0;
28224+ info.length = len;
28225+ info.align_mask = filp ? get_align_mask() : 0;
28226+ info.align_offset = pgoff << PAGE_SHIFT;
28227+ info.threadstack_offset = offset;
28228+
28229+#ifdef CONFIG_PAX_PAGEEXEC
28230+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
28231+ info.low_limit = 0x00110000UL;
28232+ info.high_limit = mm->start_code;
28233+
28234+#ifdef CONFIG_PAX_RANDMMAP
28235+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28236+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
28237+#endif
28238+
28239+ if (info.low_limit < info.high_limit) {
28240+ addr = vm_unmapped_area(&info);
28241+ if (!IS_ERR_VALUE(addr))
28242+ return addr;
28243+ }
28244+ } else
28245+#endif
28246+
28247+ info.low_limit = mm->mmap_base;
28248+ info.high_limit = pax_task_size;
28249+
28250+ return vm_unmapped_area(&info);
28251+}
28252+
28253+unsigned long
28254+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28255+ const unsigned long len, const unsigned long pgoff,
28256+ const unsigned long flags)
28257+{
28258+ struct vm_area_struct *vma;
28259+ struct mm_struct *mm = current->mm;
28260+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
28261+ struct vm_unmapped_area_info info;
28262+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28263+
28264+#ifdef CONFIG_PAX_SEGMEXEC
28265+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28266+ pax_task_size = SEGMEXEC_TASK_SIZE;
28267+#endif
28268+
28269+ pax_task_size -= PAGE_SIZE;
28270+
28271+ /* requested length too big for entire address space */
28272+ if (len > pax_task_size)
28273+ return -ENOMEM;
28274+
28275+ if (flags & MAP_FIXED)
28276+ return addr;
28277+
28278+#ifdef CONFIG_PAX_PAGEEXEC
28279+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
28280+ goto bottomup;
28281+#endif
28282+
28283+#ifdef CONFIG_PAX_RANDMMAP
28284+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28285+#endif
28286+
28287+ /* requesting a specific address */
28288+ if (addr) {
28289+ addr = PAGE_ALIGN(addr);
28290+ if (pax_task_size - len >= addr) {
28291+ vma = find_vma(mm, addr);
28292+ if (check_heap_stack_gap(vma, addr, len, offset))
28293+ return addr;
28294+ }
28295+ }
28296+
28297+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
28298+ info.length = len;
28299+ info.low_limit = PAGE_SIZE;
28300+ info.high_limit = mm->mmap_base;
28301+ info.align_mask = filp ? get_align_mask() : 0;
28302+ info.align_offset = pgoff << PAGE_SHIFT;
28303+ info.threadstack_offset = offset;
28304+
28305+ addr = vm_unmapped_area(&info);
28306+ if (!(addr & ~PAGE_MASK))
28307+ return addr;
28308+ VM_BUG_ON(addr != -ENOMEM);
28309+
28310+bottomup:
28311+ /*
28312+ * A failed mmap() very likely causes application failure,
28313+ * so fall back to the bottom-up function here. This scenario
28314+ * can happen with large stack limits and large mmap()
28315+ * allocations.
28316+ */
28317+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
28318+}
28319diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
28320index 30277e2..5664a29 100644
28321--- a/arch/x86/kernel/sys_x86_64.c
28322+++ b/arch/x86/kernel/sys_x86_64.c
28323@@ -81,8 +81,8 @@ out:
28324 return error;
28325 }
28326
28327-static void find_start_end(unsigned long flags, unsigned long *begin,
28328- unsigned long *end)
28329+static void find_start_end(struct mm_struct *mm, unsigned long flags,
28330+ unsigned long *begin, unsigned long *end)
28331 {
28332 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
28333 unsigned long new_begin;
28334@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
28335 *begin = new_begin;
28336 }
28337 } else {
28338- *begin = current->mm->mmap_legacy_base;
28339+ *begin = mm->mmap_legacy_base;
28340 *end = TASK_SIZE;
28341 }
28342 }
28343@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
28344 struct vm_area_struct *vma;
28345 struct vm_unmapped_area_info info;
28346 unsigned long begin, end;
28347+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28348
28349 if (flags & MAP_FIXED)
28350 return addr;
28351
28352- find_start_end(flags, &begin, &end);
28353+ find_start_end(mm, flags, &begin, &end);
28354
28355 if (len > end)
28356 return -ENOMEM;
28357
28358+#ifdef CONFIG_PAX_RANDMMAP
28359+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28360+#endif
28361+
28362 if (addr) {
28363 addr = PAGE_ALIGN(addr);
28364 vma = find_vma(mm, addr);
28365- if (end - len >= addr &&
28366- (!vma || addr + len <= vma->vm_start))
28367+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28368 return addr;
28369 }
28370
28371@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
28372 info.high_limit = end;
28373 info.align_mask = filp ? get_align_mask() : 0;
28374 info.align_offset = pgoff << PAGE_SHIFT;
28375+ info.threadstack_offset = offset;
28376 return vm_unmapped_area(&info);
28377 }
28378
28379@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28380 struct mm_struct *mm = current->mm;
28381 unsigned long addr = addr0;
28382 struct vm_unmapped_area_info info;
28383+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
28384
28385 /* requested length too big for entire address space */
28386 if (len > TASK_SIZE)
28387@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28388 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
28389 goto bottomup;
28390
28391+#ifdef CONFIG_PAX_RANDMMAP
28392+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28393+#endif
28394+
28395 /* requesting a specific address */
28396 if (addr) {
28397 addr = PAGE_ALIGN(addr);
28398 vma = find_vma(mm, addr);
28399- if (TASK_SIZE - len >= addr &&
28400- (!vma || addr + len <= vma->vm_start))
28401+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28402 return addr;
28403 }
28404
28405@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
28406 info.high_limit = mm->mmap_base;
28407 info.align_mask = filp ? get_align_mask() : 0;
28408 info.align_offset = pgoff << PAGE_SHIFT;
28409+ info.threadstack_offset = offset;
28410 addr = vm_unmapped_area(&info);
28411 if (!(addr & ~PAGE_MASK))
28412 return addr;
28413diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
28414index 91a4496..bb87552 100644
28415--- a/arch/x86/kernel/tboot.c
28416+++ b/arch/x86/kernel/tboot.c
28417@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
28418
28419 void tboot_shutdown(u32 shutdown_type)
28420 {
28421- void (*shutdown)(void);
28422+ void (* __noreturn shutdown)(void);
28423
28424 if (!tboot_enabled())
28425 return;
28426@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
28427
28428 switch_to_tboot_pt();
28429
28430- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
28431+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
28432 shutdown();
28433
28434 /* should not reach here */
28435@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
28436 return -ENODEV;
28437 }
28438
28439-static atomic_t ap_wfs_count;
28440+static atomic_unchecked_t ap_wfs_count;
28441
28442 static int tboot_wait_for_aps(int num_aps)
28443 {
28444@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
28445 {
28446 switch (action) {
28447 case CPU_DYING:
28448- atomic_inc(&ap_wfs_count);
28449+ atomic_inc_unchecked(&ap_wfs_count);
28450 if (num_online_cpus() == 1)
28451- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
28452+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
28453 return NOTIFY_BAD;
28454 break;
28455 }
28456@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
28457
28458 tboot_create_trampoline();
28459
28460- atomic_set(&ap_wfs_count, 0);
28461+ atomic_set_unchecked(&ap_wfs_count, 0);
28462 register_hotcpu_notifier(&tboot_cpu_notifier);
28463
28464 #ifdef CONFIG_DEBUG_FS
28465diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
28466index 0fa2960..91eabbe 100644
28467--- a/arch/x86/kernel/time.c
28468+++ b/arch/x86/kernel/time.c
28469@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
28470 {
28471 unsigned long pc = instruction_pointer(regs);
28472
28473- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
28474+ if (!user_mode(regs) && in_lock_functions(pc)) {
28475 #ifdef CONFIG_FRAME_POINTER
28476- return *(unsigned long *)(regs->bp + sizeof(long));
28477+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
28478 #else
28479 unsigned long *sp =
28480 (unsigned long *)kernel_stack_pointer(regs);
28481@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
28482 * or above a saved flags. Eflags has bits 22-31 zero,
28483 * kernel addresses don't.
28484 */
28485+
28486+#ifdef CONFIG_PAX_KERNEXEC
28487+ return ktla_ktva(sp[0]);
28488+#else
28489 if (sp[0] >> 22)
28490 return sp[0];
28491 if (sp[1] >> 22)
28492 return sp[1];
28493 #endif
28494+
28495+#endif
28496 }
28497 return pc;
28498 }
28499diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
28500index f7fec09..9991981 100644
28501--- a/arch/x86/kernel/tls.c
28502+++ b/arch/x86/kernel/tls.c
28503@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
28504 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
28505 return -EINVAL;
28506
28507+#ifdef CONFIG_PAX_SEGMEXEC
28508+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
28509+ return -EINVAL;
28510+#endif
28511+
28512 set_tls_desc(p, idx, &info, 1);
28513
28514 return 0;
28515@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
28516
28517 if (kbuf)
28518 info = kbuf;
28519- else if (__copy_from_user(infobuf, ubuf, count))
28520+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
28521 return -EFAULT;
28522 else
28523 info = infobuf;
28524diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
28525index 1c113db..287b42e 100644
28526--- a/arch/x86/kernel/tracepoint.c
28527+++ b/arch/x86/kernel/tracepoint.c
28528@@ -9,11 +9,11 @@
28529 #include <linux/atomic.h>
28530
28531 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
28532-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28533+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
28534 (unsigned long) trace_idt_table };
28535
28536 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28537-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
28538+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
28539
28540 static int trace_irq_vector_refcount;
28541 static DEFINE_MUTEX(irq_vector_mutex);
28542diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
28543index 0d0e922..0886373 100644
28544--- a/arch/x86/kernel/traps.c
28545+++ b/arch/x86/kernel/traps.c
28546@@ -67,7 +67,7 @@
28547 #include <asm/proto.h>
28548
28549 /* No need to be aligned, but done to keep all IDTs defined the same way. */
28550-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
28551+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
28552 #else
28553 #include <asm/processor-flags.h>
28554 #include <asm/setup.h>
28555@@ -76,7 +76,7 @@ asmlinkage int system_call(void);
28556 #endif
28557
28558 /* Must be page-aligned because the real IDT is used in a fixmap. */
28559-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
28560+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
28561
28562 DECLARE_BITMAP(used_vectors, NR_VECTORS);
28563 EXPORT_SYMBOL_GPL(used_vectors);
28564@@ -108,11 +108,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
28565 }
28566
28567 static nokprobe_inline int
28568-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28569+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
28570 struct pt_regs *regs, long error_code)
28571 {
28572 #ifdef CONFIG_X86_32
28573- if (regs->flags & X86_VM_MASK) {
28574+ if (v8086_mode(regs)) {
28575 /*
28576 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
28577 * On nmi (interrupt 2), do_trap should not be called.
28578@@ -125,12 +125,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
28579 return -1;
28580 }
28581 #endif
28582- if (!user_mode(regs)) {
28583+ if (!user_mode_novm(regs)) {
28584 if (!fixup_exception(regs)) {
28585 tsk->thread.error_code = error_code;
28586 tsk->thread.trap_nr = trapnr;
28587+
28588+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28589+ if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
28590+ str = "PAX: suspicious stack segment fault";
28591+#endif
28592+
28593 die(str, regs, error_code);
28594 }
28595+
28596+#ifdef CONFIG_PAX_REFCOUNT
28597+ if (trapnr == X86_TRAP_OF)
28598+ pax_report_refcount_overflow(regs);
28599+#endif
28600+
28601 return 0;
28602 }
28603
28604@@ -169,7 +181,7 @@ static siginfo_t *fill_trap_info(struct pt_regs *regs, int signr, int trapnr,
28605 }
28606
28607 static void
28608-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28609+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
28610 long error_code, siginfo_t *info)
28611 {
28612 struct task_struct *tsk = current;
28613@@ -193,7 +205,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
28614 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
28615 printk_ratelimit()) {
28616 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
28617- tsk->comm, tsk->pid, str,
28618+ tsk->comm, task_pid_nr(tsk), str,
28619 regs->ip, regs->sp, error_code);
28620 print_vma_addr(" in ", regs->ip);
28621 pr_cont("\n");
28622@@ -266,6 +278,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
28623 tsk->thread.error_code = error_code;
28624 tsk->thread.trap_nr = X86_TRAP_DF;
28625
28626+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
28627+ if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
28628+ die("grsec: kernel stack overflow detected", regs, error_code);
28629+#endif
28630+
28631 #ifdef CONFIG_DOUBLEFAULT
28632 df_debug(regs, error_code);
28633 #endif
28634@@ -288,7 +305,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
28635 conditional_sti(regs);
28636
28637 #ifdef CONFIG_X86_32
28638- if (regs->flags & X86_VM_MASK) {
28639+ if (v8086_mode(regs)) {
28640 local_irq_enable();
28641 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
28642 goto exit;
28643@@ -296,18 +313,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
28644 #endif
28645
28646 tsk = current;
28647- if (!user_mode(regs)) {
28648+ if (!user_mode_novm(regs)) {
28649 if (fixup_exception(regs))
28650 goto exit;
28651
28652 tsk->thread.error_code = error_code;
28653 tsk->thread.trap_nr = X86_TRAP_GP;
28654 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
28655- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
28656+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
28657+
28658+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28659+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
28660+ die("PAX: suspicious general protection fault", regs, error_code);
28661+ else
28662+#endif
28663+
28664 die("general protection fault", regs, error_code);
28665+ }
28666 goto exit;
28667 }
28668
28669+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
28670+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
28671+ struct mm_struct *mm = tsk->mm;
28672+ unsigned long limit;
28673+
28674+ down_write(&mm->mmap_sem);
28675+ limit = mm->context.user_cs_limit;
28676+ if (limit < TASK_SIZE) {
28677+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
28678+ up_write(&mm->mmap_sem);
28679+ return;
28680+ }
28681+ up_write(&mm->mmap_sem);
28682+ }
28683+#endif
28684+
28685 tsk->thread.error_code = error_code;
28686 tsk->thread.trap_nr = X86_TRAP_GP;
28687
28688@@ -481,7 +522,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28689 /* It's safe to allow irq's after DR6 has been saved */
28690 preempt_conditional_sti(regs);
28691
28692- if (regs->flags & X86_VM_MASK) {
28693+ if (v8086_mode(regs)) {
28694 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
28695 X86_TRAP_DB);
28696 preempt_conditional_cli(regs);
28697@@ -496,7 +537,7 @@ dotraplinkage void do_debug(struct pt_regs *regs, long error_code)
28698 * We already checked v86 mode above, so we can check for kernel mode
28699 * by just checking the CPL of CS.
28700 */
28701- if ((dr6 & DR_STEP) && !user_mode(regs)) {
28702+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
28703 tsk->thread.debugreg6 &= ~DR_STEP;
28704 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
28705 regs->flags &= ~X86_EFLAGS_TF;
28706@@ -529,7 +570,7 @@ static void math_error(struct pt_regs *regs, int error_code, int trapnr)
28707 return;
28708 conditional_sti(regs);
28709
28710- if (!user_mode_vm(regs))
28711+ if (!user_mode(regs))
28712 {
28713 if (!fixup_exception(regs)) {
28714 task->thread.error_code = error_code;
28715diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
28716index b7e50bb..f4a93ae 100644
28717--- a/arch/x86/kernel/tsc.c
28718+++ b/arch/x86/kernel/tsc.c
28719@@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
28720 */
28721 smp_wmb();
28722
28723- ACCESS_ONCE(c2n->head) = data;
28724+ ACCESS_ONCE_RW(c2n->head) = data;
28725 }
28726
28727 /*
28728diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
28729index 5d1cbfe..2a21feb 100644
28730--- a/arch/x86/kernel/uprobes.c
28731+++ b/arch/x86/kernel/uprobes.c
28732@@ -845,7 +845,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
28733 int ret = NOTIFY_DONE;
28734
28735 /* We are only interested in userspace traps */
28736- if (regs && !user_mode_vm(regs))
28737+ if (regs && !user_mode(regs))
28738 return NOTIFY_DONE;
28739
28740 switch (val) {
28741@@ -919,7 +919,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
28742
28743 if (nleft != rasize) {
28744 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
28745- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
28746+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
28747
28748 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
28749 }
28750diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
28751index b9242ba..50c5edd 100644
28752--- a/arch/x86/kernel/verify_cpu.S
28753+++ b/arch/x86/kernel/verify_cpu.S
28754@@ -20,6 +20,7 @@
28755 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
28756 * arch/x86/kernel/trampoline_64.S: secondary processor verification
28757 * arch/x86/kernel/head_32.S: processor startup
28758+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
28759 *
28760 * verify_cpu, returns the status of longmode and SSE in register %eax.
28761 * 0: Success 1: Failure
28762diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
28763index e8edcf5..27f9344 100644
28764--- a/arch/x86/kernel/vm86_32.c
28765+++ b/arch/x86/kernel/vm86_32.c
28766@@ -44,6 +44,7 @@
28767 #include <linux/ptrace.h>
28768 #include <linux/audit.h>
28769 #include <linux/stddef.h>
28770+#include <linux/grsecurity.h>
28771
28772 #include <asm/uaccess.h>
28773 #include <asm/io.h>
28774@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
28775 do_exit(SIGSEGV);
28776 }
28777
28778- tss = &per_cpu(init_tss, get_cpu());
28779+ tss = init_tss + get_cpu();
28780 current->thread.sp0 = current->thread.saved_sp0;
28781 current->thread.sysenter_cs = __KERNEL_CS;
28782 load_sp0(tss, &current->thread);
28783@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
28784
28785 if (tsk->thread.saved_sp0)
28786 return -EPERM;
28787+
28788+#ifdef CONFIG_GRKERNSEC_VM86
28789+ if (!capable(CAP_SYS_RAWIO)) {
28790+ gr_handle_vm86();
28791+ return -EPERM;
28792+ }
28793+#endif
28794+
28795 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
28796 offsetof(struct kernel_vm86_struct, vm86plus) -
28797 sizeof(info.regs));
28798@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
28799 int tmp;
28800 struct vm86plus_struct __user *v86;
28801
28802+#ifdef CONFIG_GRKERNSEC_VM86
28803+ if (!capable(CAP_SYS_RAWIO)) {
28804+ gr_handle_vm86();
28805+ return -EPERM;
28806+ }
28807+#endif
28808+
28809 tsk = current;
28810 switch (cmd) {
28811 case VM86_REQUEST_IRQ:
28812@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
28813 tsk->thread.saved_fs = info->regs32->fs;
28814 tsk->thread.saved_gs = get_user_gs(info->regs32);
28815
28816- tss = &per_cpu(init_tss, get_cpu());
28817+ tss = init_tss + get_cpu();
28818 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
28819 if (cpu_has_sep)
28820 tsk->thread.sysenter_cs = 0;
28821@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
28822 goto cannot_handle;
28823 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
28824 goto cannot_handle;
28825- intr_ptr = (unsigned long __user *) (i << 2);
28826+ intr_ptr = (__force unsigned long __user *) (i << 2);
28827 if (get_user(segoffs, intr_ptr))
28828 goto cannot_handle;
28829 if ((segoffs >> 16) == BIOSSEG)
28830diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
28831index 49edf2d..c0d1362 100644
28832--- a/arch/x86/kernel/vmlinux.lds.S
28833+++ b/arch/x86/kernel/vmlinux.lds.S
28834@@ -26,6 +26,13 @@
28835 #include <asm/page_types.h>
28836 #include <asm/cache.h>
28837 #include <asm/boot.h>
28838+#include <asm/segment.h>
28839+
28840+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28841+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
28842+#else
28843+#define __KERNEL_TEXT_OFFSET 0
28844+#endif
28845
28846 #undef i386 /* in case the preprocessor is a 32bit one */
28847
28848@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
28849
28850 PHDRS {
28851 text PT_LOAD FLAGS(5); /* R_E */
28852+#ifdef CONFIG_X86_32
28853+ module PT_LOAD FLAGS(5); /* R_E */
28854+#endif
28855+#ifdef CONFIG_XEN
28856+ rodata PT_LOAD FLAGS(5); /* R_E */
28857+#else
28858+ rodata PT_LOAD FLAGS(4); /* R__ */
28859+#endif
28860 data PT_LOAD FLAGS(6); /* RW_ */
28861-#ifdef CONFIG_X86_64
28862+ init.begin PT_LOAD FLAGS(6); /* RW_ */
28863 #ifdef CONFIG_SMP
28864 percpu PT_LOAD FLAGS(6); /* RW_ */
28865 #endif
28866+ text.init PT_LOAD FLAGS(5); /* R_E */
28867+ text.exit PT_LOAD FLAGS(5); /* R_E */
28868 init PT_LOAD FLAGS(7); /* RWE */
28869-#endif
28870 note PT_NOTE FLAGS(0); /* ___ */
28871 }
28872
28873 SECTIONS
28874 {
28875 #ifdef CONFIG_X86_32
28876- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
28877- phys_startup_32 = startup_32 - LOAD_OFFSET;
28878+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
28879 #else
28880- . = __START_KERNEL;
28881- phys_startup_64 = startup_64 - LOAD_OFFSET;
28882+ . = __START_KERNEL;
28883 #endif
28884
28885 /* Text and read-only data */
28886- .text : AT(ADDR(.text) - LOAD_OFFSET) {
28887- _text = .;
28888+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28889 /* bootstrapping code */
28890+#ifdef CONFIG_X86_32
28891+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28892+#else
28893+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28894+#endif
28895+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
28896+ _text = .;
28897 HEAD_TEXT
28898 . = ALIGN(8);
28899 _stext = .;
28900@@ -104,13 +124,47 @@ SECTIONS
28901 IRQENTRY_TEXT
28902 *(.fixup)
28903 *(.gnu.warning)
28904- /* End of text section */
28905- _etext = .;
28906 } :text = 0x9090
28907
28908- NOTES :text :note
28909+ . += __KERNEL_TEXT_OFFSET;
28910
28911- EXCEPTION_TABLE(16) :text = 0x9090
28912+#ifdef CONFIG_X86_32
28913+ . = ALIGN(PAGE_SIZE);
28914+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
28915+
28916+#ifdef CONFIG_PAX_KERNEXEC
28917+ MODULES_EXEC_VADDR = .;
28918+ BYTE(0)
28919+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
28920+ . = ALIGN(HPAGE_SIZE) - 1;
28921+ MODULES_EXEC_END = .;
28922+#endif
28923+
28924+ } :module
28925+#endif
28926+
28927+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
28928+ /* End of text section */
28929+ BYTE(0)
28930+ _etext = . - __KERNEL_TEXT_OFFSET;
28931+ }
28932+
28933+#ifdef CONFIG_X86_32
28934+ . = ALIGN(PAGE_SIZE);
28935+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
28936+ . = ALIGN(PAGE_SIZE);
28937+ *(.empty_zero_page)
28938+ *(.initial_pg_fixmap)
28939+ *(.initial_pg_pmd)
28940+ *(.initial_page_table)
28941+ *(.swapper_pg_dir)
28942+ } :rodata
28943+#endif
28944+
28945+ . = ALIGN(PAGE_SIZE);
28946+ NOTES :rodata :note
28947+
28948+ EXCEPTION_TABLE(16) :rodata
28949
28950 #if defined(CONFIG_DEBUG_RODATA)
28951 /* .text should occupy whole number of pages */
28952@@ -122,16 +176,20 @@ SECTIONS
28953
28954 /* Data */
28955 .data : AT(ADDR(.data) - LOAD_OFFSET) {
28956+
28957+#ifdef CONFIG_PAX_KERNEXEC
28958+ . = ALIGN(HPAGE_SIZE);
28959+#else
28960+ . = ALIGN(PAGE_SIZE);
28961+#endif
28962+
28963 /* Start of data section */
28964 _sdata = .;
28965
28966 /* init_task */
28967 INIT_TASK_DATA(THREAD_SIZE)
28968
28969-#ifdef CONFIG_X86_32
28970- /* 32 bit has nosave before _edata */
28971 NOSAVE_DATA
28972-#endif
28973
28974 PAGE_ALIGNED_DATA(PAGE_SIZE)
28975
28976@@ -174,12 +232,19 @@ SECTIONS
28977 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
28978
28979 /* Init code and data - will be freed after init */
28980- . = ALIGN(PAGE_SIZE);
28981 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
28982+ BYTE(0)
28983+
28984+#ifdef CONFIG_PAX_KERNEXEC
28985+ . = ALIGN(HPAGE_SIZE);
28986+#else
28987+ . = ALIGN(PAGE_SIZE);
28988+#endif
28989+
28990 __init_begin = .; /* paired with __init_end */
28991- }
28992+ } :init.begin
28993
28994-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
28995+#ifdef CONFIG_SMP
28996 /*
28997 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
28998 * output PHDR, so the next output section - .init.text - should
28999@@ -188,12 +253,27 @@ SECTIONS
29000 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
29001 #endif
29002
29003- INIT_TEXT_SECTION(PAGE_SIZE)
29004-#ifdef CONFIG_X86_64
29005- :init
29006-#endif
29007+ . = ALIGN(PAGE_SIZE);
29008+ init_begin = .;
29009+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
29010+ VMLINUX_SYMBOL(_sinittext) = .;
29011+ INIT_TEXT
29012+ VMLINUX_SYMBOL(_einittext) = .;
29013+ . = ALIGN(PAGE_SIZE);
29014+ } :text.init
29015
29016- INIT_DATA_SECTION(16)
29017+ /*
29018+ * .exit.text is discard at runtime, not link time, to deal with
29019+ * references from .altinstructions and .eh_frame
29020+ */
29021+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
29022+ EXIT_TEXT
29023+ . = ALIGN(16);
29024+ } :text.exit
29025+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
29026+
29027+ . = ALIGN(PAGE_SIZE);
29028+ INIT_DATA_SECTION(16) :init
29029
29030 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
29031 __x86_cpu_dev_start = .;
29032@@ -264,19 +344,12 @@ SECTIONS
29033 }
29034
29035 . = ALIGN(8);
29036- /*
29037- * .exit.text is discard at runtime, not link time, to deal with
29038- * references from .altinstructions and .eh_frame
29039- */
29040- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
29041- EXIT_TEXT
29042- }
29043
29044 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
29045 EXIT_DATA
29046 }
29047
29048-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
29049+#ifndef CONFIG_SMP
29050 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
29051 #endif
29052
29053@@ -295,16 +368,10 @@ SECTIONS
29054 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
29055 __smp_locks = .;
29056 *(.smp_locks)
29057- . = ALIGN(PAGE_SIZE);
29058 __smp_locks_end = .;
29059+ . = ALIGN(PAGE_SIZE);
29060 }
29061
29062-#ifdef CONFIG_X86_64
29063- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
29064- NOSAVE_DATA
29065- }
29066-#endif
29067-
29068 /* BSS */
29069 . = ALIGN(PAGE_SIZE);
29070 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
29071@@ -320,6 +387,7 @@ SECTIONS
29072 __brk_base = .;
29073 . += 64 * 1024; /* 64k alignment slop space */
29074 *(.brk_reservation) /* areas brk users have reserved */
29075+ . = ALIGN(HPAGE_SIZE);
29076 __brk_limit = .;
29077 }
29078
29079@@ -346,13 +414,12 @@ SECTIONS
29080 * for the boot processor.
29081 */
29082 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
29083-INIT_PER_CPU(gdt_page);
29084 INIT_PER_CPU(irq_stack_union);
29085
29086 /*
29087 * Build-time check on the image size:
29088 */
29089-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
29090+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
29091 "kernel image bigger than KERNEL_IMAGE_SIZE");
29092
29093 #ifdef CONFIG_SMP
29094diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
29095index e1e1e80..1400089 100644
29096--- a/arch/x86/kernel/vsyscall_64.c
29097+++ b/arch/x86/kernel/vsyscall_64.c
29098@@ -54,15 +54,13 @@
29099
29100 DEFINE_VVAR(int, vgetcpu_mode);
29101
29102-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
29103+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
29104
29105 static int __init vsyscall_setup(char *str)
29106 {
29107 if (str) {
29108 if (!strcmp("emulate", str))
29109 vsyscall_mode = EMULATE;
29110- else if (!strcmp("native", str))
29111- vsyscall_mode = NATIVE;
29112 else if (!strcmp("none", str))
29113 vsyscall_mode = NONE;
29114 else
29115@@ -279,8 +277,7 @@ do_ret:
29116 return true;
29117
29118 sigsegv:
29119- force_sig(SIGSEGV, current);
29120- return true;
29121+ do_group_exit(SIGKILL);
29122 }
29123
29124 /*
29125@@ -331,10 +328,7 @@ void __init map_vsyscall(void)
29126 extern char __vsyscall_page;
29127 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
29128
29129- __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall,
29130- vsyscall_mode == NATIVE
29131- ? PAGE_KERNEL_VSYSCALL
29132- : PAGE_KERNEL_VVAR);
29133+ __set_fixmap(VSYSCALL_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
29134 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_PAGE) !=
29135 (unsigned long)VSYSCALL_ADDR);
29136 }
29137diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
29138index 04068192..4d75aa6 100644
29139--- a/arch/x86/kernel/x8664_ksyms_64.c
29140+++ b/arch/x86/kernel/x8664_ksyms_64.c
29141@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
29142 EXPORT_SYMBOL(copy_user_generic_unrolled);
29143 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
29144 EXPORT_SYMBOL(__copy_user_nocache);
29145-EXPORT_SYMBOL(_copy_from_user);
29146-EXPORT_SYMBOL(_copy_to_user);
29147
29148 EXPORT_SYMBOL(copy_page);
29149 EXPORT_SYMBOL(clear_page);
29150@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
29151 EXPORT_SYMBOL(___preempt_schedule_context);
29152 #endif
29153 #endif
29154+
29155+#ifdef CONFIG_PAX_PER_CPU_PGD
29156+EXPORT_SYMBOL(cpu_pgd);
29157+#endif
29158diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
29159index e48b674..a451dd9 100644
29160--- a/arch/x86/kernel/x86_init.c
29161+++ b/arch/x86/kernel/x86_init.c
29162@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
29163 static void default_nmi_init(void) { };
29164 static int default_i8042_detect(void) { return 1; };
29165
29166-struct x86_platform_ops x86_platform = {
29167+struct x86_platform_ops x86_platform __read_only = {
29168 .calibrate_tsc = native_calibrate_tsc,
29169 .get_wallclock = mach_get_cmos_time,
29170 .set_wallclock = mach_set_rtc_mmss,
29171@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
29172 EXPORT_SYMBOL_GPL(x86_platform);
29173
29174 #if defined(CONFIG_PCI_MSI)
29175-struct x86_msi_ops x86_msi = {
29176+struct x86_msi_ops x86_msi __read_only = {
29177 .setup_msi_irqs = native_setup_msi_irqs,
29178 .compose_msi_msg = native_compose_msi_msg,
29179 .teardown_msi_irq = native_teardown_msi_irq,
29180@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
29181 }
29182 #endif
29183
29184-struct x86_io_apic_ops x86_io_apic_ops = {
29185+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
29186 .init = native_io_apic_init_mappings,
29187 .read = native_io_apic_read,
29188 .write = native_io_apic_write,
29189diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
29190index 4c540c4..0b985b0 100644
29191--- a/arch/x86/kernel/xsave.c
29192+++ b/arch/x86/kernel/xsave.c
29193@@ -167,18 +167,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
29194
29195 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
29196 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
29197- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
29198+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
29199
29200 if (!use_xsave())
29201 return err;
29202
29203- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
29204+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
29205
29206 /*
29207 * Read the xstate_bv which we copied (directly from the cpu or
29208 * from the state in task struct) to the user buffers.
29209 */
29210- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
29211+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
29212
29213 /*
29214 * For legacy compatible, we always set FP/SSE bits in the bit
29215@@ -193,7 +193,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
29216 */
29217 xstate_bv |= XSTATE_FPSSE;
29218
29219- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
29220+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
29221
29222 return err;
29223 }
29224@@ -202,6 +202,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
29225 {
29226 int err;
29227
29228+ buf = (struct xsave_struct __user *)____m(buf);
29229 if (use_xsave())
29230 err = xsave_user(buf);
29231 else if (use_fxsr())
29232@@ -312,6 +313,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
29233 */
29234 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
29235 {
29236+ buf = (void __user *)____m(buf);
29237 if (use_xsave()) {
29238 if ((unsigned long)buf % 64 || fx_only) {
29239 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
29240diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
29241index 38a0afe..94421a9 100644
29242--- a/arch/x86/kvm/cpuid.c
29243+++ b/arch/x86/kvm/cpuid.c
29244@@ -166,15 +166,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
29245 struct kvm_cpuid2 *cpuid,
29246 struct kvm_cpuid_entry2 __user *entries)
29247 {
29248- int r;
29249+ int r, i;
29250
29251 r = -E2BIG;
29252 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
29253 goto out;
29254 r = -EFAULT;
29255- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
29256- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
29257+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
29258 goto out;
29259+ for (i = 0; i < cpuid->nent; ++i) {
29260+ struct kvm_cpuid_entry2 cpuid_entry;
29261+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
29262+ goto out;
29263+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
29264+ }
29265 vcpu->arch.cpuid_nent = cpuid->nent;
29266 kvm_apic_set_version(vcpu);
29267 kvm_x86_ops->cpuid_update(vcpu);
29268@@ -189,15 +194,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
29269 struct kvm_cpuid2 *cpuid,
29270 struct kvm_cpuid_entry2 __user *entries)
29271 {
29272- int r;
29273+ int r, i;
29274
29275 r = -E2BIG;
29276 if (cpuid->nent < vcpu->arch.cpuid_nent)
29277 goto out;
29278 r = -EFAULT;
29279- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
29280- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
29281+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
29282 goto out;
29283+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
29284+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
29285+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
29286+ goto out;
29287+ }
29288 return 0;
29289
29290 out:
29291diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
29292index 08e8a89..0e9183e 100644
29293--- a/arch/x86/kvm/lapic.c
29294+++ b/arch/x86/kvm/lapic.c
29295@@ -55,7 +55,7 @@
29296 #define APIC_BUS_CYCLE_NS 1
29297
29298 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
29299-#define apic_debug(fmt, arg...)
29300+#define apic_debug(fmt, arg...) do {} while (0)
29301
29302 #define APIC_LVT_NUM 6
29303 /* 14 is the version for Xeon and Pentium 8.4.8*/
29304diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
29305index 4107765..d9eb358 100644
29306--- a/arch/x86/kvm/paging_tmpl.h
29307+++ b/arch/x86/kvm/paging_tmpl.h
29308@@ -331,7 +331,7 @@ retry_walk:
29309 if (unlikely(kvm_is_error_hva(host_addr)))
29310 goto error;
29311
29312- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
29313+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
29314 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
29315 goto error;
29316 walker->ptep_user[walker->level - 1] = ptep_user;
29317diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
29318index 78dadc3..fd84599 100644
29319--- a/arch/x86/kvm/svm.c
29320+++ b/arch/x86/kvm/svm.c
29321@@ -3547,7 +3547,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
29322 int cpu = raw_smp_processor_id();
29323
29324 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
29325+
29326+ pax_open_kernel();
29327 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
29328+ pax_close_kernel();
29329+
29330 load_TR_desc();
29331 }
29332
29333@@ -3948,6 +3952,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
29334 #endif
29335 #endif
29336
29337+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29338+ __set_fs(current_thread_info()->addr_limit);
29339+#endif
29340+
29341 reload_tss(vcpu);
29342
29343 local_irq_disable();
29344diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
29345index 41a5426..c0b3c00 100644
29346--- a/arch/x86/kvm/vmx.c
29347+++ b/arch/x86/kvm/vmx.c
29348@@ -1341,12 +1341,12 @@ static void vmcs_write64(unsigned long field, u64 value)
29349 #endif
29350 }
29351
29352-static void vmcs_clear_bits(unsigned long field, u32 mask)
29353+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
29354 {
29355 vmcs_writel(field, vmcs_readl(field) & ~mask);
29356 }
29357
29358-static void vmcs_set_bits(unsigned long field, u32 mask)
29359+static void vmcs_set_bits(unsigned long field, unsigned long mask)
29360 {
29361 vmcs_writel(field, vmcs_readl(field) | mask);
29362 }
29363@@ -1606,7 +1606,11 @@ static void reload_tss(void)
29364 struct desc_struct *descs;
29365
29366 descs = (void *)gdt->address;
29367+
29368+ pax_open_kernel();
29369 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
29370+ pax_close_kernel();
29371+
29372 load_TR_desc();
29373 }
29374
29375@@ -1834,6 +1838,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
29376 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
29377 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
29378
29379+#ifdef CONFIG_PAX_PER_CPU_PGD
29380+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
29381+#endif
29382+
29383 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
29384 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
29385 vmx->loaded_vmcs->cpu = cpu;
29386@@ -2123,7 +2131,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
29387 * reads and returns guest's timestamp counter "register"
29388 * guest_tsc = host_tsc + tsc_offset -- 21.3
29389 */
29390-static u64 guest_read_tsc(void)
29391+static u64 __intentional_overflow(-1) guest_read_tsc(void)
29392 {
29393 u64 host_tsc, tsc_offset;
29394
29395@@ -3114,8 +3122,11 @@ static __init int hardware_setup(void)
29396 if (!cpu_has_vmx_flexpriority())
29397 flexpriority_enabled = 0;
29398
29399- if (!cpu_has_vmx_tpr_shadow())
29400- kvm_x86_ops->update_cr8_intercept = NULL;
29401+ if (!cpu_has_vmx_tpr_shadow()) {
29402+ pax_open_kernel();
29403+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
29404+ pax_close_kernel();
29405+ }
29406
29407 if (enable_ept && !cpu_has_vmx_ept_2m_page())
29408 kvm_disable_largepages();
29409@@ -3126,13 +3137,15 @@ static __init int hardware_setup(void)
29410 if (!cpu_has_vmx_apicv())
29411 enable_apicv = 0;
29412
29413+ pax_open_kernel();
29414 if (enable_apicv)
29415- kvm_x86_ops->update_cr8_intercept = NULL;
29416+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
29417 else {
29418- kvm_x86_ops->hwapic_irr_update = NULL;
29419- kvm_x86_ops->deliver_posted_interrupt = NULL;
29420- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
29421+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
29422+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
29423+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
29424 }
29425+ pax_close_kernel();
29426
29427 if (nested)
29428 nested_vmx_setup_ctls_msrs();
29429@@ -4242,7 +4255,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
29430 unsigned long cr4;
29431
29432 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
29433+
29434+#ifndef CONFIG_PAX_PER_CPU_PGD
29435 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
29436+#endif
29437
29438 /* Save the most likely value for this task's CR4 in the VMCS. */
29439 cr4 = read_cr4();
29440@@ -4269,7 +4285,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
29441 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
29442 vmx->host_idt_base = dt.address;
29443
29444- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
29445+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
29446
29447 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
29448 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
29449@@ -7475,6 +7491,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29450 "jmp 2f \n\t"
29451 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
29452 "2: "
29453+
29454+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29455+ "ljmp %[cs],$3f\n\t"
29456+ "3: "
29457+#endif
29458+
29459 /* Save guest registers, load host registers, keep flags */
29460 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
29461 "pop %0 \n\t"
29462@@ -7527,6 +7549,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29463 #endif
29464 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
29465 [wordsize]"i"(sizeof(ulong))
29466+
29467+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
29468+ ,[cs]"i"(__KERNEL_CS)
29469+#endif
29470+
29471 : "cc", "memory"
29472 #ifdef CONFIG_X86_64
29473 , "rax", "rbx", "rdi", "rsi"
29474@@ -7540,7 +7567,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29475 if (debugctlmsr)
29476 update_debugctlmsr(debugctlmsr);
29477
29478-#ifndef CONFIG_X86_64
29479+#ifdef CONFIG_X86_32
29480 /*
29481 * The sysexit path does not restore ds/es, so we must set them to
29482 * a reasonable value ourselves.
29483@@ -7549,8 +7576,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
29484 * may be executed in interrupt context, which saves and restore segments
29485 * around it, nullifying its effect.
29486 */
29487- loadsegment(ds, __USER_DS);
29488- loadsegment(es, __USER_DS);
29489+ loadsegment(ds, __KERNEL_DS);
29490+ loadsegment(es, __KERNEL_DS);
29491+ loadsegment(ss, __KERNEL_DS);
29492+
29493+#ifdef CONFIG_PAX_KERNEXEC
29494+ loadsegment(fs, __KERNEL_PERCPU);
29495+#endif
29496+
29497+#ifdef CONFIG_PAX_MEMORY_UDEREF
29498+ __set_fs(current_thread_info()->addr_limit);
29499+#endif
29500+
29501 #endif
29502
29503 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
29504diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
29505index 9d292e8..cea125a 100644
29506--- a/arch/x86/kvm/x86.c
29507+++ b/arch/x86/kvm/x86.c
29508@@ -1857,8 +1857,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
29509 {
29510 struct kvm *kvm = vcpu->kvm;
29511 int lm = is_long_mode(vcpu);
29512- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29513- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29514+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
29515+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
29516 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
29517 : kvm->arch.xen_hvm_config.blob_size_32;
29518 u32 page_num = data & ~PAGE_MASK;
29519@@ -2779,6 +2779,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
29520 if (n < msr_list.nmsrs)
29521 goto out;
29522 r = -EFAULT;
29523+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
29524+ goto out;
29525 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
29526 num_msrs_to_save * sizeof(u32)))
29527 goto out;
29528@@ -5002,7 +5004,7 @@ static int handle_emulation_failure(struct kvm_vcpu *vcpu)
29529
29530 ++vcpu->stat.insn_emulation_fail;
29531 trace_kvm_emulate_insn_failed(vcpu);
29532- if (!is_guest_mode(vcpu)) {
29533+ if (!is_guest_mode(vcpu) && kvm_x86_ops->get_cpl(vcpu) == 0) {
29534 vcpu->run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
29535 vcpu->run->internal.suberror = KVM_INTERNAL_ERROR_EMULATION;
29536 vcpu->run->internal.ndata = 0;
29537@@ -5639,7 +5641,7 @@ static struct notifier_block pvclock_gtod_notifier = {
29538 };
29539 #endif
29540
29541-int kvm_arch_init(void *opaque)
29542+int kvm_arch_init(const void *opaque)
29543 {
29544 int r;
29545 struct kvm_x86_ops *ops = opaque;
29546diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
29547index aae9413..d11e829 100644
29548--- a/arch/x86/lguest/boot.c
29549+++ b/arch/x86/lguest/boot.c
29550@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
29551 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
29552 * Launcher to reboot us.
29553 */
29554-static void lguest_restart(char *reason)
29555+static __noreturn void lguest_restart(char *reason)
29556 {
29557 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
29558+ BUG();
29559 }
29560
29561 /*G:050
29562diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
29563index 00933d5..3a64af9 100644
29564--- a/arch/x86/lib/atomic64_386_32.S
29565+++ b/arch/x86/lib/atomic64_386_32.S
29566@@ -48,6 +48,10 @@ BEGIN(read)
29567 movl (v), %eax
29568 movl 4(v), %edx
29569 RET_ENDP
29570+BEGIN(read_unchecked)
29571+ movl (v), %eax
29572+ movl 4(v), %edx
29573+RET_ENDP
29574 #undef v
29575
29576 #define v %esi
29577@@ -55,6 +59,10 @@ BEGIN(set)
29578 movl %ebx, (v)
29579 movl %ecx, 4(v)
29580 RET_ENDP
29581+BEGIN(set_unchecked)
29582+ movl %ebx, (v)
29583+ movl %ecx, 4(v)
29584+RET_ENDP
29585 #undef v
29586
29587 #define v %esi
29588@@ -70,6 +78,20 @@ RET_ENDP
29589 BEGIN(add)
29590 addl %eax, (v)
29591 adcl %edx, 4(v)
29592+
29593+#ifdef CONFIG_PAX_REFCOUNT
29594+ jno 0f
29595+ subl %eax, (v)
29596+ sbbl %edx, 4(v)
29597+ int $4
29598+0:
29599+ _ASM_EXTABLE(0b, 0b)
29600+#endif
29601+
29602+RET_ENDP
29603+BEGIN(add_unchecked)
29604+ addl %eax, (v)
29605+ adcl %edx, 4(v)
29606 RET_ENDP
29607 #undef v
29608
29609@@ -77,6 +99,24 @@ RET_ENDP
29610 BEGIN(add_return)
29611 addl (v), %eax
29612 adcl 4(v), %edx
29613+
29614+#ifdef CONFIG_PAX_REFCOUNT
29615+ into
29616+1234:
29617+ _ASM_EXTABLE(1234b, 2f)
29618+#endif
29619+
29620+ movl %eax, (v)
29621+ movl %edx, 4(v)
29622+
29623+#ifdef CONFIG_PAX_REFCOUNT
29624+2:
29625+#endif
29626+
29627+RET_ENDP
29628+BEGIN(add_return_unchecked)
29629+ addl (v), %eax
29630+ adcl 4(v), %edx
29631 movl %eax, (v)
29632 movl %edx, 4(v)
29633 RET_ENDP
29634@@ -86,6 +126,20 @@ RET_ENDP
29635 BEGIN(sub)
29636 subl %eax, (v)
29637 sbbl %edx, 4(v)
29638+
29639+#ifdef CONFIG_PAX_REFCOUNT
29640+ jno 0f
29641+ addl %eax, (v)
29642+ adcl %edx, 4(v)
29643+ int $4
29644+0:
29645+ _ASM_EXTABLE(0b, 0b)
29646+#endif
29647+
29648+RET_ENDP
29649+BEGIN(sub_unchecked)
29650+ subl %eax, (v)
29651+ sbbl %edx, 4(v)
29652 RET_ENDP
29653 #undef v
29654
29655@@ -96,6 +150,27 @@ BEGIN(sub_return)
29656 sbbl $0, %edx
29657 addl (v), %eax
29658 adcl 4(v), %edx
29659+
29660+#ifdef CONFIG_PAX_REFCOUNT
29661+ into
29662+1234:
29663+ _ASM_EXTABLE(1234b, 2f)
29664+#endif
29665+
29666+ movl %eax, (v)
29667+ movl %edx, 4(v)
29668+
29669+#ifdef CONFIG_PAX_REFCOUNT
29670+2:
29671+#endif
29672+
29673+RET_ENDP
29674+BEGIN(sub_return_unchecked)
29675+ negl %edx
29676+ negl %eax
29677+ sbbl $0, %edx
29678+ addl (v), %eax
29679+ adcl 4(v), %edx
29680 movl %eax, (v)
29681 movl %edx, 4(v)
29682 RET_ENDP
29683@@ -105,6 +180,20 @@ RET_ENDP
29684 BEGIN(inc)
29685 addl $1, (v)
29686 adcl $0, 4(v)
29687+
29688+#ifdef CONFIG_PAX_REFCOUNT
29689+ jno 0f
29690+ subl $1, (v)
29691+ sbbl $0, 4(v)
29692+ int $4
29693+0:
29694+ _ASM_EXTABLE(0b, 0b)
29695+#endif
29696+
29697+RET_ENDP
29698+BEGIN(inc_unchecked)
29699+ addl $1, (v)
29700+ adcl $0, 4(v)
29701 RET_ENDP
29702 #undef v
29703
29704@@ -114,6 +203,26 @@ BEGIN(inc_return)
29705 movl 4(v), %edx
29706 addl $1, %eax
29707 adcl $0, %edx
29708+
29709+#ifdef CONFIG_PAX_REFCOUNT
29710+ into
29711+1234:
29712+ _ASM_EXTABLE(1234b, 2f)
29713+#endif
29714+
29715+ movl %eax, (v)
29716+ movl %edx, 4(v)
29717+
29718+#ifdef CONFIG_PAX_REFCOUNT
29719+2:
29720+#endif
29721+
29722+RET_ENDP
29723+BEGIN(inc_return_unchecked)
29724+ movl (v), %eax
29725+ movl 4(v), %edx
29726+ addl $1, %eax
29727+ adcl $0, %edx
29728 movl %eax, (v)
29729 movl %edx, 4(v)
29730 RET_ENDP
29731@@ -123,6 +232,20 @@ RET_ENDP
29732 BEGIN(dec)
29733 subl $1, (v)
29734 sbbl $0, 4(v)
29735+
29736+#ifdef CONFIG_PAX_REFCOUNT
29737+ jno 0f
29738+ addl $1, (v)
29739+ adcl $0, 4(v)
29740+ int $4
29741+0:
29742+ _ASM_EXTABLE(0b, 0b)
29743+#endif
29744+
29745+RET_ENDP
29746+BEGIN(dec_unchecked)
29747+ subl $1, (v)
29748+ sbbl $0, 4(v)
29749 RET_ENDP
29750 #undef v
29751
29752@@ -132,6 +255,26 @@ BEGIN(dec_return)
29753 movl 4(v), %edx
29754 subl $1, %eax
29755 sbbl $0, %edx
29756+
29757+#ifdef CONFIG_PAX_REFCOUNT
29758+ into
29759+1234:
29760+ _ASM_EXTABLE(1234b, 2f)
29761+#endif
29762+
29763+ movl %eax, (v)
29764+ movl %edx, 4(v)
29765+
29766+#ifdef CONFIG_PAX_REFCOUNT
29767+2:
29768+#endif
29769+
29770+RET_ENDP
29771+BEGIN(dec_return_unchecked)
29772+ movl (v), %eax
29773+ movl 4(v), %edx
29774+ subl $1, %eax
29775+ sbbl $0, %edx
29776 movl %eax, (v)
29777 movl %edx, 4(v)
29778 RET_ENDP
29779@@ -143,6 +286,13 @@ BEGIN(add_unless)
29780 adcl %edx, %edi
29781 addl (v), %eax
29782 adcl 4(v), %edx
29783+
29784+#ifdef CONFIG_PAX_REFCOUNT
29785+ into
29786+1234:
29787+ _ASM_EXTABLE(1234b, 2f)
29788+#endif
29789+
29790 cmpl %eax, %ecx
29791 je 3f
29792 1:
29793@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
29794 1:
29795 addl $1, %eax
29796 adcl $0, %edx
29797+
29798+#ifdef CONFIG_PAX_REFCOUNT
29799+ into
29800+1234:
29801+ _ASM_EXTABLE(1234b, 2f)
29802+#endif
29803+
29804 movl %eax, (v)
29805 movl %edx, 4(v)
29806 movl $1, %eax
29807@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
29808 movl 4(v), %edx
29809 subl $1, %eax
29810 sbbl $0, %edx
29811+
29812+#ifdef CONFIG_PAX_REFCOUNT
29813+ into
29814+1234:
29815+ _ASM_EXTABLE(1234b, 1f)
29816+#endif
29817+
29818 js 1f
29819 movl %eax, (v)
29820 movl %edx, 4(v)
29821diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
29822index f5cc9eb..51fa319 100644
29823--- a/arch/x86/lib/atomic64_cx8_32.S
29824+++ b/arch/x86/lib/atomic64_cx8_32.S
29825@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
29826 CFI_STARTPROC
29827
29828 read64 %ecx
29829+ pax_force_retaddr
29830 ret
29831 CFI_ENDPROC
29832 ENDPROC(atomic64_read_cx8)
29833
29834+ENTRY(atomic64_read_unchecked_cx8)
29835+ CFI_STARTPROC
29836+
29837+ read64 %ecx
29838+ pax_force_retaddr
29839+ ret
29840+ CFI_ENDPROC
29841+ENDPROC(atomic64_read_unchecked_cx8)
29842+
29843 ENTRY(atomic64_set_cx8)
29844 CFI_STARTPROC
29845
29846@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
29847 cmpxchg8b (%esi)
29848 jne 1b
29849
29850+ pax_force_retaddr
29851 ret
29852 CFI_ENDPROC
29853 ENDPROC(atomic64_set_cx8)
29854
29855+ENTRY(atomic64_set_unchecked_cx8)
29856+ CFI_STARTPROC
29857+
29858+1:
29859+/* we don't need LOCK_PREFIX since aligned 64-bit writes
29860+ * are atomic on 586 and newer */
29861+ cmpxchg8b (%esi)
29862+ jne 1b
29863+
29864+ pax_force_retaddr
29865+ ret
29866+ CFI_ENDPROC
29867+ENDPROC(atomic64_set_unchecked_cx8)
29868+
29869 ENTRY(atomic64_xchg_cx8)
29870 CFI_STARTPROC
29871
29872@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
29873 cmpxchg8b (%esi)
29874 jne 1b
29875
29876+ pax_force_retaddr
29877 ret
29878 CFI_ENDPROC
29879 ENDPROC(atomic64_xchg_cx8)
29880
29881-.macro addsub_return func ins insc
29882-ENTRY(atomic64_\func\()_return_cx8)
29883+.macro addsub_return func ins insc unchecked=""
29884+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29885 CFI_STARTPROC
29886 SAVE ebp
29887 SAVE ebx
29888@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
29889 movl %edx, %ecx
29890 \ins\()l %esi, %ebx
29891 \insc\()l %edi, %ecx
29892+
29893+.ifb \unchecked
29894+#ifdef CONFIG_PAX_REFCOUNT
29895+ into
29896+2:
29897+ _ASM_EXTABLE(2b, 3f)
29898+#endif
29899+.endif
29900+
29901 LOCK_PREFIX
29902 cmpxchg8b (%ebp)
29903 jne 1b
29904-
29905-10:
29906 movl %ebx, %eax
29907 movl %ecx, %edx
29908+
29909+.ifb \unchecked
29910+#ifdef CONFIG_PAX_REFCOUNT
29911+3:
29912+#endif
29913+.endif
29914+
29915 RESTORE edi
29916 RESTORE esi
29917 RESTORE ebx
29918 RESTORE ebp
29919+ pax_force_retaddr
29920 ret
29921 CFI_ENDPROC
29922-ENDPROC(atomic64_\func\()_return_cx8)
29923+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29924 .endm
29925
29926 addsub_return add add adc
29927 addsub_return sub sub sbb
29928+addsub_return add add adc _unchecked
29929+addsub_return sub sub sbb _unchecked
29930
29931-.macro incdec_return func ins insc
29932-ENTRY(atomic64_\func\()_return_cx8)
29933+.macro incdec_return func ins insc unchecked=""
29934+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
29935 CFI_STARTPROC
29936 SAVE ebx
29937
29938@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
29939 movl %edx, %ecx
29940 \ins\()l $1, %ebx
29941 \insc\()l $0, %ecx
29942+
29943+.ifb \unchecked
29944+#ifdef CONFIG_PAX_REFCOUNT
29945+ into
29946+2:
29947+ _ASM_EXTABLE(2b, 3f)
29948+#endif
29949+.endif
29950+
29951 LOCK_PREFIX
29952 cmpxchg8b (%esi)
29953 jne 1b
29954
29955-10:
29956 movl %ebx, %eax
29957 movl %ecx, %edx
29958+
29959+.ifb \unchecked
29960+#ifdef CONFIG_PAX_REFCOUNT
29961+3:
29962+#endif
29963+.endif
29964+
29965 RESTORE ebx
29966+ pax_force_retaddr
29967 ret
29968 CFI_ENDPROC
29969-ENDPROC(atomic64_\func\()_return_cx8)
29970+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
29971 .endm
29972
29973 incdec_return inc add adc
29974 incdec_return dec sub sbb
29975+incdec_return inc add adc _unchecked
29976+incdec_return dec sub sbb _unchecked
29977
29978 ENTRY(atomic64_dec_if_positive_cx8)
29979 CFI_STARTPROC
29980@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
29981 movl %edx, %ecx
29982 subl $1, %ebx
29983 sbb $0, %ecx
29984+
29985+#ifdef CONFIG_PAX_REFCOUNT
29986+ into
29987+1234:
29988+ _ASM_EXTABLE(1234b, 2f)
29989+#endif
29990+
29991 js 2f
29992 LOCK_PREFIX
29993 cmpxchg8b (%esi)
29994@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
29995 movl %ebx, %eax
29996 movl %ecx, %edx
29997 RESTORE ebx
29998+ pax_force_retaddr
29999 ret
30000 CFI_ENDPROC
30001 ENDPROC(atomic64_dec_if_positive_cx8)
30002@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
30003 movl %edx, %ecx
30004 addl %ebp, %ebx
30005 adcl %edi, %ecx
30006+
30007+#ifdef CONFIG_PAX_REFCOUNT
30008+ into
30009+1234:
30010+ _ASM_EXTABLE(1234b, 3f)
30011+#endif
30012+
30013 LOCK_PREFIX
30014 cmpxchg8b (%esi)
30015 jne 1b
30016@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
30017 CFI_ADJUST_CFA_OFFSET -8
30018 RESTORE ebx
30019 RESTORE ebp
30020+ pax_force_retaddr
30021 ret
30022 4:
30023 cmpl %edx, 4(%esp)
30024@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
30025 xorl %ecx, %ecx
30026 addl $1, %ebx
30027 adcl %edx, %ecx
30028+
30029+#ifdef CONFIG_PAX_REFCOUNT
30030+ into
30031+1234:
30032+ _ASM_EXTABLE(1234b, 3f)
30033+#endif
30034+
30035 LOCK_PREFIX
30036 cmpxchg8b (%esi)
30037 jne 1b
30038@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
30039 movl $1, %eax
30040 3:
30041 RESTORE ebx
30042+ pax_force_retaddr
30043 ret
30044 CFI_ENDPROC
30045 ENDPROC(atomic64_inc_not_zero_cx8)
30046diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
30047index e78b8eee..7e173a8 100644
30048--- a/arch/x86/lib/checksum_32.S
30049+++ b/arch/x86/lib/checksum_32.S
30050@@ -29,7 +29,8 @@
30051 #include <asm/dwarf2.h>
30052 #include <asm/errno.h>
30053 #include <asm/asm.h>
30054-
30055+#include <asm/segment.h>
30056+
30057 /*
30058 * computes a partial checksum, e.g. for TCP/UDP fragments
30059 */
30060@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
30061
30062 #define ARGBASE 16
30063 #define FP 12
30064-
30065-ENTRY(csum_partial_copy_generic)
30066+
30067+ENTRY(csum_partial_copy_generic_to_user)
30068 CFI_STARTPROC
30069+
30070+#ifdef CONFIG_PAX_MEMORY_UDEREF
30071+ pushl_cfi %gs
30072+ popl_cfi %es
30073+ jmp csum_partial_copy_generic
30074+#endif
30075+
30076+ENTRY(csum_partial_copy_generic_from_user)
30077+
30078+#ifdef CONFIG_PAX_MEMORY_UDEREF
30079+ pushl_cfi %gs
30080+ popl_cfi %ds
30081+#endif
30082+
30083+ENTRY(csum_partial_copy_generic)
30084 subl $4,%esp
30085 CFI_ADJUST_CFA_OFFSET 4
30086 pushl_cfi %edi
30087@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
30088 jmp 4f
30089 SRC(1: movw (%esi), %bx )
30090 addl $2, %esi
30091-DST( movw %bx, (%edi) )
30092+DST( movw %bx, %es:(%edi) )
30093 addl $2, %edi
30094 addw %bx, %ax
30095 adcl $0, %eax
30096@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
30097 SRC(1: movl (%esi), %ebx )
30098 SRC( movl 4(%esi), %edx )
30099 adcl %ebx, %eax
30100-DST( movl %ebx, (%edi) )
30101+DST( movl %ebx, %es:(%edi) )
30102 adcl %edx, %eax
30103-DST( movl %edx, 4(%edi) )
30104+DST( movl %edx, %es:4(%edi) )
30105
30106 SRC( movl 8(%esi), %ebx )
30107 SRC( movl 12(%esi), %edx )
30108 adcl %ebx, %eax
30109-DST( movl %ebx, 8(%edi) )
30110+DST( movl %ebx, %es:8(%edi) )
30111 adcl %edx, %eax
30112-DST( movl %edx, 12(%edi) )
30113+DST( movl %edx, %es:12(%edi) )
30114
30115 SRC( movl 16(%esi), %ebx )
30116 SRC( movl 20(%esi), %edx )
30117 adcl %ebx, %eax
30118-DST( movl %ebx, 16(%edi) )
30119+DST( movl %ebx, %es:16(%edi) )
30120 adcl %edx, %eax
30121-DST( movl %edx, 20(%edi) )
30122+DST( movl %edx, %es:20(%edi) )
30123
30124 SRC( movl 24(%esi), %ebx )
30125 SRC( movl 28(%esi), %edx )
30126 adcl %ebx, %eax
30127-DST( movl %ebx, 24(%edi) )
30128+DST( movl %ebx, %es:24(%edi) )
30129 adcl %edx, %eax
30130-DST( movl %edx, 28(%edi) )
30131+DST( movl %edx, %es:28(%edi) )
30132
30133 lea 32(%esi), %esi
30134 lea 32(%edi), %edi
30135@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
30136 shrl $2, %edx # This clears CF
30137 SRC(3: movl (%esi), %ebx )
30138 adcl %ebx, %eax
30139-DST( movl %ebx, (%edi) )
30140+DST( movl %ebx, %es:(%edi) )
30141 lea 4(%esi), %esi
30142 lea 4(%edi), %edi
30143 dec %edx
30144@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
30145 jb 5f
30146 SRC( movw (%esi), %cx )
30147 leal 2(%esi), %esi
30148-DST( movw %cx, (%edi) )
30149+DST( movw %cx, %es:(%edi) )
30150 leal 2(%edi), %edi
30151 je 6f
30152 shll $16,%ecx
30153 SRC(5: movb (%esi), %cl )
30154-DST( movb %cl, (%edi) )
30155+DST( movb %cl, %es:(%edi) )
30156 6: addl %ecx, %eax
30157 adcl $0, %eax
30158 7:
30159@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
30160
30161 6001:
30162 movl ARGBASE+20(%esp), %ebx # src_err_ptr
30163- movl $-EFAULT, (%ebx)
30164+ movl $-EFAULT, %ss:(%ebx)
30165
30166 # zero the complete destination - computing the rest
30167 # is too much work
30168@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
30169
30170 6002:
30171 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
30172- movl $-EFAULT,(%ebx)
30173+ movl $-EFAULT,%ss:(%ebx)
30174 jmp 5000b
30175
30176 .previous
30177
30178+ pushl_cfi %ss
30179+ popl_cfi %ds
30180+ pushl_cfi %ss
30181+ popl_cfi %es
30182 popl_cfi %ebx
30183 CFI_RESTORE ebx
30184 popl_cfi %esi
30185@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
30186 popl_cfi %ecx # equivalent to addl $4,%esp
30187 ret
30188 CFI_ENDPROC
30189-ENDPROC(csum_partial_copy_generic)
30190+ENDPROC(csum_partial_copy_generic_to_user)
30191
30192 #else
30193
30194 /* Version for PentiumII/PPro */
30195
30196 #define ROUND1(x) \
30197+ nop; nop; nop; \
30198 SRC(movl x(%esi), %ebx ) ; \
30199 addl %ebx, %eax ; \
30200- DST(movl %ebx, x(%edi) ) ;
30201+ DST(movl %ebx, %es:x(%edi)) ;
30202
30203 #define ROUND(x) \
30204+ nop; nop; nop; \
30205 SRC(movl x(%esi), %ebx ) ; \
30206 adcl %ebx, %eax ; \
30207- DST(movl %ebx, x(%edi) ) ;
30208+ DST(movl %ebx, %es:x(%edi)) ;
30209
30210 #define ARGBASE 12
30211-
30212-ENTRY(csum_partial_copy_generic)
30213+
30214+ENTRY(csum_partial_copy_generic_to_user)
30215 CFI_STARTPROC
30216+
30217+#ifdef CONFIG_PAX_MEMORY_UDEREF
30218+ pushl_cfi %gs
30219+ popl_cfi %es
30220+ jmp csum_partial_copy_generic
30221+#endif
30222+
30223+ENTRY(csum_partial_copy_generic_from_user)
30224+
30225+#ifdef CONFIG_PAX_MEMORY_UDEREF
30226+ pushl_cfi %gs
30227+ popl_cfi %ds
30228+#endif
30229+
30230+ENTRY(csum_partial_copy_generic)
30231 pushl_cfi %ebx
30232 CFI_REL_OFFSET ebx, 0
30233 pushl_cfi %edi
30234@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
30235 subl %ebx, %edi
30236 lea -1(%esi),%edx
30237 andl $-32,%edx
30238- lea 3f(%ebx,%ebx), %ebx
30239+ lea 3f(%ebx,%ebx,2), %ebx
30240 testl %esi, %esi
30241 jmp *%ebx
30242 1: addl $64,%esi
30243@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
30244 jb 5f
30245 SRC( movw (%esi), %dx )
30246 leal 2(%esi), %esi
30247-DST( movw %dx, (%edi) )
30248+DST( movw %dx, %es:(%edi) )
30249 leal 2(%edi), %edi
30250 je 6f
30251 shll $16,%edx
30252 5:
30253 SRC( movb (%esi), %dl )
30254-DST( movb %dl, (%edi) )
30255+DST( movb %dl, %es:(%edi) )
30256 6: addl %edx, %eax
30257 adcl $0, %eax
30258 7:
30259 .section .fixup, "ax"
30260 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
30261- movl $-EFAULT, (%ebx)
30262+ movl $-EFAULT, %ss:(%ebx)
30263 # zero the complete destination (computing the rest is too much work)
30264 movl ARGBASE+8(%esp),%edi # dst
30265 movl ARGBASE+12(%esp),%ecx # len
30266@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
30267 rep; stosb
30268 jmp 7b
30269 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
30270- movl $-EFAULT, (%ebx)
30271+ movl $-EFAULT, %ss:(%ebx)
30272 jmp 7b
30273 .previous
30274
30275+#ifdef CONFIG_PAX_MEMORY_UDEREF
30276+ pushl_cfi %ss
30277+ popl_cfi %ds
30278+ pushl_cfi %ss
30279+ popl_cfi %es
30280+#endif
30281+
30282 popl_cfi %esi
30283 CFI_RESTORE esi
30284 popl_cfi %edi
30285@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
30286 CFI_RESTORE ebx
30287 ret
30288 CFI_ENDPROC
30289-ENDPROC(csum_partial_copy_generic)
30290+ENDPROC(csum_partial_copy_generic_to_user)
30291
30292 #undef ROUND
30293 #undef ROUND1
30294diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
30295index f2145cf..cea889d 100644
30296--- a/arch/x86/lib/clear_page_64.S
30297+++ b/arch/x86/lib/clear_page_64.S
30298@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
30299 movl $4096/8,%ecx
30300 xorl %eax,%eax
30301 rep stosq
30302+ pax_force_retaddr
30303 ret
30304 CFI_ENDPROC
30305 ENDPROC(clear_page_c)
30306@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
30307 movl $4096,%ecx
30308 xorl %eax,%eax
30309 rep stosb
30310+ pax_force_retaddr
30311 ret
30312 CFI_ENDPROC
30313 ENDPROC(clear_page_c_e)
30314@@ -43,6 +45,7 @@ ENTRY(clear_page)
30315 leaq 64(%rdi),%rdi
30316 jnz .Lloop
30317 nop
30318+ pax_force_retaddr
30319 ret
30320 CFI_ENDPROC
30321 .Lclear_page_end:
30322@@ -58,7 +61,7 @@ ENDPROC(clear_page)
30323
30324 #include <asm/cpufeature.h>
30325
30326- .section .altinstr_replacement,"ax"
30327+ .section .altinstr_replacement,"a"
30328 1: .byte 0xeb /* jmp <disp8> */
30329 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
30330 2: .byte 0xeb /* jmp <disp8> */
30331diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
30332index 1e572c5..2a162cd 100644
30333--- a/arch/x86/lib/cmpxchg16b_emu.S
30334+++ b/arch/x86/lib/cmpxchg16b_emu.S
30335@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
30336
30337 popf
30338 mov $1, %al
30339+ pax_force_retaddr
30340 ret
30341
30342 not_same:
30343 popf
30344 xor %al,%al
30345+ pax_force_retaddr
30346 ret
30347
30348 CFI_ENDPROC
30349diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
30350index 176cca6..e0d658e 100644
30351--- a/arch/x86/lib/copy_page_64.S
30352+++ b/arch/x86/lib/copy_page_64.S
30353@@ -9,6 +9,7 @@ copy_page_rep:
30354 CFI_STARTPROC
30355 movl $4096/8, %ecx
30356 rep movsq
30357+ pax_force_retaddr
30358 ret
30359 CFI_ENDPROC
30360 ENDPROC(copy_page_rep)
30361@@ -24,8 +25,8 @@ ENTRY(copy_page)
30362 CFI_ADJUST_CFA_OFFSET 2*8
30363 movq %rbx, (%rsp)
30364 CFI_REL_OFFSET rbx, 0
30365- movq %r12, 1*8(%rsp)
30366- CFI_REL_OFFSET r12, 1*8
30367+ movq %r13, 1*8(%rsp)
30368+ CFI_REL_OFFSET r13, 1*8
30369
30370 movl $(4096/64)-5, %ecx
30371 .p2align 4
30372@@ -38,7 +39,7 @@ ENTRY(copy_page)
30373 movq 0x8*4(%rsi), %r9
30374 movq 0x8*5(%rsi), %r10
30375 movq 0x8*6(%rsi), %r11
30376- movq 0x8*7(%rsi), %r12
30377+ movq 0x8*7(%rsi), %r13
30378
30379 prefetcht0 5*64(%rsi)
30380
30381@@ -49,7 +50,7 @@ ENTRY(copy_page)
30382 movq %r9, 0x8*4(%rdi)
30383 movq %r10, 0x8*5(%rdi)
30384 movq %r11, 0x8*6(%rdi)
30385- movq %r12, 0x8*7(%rdi)
30386+ movq %r13, 0x8*7(%rdi)
30387
30388 leaq 64 (%rsi), %rsi
30389 leaq 64 (%rdi), %rdi
30390@@ -68,7 +69,7 @@ ENTRY(copy_page)
30391 movq 0x8*4(%rsi), %r9
30392 movq 0x8*5(%rsi), %r10
30393 movq 0x8*6(%rsi), %r11
30394- movq 0x8*7(%rsi), %r12
30395+ movq 0x8*7(%rsi), %r13
30396
30397 movq %rax, 0x8*0(%rdi)
30398 movq %rbx, 0x8*1(%rdi)
30399@@ -77,7 +78,7 @@ ENTRY(copy_page)
30400 movq %r9, 0x8*4(%rdi)
30401 movq %r10, 0x8*5(%rdi)
30402 movq %r11, 0x8*6(%rdi)
30403- movq %r12, 0x8*7(%rdi)
30404+ movq %r13, 0x8*7(%rdi)
30405
30406 leaq 64(%rdi), %rdi
30407 leaq 64(%rsi), %rsi
30408@@ -85,10 +86,11 @@ ENTRY(copy_page)
30409
30410 movq (%rsp), %rbx
30411 CFI_RESTORE rbx
30412- movq 1*8(%rsp), %r12
30413- CFI_RESTORE r12
30414+ movq 1*8(%rsp), %r13
30415+ CFI_RESTORE r13
30416 addq $2*8, %rsp
30417 CFI_ADJUST_CFA_OFFSET -2*8
30418+ pax_force_retaddr
30419 ret
30420 .Lcopy_page_end:
30421 CFI_ENDPROC
30422@@ -99,7 +101,7 @@ ENDPROC(copy_page)
30423
30424 #include <asm/cpufeature.h>
30425
30426- .section .altinstr_replacement,"ax"
30427+ .section .altinstr_replacement,"a"
30428 1: .byte 0xeb /* jmp <disp8> */
30429 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
30430 2:
30431diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
30432index dee945d..a84067b 100644
30433--- a/arch/x86/lib/copy_user_64.S
30434+++ b/arch/x86/lib/copy_user_64.S
30435@@ -18,31 +18,7 @@
30436 #include <asm/alternative-asm.h>
30437 #include <asm/asm.h>
30438 #include <asm/smap.h>
30439-
30440-/*
30441- * By placing feature2 after feature1 in altinstructions section, we logically
30442- * implement:
30443- * If CPU has feature2, jmp to alt2 is used
30444- * else if CPU has feature1, jmp to alt1 is used
30445- * else jmp to orig is used.
30446- */
30447- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
30448-0:
30449- .byte 0xe9 /* 32bit jump */
30450- .long \orig-1f /* by default jump to orig */
30451-1:
30452- .section .altinstr_replacement,"ax"
30453-2: .byte 0xe9 /* near jump with 32bit immediate */
30454- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
30455-3: .byte 0xe9 /* near jump with 32bit immediate */
30456- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
30457- .previous
30458-
30459- .section .altinstructions,"a"
30460- altinstruction_entry 0b,2b,\feature1,5,5
30461- altinstruction_entry 0b,3b,\feature2,5,5
30462- .previous
30463- .endm
30464+#include <asm/pgtable.h>
30465
30466 .macro ALIGN_DESTINATION
30467 #ifdef FIX_ALIGNMENT
30468@@ -70,52 +46,6 @@
30469 #endif
30470 .endm
30471
30472-/* Standard copy_to_user with segment limit checking */
30473-ENTRY(_copy_to_user)
30474- CFI_STARTPROC
30475- GET_THREAD_INFO(%rax)
30476- movq %rdi,%rcx
30477- addq %rdx,%rcx
30478- jc bad_to_user
30479- cmpq TI_addr_limit(%rax),%rcx
30480- ja bad_to_user
30481- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
30482- copy_user_generic_unrolled,copy_user_generic_string, \
30483- copy_user_enhanced_fast_string
30484- CFI_ENDPROC
30485-ENDPROC(_copy_to_user)
30486-
30487-/* Standard copy_from_user with segment limit checking */
30488-ENTRY(_copy_from_user)
30489- CFI_STARTPROC
30490- GET_THREAD_INFO(%rax)
30491- movq %rsi,%rcx
30492- addq %rdx,%rcx
30493- jc bad_from_user
30494- cmpq TI_addr_limit(%rax),%rcx
30495- ja bad_from_user
30496- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
30497- copy_user_generic_unrolled,copy_user_generic_string, \
30498- copy_user_enhanced_fast_string
30499- CFI_ENDPROC
30500-ENDPROC(_copy_from_user)
30501-
30502- .section .fixup,"ax"
30503- /* must zero dest */
30504-ENTRY(bad_from_user)
30505-bad_from_user:
30506- CFI_STARTPROC
30507- movl %edx,%ecx
30508- xorl %eax,%eax
30509- rep
30510- stosb
30511-bad_to_user:
30512- movl %edx,%eax
30513- ret
30514- CFI_ENDPROC
30515-ENDPROC(bad_from_user)
30516- .previous
30517-
30518 /*
30519 * copy_user_generic_unrolled - memory copy with exception handling.
30520 * This version is for CPUs like P4 that don't have efficient micro
30521@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
30522 */
30523 ENTRY(copy_user_generic_unrolled)
30524 CFI_STARTPROC
30525+ ASM_PAX_OPEN_USERLAND
30526 ASM_STAC
30527 cmpl $8,%edx
30528 jb 20f /* less then 8 bytes, go to byte copy loop */
30529@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
30530 jnz 21b
30531 23: xor %eax,%eax
30532 ASM_CLAC
30533+ ASM_PAX_CLOSE_USERLAND
30534+ pax_force_retaddr
30535 ret
30536
30537 .section .fixup,"ax"
30538@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
30539 */
30540 ENTRY(copy_user_generic_string)
30541 CFI_STARTPROC
30542+ ASM_PAX_OPEN_USERLAND
30543 ASM_STAC
30544 cmpl $8,%edx
30545 jb 2f /* less than 8 bytes, go to byte copy loop */
30546@@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
30547 movsb
30548 xorl %eax,%eax
30549 ASM_CLAC
30550+ ASM_PAX_CLOSE_USERLAND
30551+ pax_force_retaddr
30552 ret
30553
30554 .section .fixup,"ax"
30555@@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
30556 */
30557 ENTRY(copy_user_enhanced_fast_string)
30558 CFI_STARTPROC
30559+ ASM_PAX_OPEN_USERLAND
30560 ASM_STAC
30561 movl %edx,%ecx
30562 1: rep
30563 movsb
30564 xorl %eax,%eax
30565 ASM_CLAC
30566+ ASM_PAX_CLOSE_USERLAND
30567+ pax_force_retaddr
30568 ret
30569
30570 .section .fixup,"ax"
30571diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
30572index 6a4f43c..c70fb52 100644
30573--- a/arch/x86/lib/copy_user_nocache_64.S
30574+++ b/arch/x86/lib/copy_user_nocache_64.S
30575@@ -8,6 +8,7 @@
30576
30577 #include <linux/linkage.h>
30578 #include <asm/dwarf2.h>
30579+#include <asm/alternative-asm.h>
30580
30581 #define FIX_ALIGNMENT 1
30582
30583@@ -16,6 +17,7 @@
30584 #include <asm/thread_info.h>
30585 #include <asm/asm.h>
30586 #include <asm/smap.h>
30587+#include <asm/pgtable.h>
30588
30589 .macro ALIGN_DESTINATION
30590 #ifdef FIX_ALIGNMENT
30591@@ -49,6 +51,16 @@
30592 */
30593 ENTRY(__copy_user_nocache)
30594 CFI_STARTPROC
30595+
30596+#ifdef CONFIG_PAX_MEMORY_UDEREF
30597+ mov pax_user_shadow_base,%rcx
30598+ cmp %rcx,%rsi
30599+ jae 1f
30600+ add %rcx,%rsi
30601+1:
30602+#endif
30603+
30604+ ASM_PAX_OPEN_USERLAND
30605 ASM_STAC
30606 cmpl $8,%edx
30607 jb 20f /* less then 8 bytes, go to byte copy loop */
30608@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
30609 jnz 21b
30610 23: xorl %eax,%eax
30611 ASM_CLAC
30612+ ASM_PAX_CLOSE_USERLAND
30613 sfence
30614+ pax_force_retaddr
30615 ret
30616
30617 .section .fixup,"ax"
30618diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
30619index 2419d5f..fe52d0e 100644
30620--- a/arch/x86/lib/csum-copy_64.S
30621+++ b/arch/x86/lib/csum-copy_64.S
30622@@ -9,6 +9,7 @@
30623 #include <asm/dwarf2.h>
30624 #include <asm/errno.h>
30625 #include <asm/asm.h>
30626+#include <asm/alternative-asm.h>
30627
30628 /*
30629 * Checksum copy with exception handling.
30630@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
30631 CFI_ADJUST_CFA_OFFSET 7*8
30632 movq %rbx, 2*8(%rsp)
30633 CFI_REL_OFFSET rbx, 2*8
30634- movq %r12, 3*8(%rsp)
30635- CFI_REL_OFFSET r12, 3*8
30636+ movq %r15, 3*8(%rsp)
30637+ CFI_REL_OFFSET r15, 3*8
30638 movq %r14, 4*8(%rsp)
30639 CFI_REL_OFFSET r14, 4*8
30640 movq %r13, 5*8(%rsp)
30641@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
30642 movl %edx, %ecx
30643
30644 xorl %r9d, %r9d
30645- movq %rcx, %r12
30646+ movq %rcx, %r15
30647
30648- shrq $6, %r12
30649+ shrq $6, %r15
30650 jz .Lhandle_tail /* < 64 */
30651
30652 clc
30653
30654 /* main loop. clear in 64 byte blocks */
30655 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
30656- /* r11: temp3, rdx: temp4, r12 loopcnt */
30657+ /* r11: temp3, rdx: temp4, r15 loopcnt */
30658 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
30659 .p2align 4
30660 .Lloop:
30661@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
30662 adcq %r14, %rax
30663 adcq %r13, %rax
30664
30665- decl %r12d
30666+ decl %r15d
30667
30668 dest
30669 movq %rbx, (%rsi)
30670@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
30671 .Lende:
30672 movq 2*8(%rsp), %rbx
30673 CFI_RESTORE rbx
30674- movq 3*8(%rsp), %r12
30675- CFI_RESTORE r12
30676+ movq 3*8(%rsp), %r15
30677+ CFI_RESTORE r15
30678 movq 4*8(%rsp), %r14
30679 CFI_RESTORE r14
30680 movq 5*8(%rsp), %r13
30681@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
30682 CFI_RESTORE rbp
30683 addq $7*8, %rsp
30684 CFI_ADJUST_CFA_OFFSET -7*8
30685+ pax_force_retaddr
30686 ret
30687 CFI_RESTORE_STATE
30688
30689diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
30690index 7609e0e..b449b98 100644
30691--- a/arch/x86/lib/csum-wrappers_64.c
30692+++ b/arch/x86/lib/csum-wrappers_64.c
30693@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
30694 len -= 2;
30695 }
30696 }
30697+ pax_open_userland();
30698 stac();
30699- isum = csum_partial_copy_generic((__force const void *)src,
30700+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
30701 dst, len, isum, errp, NULL);
30702 clac();
30703+ pax_close_userland();
30704 if (unlikely(*errp))
30705 goto out_err;
30706
30707@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
30708 }
30709
30710 *errp = 0;
30711+ pax_open_userland();
30712 stac();
30713- ret = csum_partial_copy_generic(src, (void __force *)dst,
30714+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
30715 len, isum, NULL, errp);
30716 clac();
30717+ pax_close_userland();
30718 return ret;
30719 }
30720 EXPORT_SYMBOL(csum_partial_copy_to_user);
30721diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
30722index a451235..1daa956 100644
30723--- a/arch/x86/lib/getuser.S
30724+++ b/arch/x86/lib/getuser.S
30725@@ -33,17 +33,40 @@
30726 #include <asm/thread_info.h>
30727 #include <asm/asm.h>
30728 #include <asm/smap.h>
30729+#include <asm/segment.h>
30730+#include <asm/pgtable.h>
30731+#include <asm/alternative-asm.h>
30732+
30733+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30734+#define __copyuser_seg gs;
30735+#else
30736+#define __copyuser_seg
30737+#endif
30738
30739 .text
30740 ENTRY(__get_user_1)
30741 CFI_STARTPROC
30742+
30743+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30744 GET_THREAD_INFO(%_ASM_DX)
30745 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30746 jae bad_get_user
30747 ASM_STAC
30748-1: movzbl (%_ASM_AX),%edx
30749+
30750+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30751+ mov pax_user_shadow_base,%_ASM_DX
30752+ cmp %_ASM_DX,%_ASM_AX
30753+ jae 1234f
30754+ add %_ASM_DX,%_ASM_AX
30755+1234:
30756+#endif
30757+
30758+#endif
30759+
30760+1: __copyuser_seg movzbl (%_ASM_AX),%edx
30761 xor %eax,%eax
30762 ASM_CLAC
30763+ pax_force_retaddr
30764 ret
30765 CFI_ENDPROC
30766 ENDPROC(__get_user_1)
30767@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
30768 ENTRY(__get_user_2)
30769 CFI_STARTPROC
30770 add $1,%_ASM_AX
30771+
30772+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30773 jc bad_get_user
30774 GET_THREAD_INFO(%_ASM_DX)
30775 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30776 jae bad_get_user
30777 ASM_STAC
30778-2: movzwl -1(%_ASM_AX),%edx
30779+
30780+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30781+ mov pax_user_shadow_base,%_ASM_DX
30782+ cmp %_ASM_DX,%_ASM_AX
30783+ jae 1234f
30784+ add %_ASM_DX,%_ASM_AX
30785+1234:
30786+#endif
30787+
30788+#endif
30789+
30790+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
30791 xor %eax,%eax
30792 ASM_CLAC
30793+ pax_force_retaddr
30794 ret
30795 CFI_ENDPROC
30796 ENDPROC(__get_user_2)
30797@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
30798 ENTRY(__get_user_4)
30799 CFI_STARTPROC
30800 add $3,%_ASM_AX
30801+
30802+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30803 jc bad_get_user
30804 GET_THREAD_INFO(%_ASM_DX)
30805 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30806 jae bad_get_user
30807 ASM_STAC
30808-3: movl -3(%_ASM_AX),%edx
30809+
30810+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30811+ mov pax_user_shadow_base,%_ASM_DX
30812+ cmp %_ASM_DX,%_ASM_AX
30813+ jae 1234f
30814+ add %_ASM_DX,%_ASM_AX
30815+1234:
30816+#endif
30817+
30818+#endif
30819+
30820+3: __copyuser_seg movl -3(%_ASM_AX),%edx
30821 xor %eax,%eax
30822 ASM_CLAC
30823+ pax_force_retaddr
30824 ret
30825 CFI_ENDPROC
30826 ENDPROC(__get_user_4)
30827@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
30828 GET_THREAD_INFO(%_ASM_DX)
30829 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30830 jae bad_get_user
30831+
30832+#ifdef CONFIG_PAX_MEMORY_UDEREF
30833+ mov pax_user_shadow_base,%_ASM_DX
30834+ cmp %_ASM_DX,%_ASM_AX
30835+ jae 1234f
30836+ add %_ASM_DX,%_ASM_AX
30837+1234:
30838+#endif
30839+
30840 ASM_STAC
30841 4: movq -7(%_ASM_AX),%rdx
30842 xor %eax,%eax
30843 ASM_CLAC
30844+ pax_force_retaddr
30845 ret
30846 #else
30847 add $7,%_ASM_AX
30848@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
30849 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
30850 jae bad_get_user_8
30851 ASM_STAC
30852-4: movl -7(%_ASM_AX),%edx
30853-5: movl -3(%_ASM_AX),%ecx
30854+4: __copyuser_seg movl -7(%_ASM_AX),%edx
30855+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
30856 xor %eax,%eax
30857 ASM_CLAC
30858+ pax_force_retaddr
30859 ret
30860 #endif
30861 CFI_ENDPROC
30862@@ -113,6 +175,7 @@ bad_get_user:
30863 xor %edx,%edx
30864 mov $(-EFAULT),%_ASM_AX
30865 ASM_CLAC
30866+ pax_force_retaddr
30867 ret
30868 CFI_ENDPROC
30869 END(bad_get_user)
30870@@ -124,6 +187,7 @@ bad_get_user_8:
30871 xor %ecx,%ecx
30872 mov $(-EFAULT),%_ASM_AX
30873 ASM_CLAC
30874+ pax_force_retaddr
30875 ret
30876 CFI_ENDPROC
30877 END(bad_get_user_8)
30878diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
30879index 54fcffe..7be149e 100644
30880--- a/arch/x86/lib/insn.c
30881+++ b/arch/x86/lib/insn.c
30882@@ -20,8 +20,10 @@
30883
30884 #ifdef __KERNEL__
30885 #include <linux/string.h>
30886+#include <asm/pgtable_types.h>
30887 #else
30888 #include <string.h>
30889+#define ktla_ktva(addr) addr
30890 #endif
30891 #include <asm/inat.h>
30892 #include <asm/insn.h>
30893@@ -53,8 +55,8 @@
30894 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
30895 {
30896 memset(insn, 0, sizeof(*insn));
30897- insn->kaddr = kaddr;
30898- insn->next_byte = kaddr;
30899+ insn->kaddr = ktla_ktva(kaddr);
30900+ insn->next_byte = ktla_ktva(kaddr);
30901 insn->x86_64 = x86_64 ? 1 : 0;
30902 insn->opnd_bytes = 4;
30903 if (x86_64)
30904diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
30905index 05a95e7..326f2fa 100644
30906--- a/arch/x86/lib/iomap_copy_64.S
30907+++ b/arch/x86/lib/iomap_copy_64.S
30908@@ -17,6 +17,7 @@
30909
30910 #include <linux/linkage.h>
30911 #include <asm/dwarf2.h>
30912+#include <asm/alternative-asm.h>
30913
30914 /*
30915 * override generic version in lib/iomap_copy.c
30916@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
30917 CFI_STARTPROC
30918 movl %edx,%ecx
30919 rep movsd
30920+ pax_force_retaddr
30921 ret
30922 CFI_ENDPROC
30923 ENDPROC(__iowrite32_copy)
30924diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
30925index 56313a3..0db417e 100644
30926--- a/arch/x86/lib/memcpy_64.S
30927+++ b/arch/x86/lib/memcpy_64.S
30928@@ -24,7 +24,7 @@
30929 * This gets patched over the unrolled variant (below) via the
30930 * alternative instructions framework:
30931 */
30932- .section .altinstr_replacement, "ax", @progbits
30933+ .section .altinstr_replacement, "a", @progbits
30934 .Lmemcpy_c:
30935 movq %rdi, %rax
30936 movq %rdx, %rcx
30937@@ -33,6 +33,7 @@
30938 rep movsq
30939 movl %edx, %ecx
30940 rep movsb
30941+ pax_force_retaddr
30942 ret
30943 .Lmemcpy_e:
30944 .previous
30945@@ -44,11 +45,12 @@
30946 * This gets patched over the unrolled variant (below) via the
30947 * alternative instructions framework:
30948 */
30949- .section .altinstr_replacement, "ax", @progbits
30950+ .section .altinstr_replacement, "a", @progbits
30951 .Lmemcpy_c_e:
30952 movq %rdi, %rax
30953 movq %rdx, %rcx
30954 rep movsb
30955+ pax_force_retaddr
30956 ret
30957 .Lmemcpy_e_e:
30958 .previous
30959@@ -136,6 +138,7 @@ ENTRY(memcpy)
30960 movq %r9, 1*8(%rdi)
30961 movq %r10, -2*8(%rdi, %rdx)
30962 movq %r11, -1*8(%rdi, %rdx)
30963+ pax_force_retaddr
30964 retq
30965 .p2align 4
30966 .Lless_16bytes:
30967@@ -148,6 +151,7 @@ ENTRY(memcpy)
30968 movq -1*8(%rsi, %rdx), %r9
30969 movq %r8, 0*8(%rdi)
30970 movq %r9, -1*8(%rdi, %rdx)
30971+ pax_force_retaddr
30972 retq
30973 .p2align 4
30974 .Lless_8bytes:
30975@@ -161,6 +165,7 @@ ENTRY(memcpy)
30976 movl -4(%rsi, %rdx), %r8d
30977 movl %ecx, (%rdi)
30978 movl %r8d, -4(%rdi, %rdx)
30979+ pax_force_retaddr
30980 retq
30981 .p2align 4
30982 .Lless_3bytes:
30983@@ -179,6 +184,7 @@ ENTRY(memcpy)
30984 movb %cl, (%rdi)
30985
30986 .Lend:
30987+ pax_force_retaddr
30988 retq
30989 CFI_ENDPROC
30990 ENDPROC(memcpy)
30991diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
30992index 65268a6..dd1de11 100644
30993--- a/arch/x86/lib/memmove_64.S
30994+++ b/arch/x86/lib/memmove_64.S
30995@@ -202,14 +202,16 @@ ENTRY(memmove)
30996 movb (%rsi), %r11b
30997 movb %r11b, (%rdi)
30998 13:
30999+ pax_force_retaddr
31000 retq
31001 CFI_ENDPROC
31002
31003- .section .altinstr_replacement,"ax"
31004+ .section .altinstr_replacement,"a"
31005 .Lmemmove_begin_forward_efs:
31006 /* Forward moving data. */
31007 movq %rdx, %rcx
31008 rep movsb
31009+ pax_force_retaddr
31010 retq
31011 .Lmemmove_end_forward_efs:
31012 .previous
31013diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
31014index 2dcb380..2eb79fe 100644
31015--- a/arch/x86/lib/memset_64.S
31016+++ b/arch/x86/lib/memset_64.S
31017@@ -16,7 +16,7 @@
31018 *
31019 * rax original destination
31020 */
31021- .section .altinstr_replacement, "ax", @progbits
31022+ .section .altinstr_replacement, "a", @progbits
31023 .Lmemset_c:
31024 movq %rdi,%r9
31025 movq %rdx,%rcx
31026@@ -30,6 +30,7 @@
31027 movl %edx,%ecx
31028 rep stosb
31029 movq %r9,%rax
31030+ pax_force_retaddr
31031 ret
31032 .Lmemset_e:
31033 .previous
31034@@ -45,13 +46,14 @@
31035 *
31036 * rax original destination
31037 */
31038- .section .altinstr_replacement, "ax", @progbits
31039+ .section .altinstr_replacement, "a", @progbits
31040 .Lmemset_c_e:
31041 movq %rdi,%r9
31042 movb %sil,%al
31043 movq %rdx,%rcx
31044 rep stosb
31045 movq %r9,%rax
31046+ pax_force_retaddr
31047 ret
31048 .Lmemset_e_e:
31049 .previous
31050@@ -118,6 +120,7 @@ ENTRY(__memset)
31051
31052 .Lende:
31053 movq %r10,%rax
31054+ pax_force_retaddr
31055 ret
31056
31057 CFI_RESTORE_STATE
31058diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
31059index c9f2d9b..e7fd2c0 100644
31060--- a/arch/x86/lib/mmx_32.c
31061+++ b/arch/x86/lib/mmx_32.c
31062@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
31063 {
31064 void *p;
31065 int i;
31066+ unsigned long cr0;
31067
31068 if (unlikely(in_interrupt()))
31069 return __memcpy(to, from, len);
31070@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
31071 kernel_fpu_begin();
31072
31073 __asm__ __volatile__ (
31074- "1: prefetch (%0)\n" /* This set is 28 bytes */
31075- " prefetch 64(%0)\n"
31076- " prefetch 128(%0)\n"
31077- " prefetch 192(%0)\n"
31078- " prefetch 256(%0)\n"
31079+ "1: prefetch (%1)\n" /* This set is 28 bytes */
31080+ " prefetch 64(%1)\n"
31081+ " prefetch 128(%1)\n"
31082+ " prefetch 192(%1)\n"
31083+ " prefetch 256(%1)\n"
31084 "2: \n"
31085 ".section .fixup, \"ax\"\n"
31086- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31087+ "3: \n"
31088+
31089+#ifdef CONFIG_PAX_KERNEXEC
31090+ " movl %%cr0, %0\n"
31091+ " movl %0, %%eax\n"
31092+ " andl $0xFFFEFFFF, %%eax\n"
31093+ " movl %%eax, %%cr0\n"
31094+#endif
31095+
31096+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31097+
31098+#ifdef CONFIG_PAX_KERNEXEC
31099+ " movl %0, %%cr0\n"
31100+#endif
31101+
31102 " jmp 2b\n"
31103 ".previous\n"
31104 _ASM_EXTABLE(1b, 3b)
31105- : : "r" (from));
31106+ : "=&r" (cr0) : "r" (from) : "ax");
31107
31108 for ( ; i > 5; i--) {
31109 __asm__ __volatile__ (
31110- "1: prefetch 320(%0)\n"
31111- "2: movq (%0), %%mm0\n"
31112- " movq 8(%0), %%mm1\n"
31113- " movq 16(%0), %%mm2\n"
31114- " movq 24(%0), %%mm3\n"
31115- " movq %%mm0, (%1)\n"
31116- " movq %%mm1, 8(%1)\n"
31117- " movq %%mm2, 16(%1)\n"
31118- " movq %%mm3, 24(%1)\n"
31119- " movq 32(%0), %%mm0\n"
31120- " movq 40(%0), %%mm1\n"
31121- " movq 48(%0), %%mm2\n"
31122- " movq 56(%0), %%mm3\n"
31123- " movq %%mm0, 32(%1)\n"
31124- " movq %%mm1, 40(%1)\n"
31125- " movq %%mm2, 48(%1)\n"
31126- " movq %%mm3, 56(%1)\n"
31127+ "1: prefetch 320(%1)\n"
31128+ "2: movq (%1), %%mm0\n"
31129+ " movq 8(%1), %%mm1\n"
31130+ " movq 16(%1), %%mm2\n"
31131+ " movq 24(%1), %%mm3\n"
31132+ " movq %%mm0, (%2)\n"
31133+ " movq %%mm1, 8(%2)\n"
31134+ " movq %%mm2, 16(%2)\n"
31135+ " movq %%mm3, 24(%2)\n"
31136+ " movq 32(%1), %%mm0\n"
31137+ " movq 40(%1), %%mm1\n"
31138+ " movq 48(%1), %%mm2\n"
31139+ " movq 56(%1), %%mm3\n"
31140+ " movq %%mm0, 32(%2)\n"
31141+ " movq %%mm1, 40(%2)\n"
31142+ " movq %%mm2, 48(%2)\n"
31143+ " movq %%mm3, 56(%2)\n"
31144 ".section .fixup, \"ax\"\n"
31145- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31146+ "3:\n"
31147+
31148+#ifdef CONFIG_PAX_KERNEXEC
31149+ " movl %%cr0, %0\n"
31150+ " movl %0, %%eax\n"
31151+ " andl $0xFFFEFFFF, %%eax\n"
31152+ " movl %%eax, %%cr0\n"
31153+#endif
31154+
31155+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31156+
31157+#ifdef CONFIG_PAX_KERNEXEC
31158+ " movl %0, %%cr0\n"
31159+#endif
31160+
31161 " jmp 2b\n"
31162 ".previous\n"
31163 _ASM_EXTABLE(1b, 3b)
31164- : : "r" (from), "r" (to) : "memory");
31165+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31166
31167 from += 64;
31168 to += 64;
31169@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
31170 static void fast_copy_page(void *to, void *from)
31171 {
31172 int i;
31173+ unsigned long cr0;
31174
31175 kernel_fpu_begin();
31176
31177@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
31178 * but that is for later. -AV
31179 */
31180 __asm__ __volatile__(
31181- "1: prefetch (%0)\n"
31182- " prefetch 64(%0)\n"
31183- " prefetch 128(%0)\n"
31184- " prefetch 192(%0)\n"
31185- " prefetch 256(%0)\n"
31186+ "1: prefetch (%1)\n"
31187+ " prefetch 64(%1)\n"
31188+ " prefetch 128(%1)\n"
31189+ " prefetch 192(%1)\n"
31190+ " prefetch 256(%1)\n"
31191 "2: \n"
31192 ".section .fixup, \"ax\"\n"
31193- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31194+ "3: \n"
31195+
31196+#ifdef CONFIG_PAX_KERNEXEC
31197+ " movl %%cr0, %0\n"
31198+ " movl %0, %%eax\n"
31199+ " andl $0xFFFEFFFF, %%eax\n"
31200+ " movl %%eax, %%cr0\n"
31201+#endif
31202+
31203+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31204+
31205+#ifdef CONFIG_PAX_KERNEXEC
31206+ " movl %0, %%cr0\n"
31207+#endif
31208+
31209 " jmp 2b\n"
31210 ".previous\n"
31211- _ASM_EXTABLE(1b, 3b) : : "r" (from));
31212+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
31213
31214 for (i = 0; i < (4096-320)/64; i++) {
31215 __asm__ __volatile__ (
31216- "1: prefetch 320(%0)\n"
31217- "2: movq (%0), %%mm0\n"
31218- " movntq %%mm0, (%1)\n"
31219- " movq 8(%0), %%mm1\n"
31220- " movntq %%mm1, 8(%1)\n"
31221- " movq 16(%0), %%mm2\n"
31222- " movntq %%mm2, 16(%1)\n"
31223- " movq 24(%0), %%mm3\n"
31224- " movntq %%mm3, 24(%1)\n"
31225- " movq 32(%0), %%mm4\n"
31226- " movntq %%mm4, 32(%1)\n"
31227- " movq 40(%0), %%mm5\n"
31228- " movntq %%mm5, 40(%1)\n"
31229- " movq 48(%0), %%mm6\n"
31230- " movntq %%mm6, 48(%1)\n"
31231- " movq 56(%0), %%mm7\n"
31232- " movntq %%mm7, 56(%1)\n"
31233+ "1: prefetch 320(%1)\n"
31234+ "2: movq (%1), %%mm0\n"
31235+ " movntq %%mm0, (%2)\n"
31236+ " movq 8(%1), %%mm1\n"
31237+ " movntq %%mm1, 8(%2)\n"
31238+ " movq 16(%1), %%mm2\n"
31239+ " movntq %%mm2, 16(%2)\n"
31240+ " movq 24(%1), %%mm3\n"
31241+ " movntq %%mm3, 24(%2)\n"
31242+ " movq 32(%1), %%mm4\n"
31243+ " movntq %%mm4, 32(%2)\n"
31244+ " movq 40(%1), %%mm5\n"
31245+ " movntq %%mm5, 40(%2)\n"
31246+ " movq 48(%1), %%mm6\n"
31247+ " movntq %%mm6, 48(%2)\n"
31248+ " movq 56(%1), %%mm7\n"
31249+ " movntq %%mm7, 56(%2)\n"
31250 ".section .fixup, \"ax\"\n"
31251- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31252+ "3:\n"
31253+
31254+#ifdef CONFIG_PAX_KERNEXEC
31255+ " movl %%cr0, %0\n"
31256+ " movl %0, %%eax\n"
31257+ " andl $0xFFFEFFFF, %%eax\n"
31258+ " movl %%eax, %%cr0\n"
31259+#endif
31260+
31261+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31262+
31263+#ifdef CONFIG_PAX_KERNEXEC
31264+ " movl %0, %%cr0\n"
31265+#endif
31266+
31267 " jmp 2b\n"
31268 ".previous\n"
31269- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
31270+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31271
31272 from += 64;
31273 to += 64;
31274@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
31275 static void fast_copy_page(void *to, void *from)
31276 {
31277 int i;
31278+ unsigned long cr0;
31279
31280 kernel_fpu_begin();
31281
31282 __asm__ __volatile__ (
31283- "1: prefetch (%0)\n"
31284- " prefetch 64(%0)\n"
31285- " prefetch 128(%0)\n"
31286- " prefetch 192(%0)\n"
31287- " prefetch 256(%0)\n"
31288+ "1: prefetch (%1)\n"
31289+ " prefetch 64(%1)\n"
31290+ " prefetch 128(%1)\n"
31291+ " prefetch 192(%1)\n"
31292+ " prefetch 256(%1)\n"
31293 "2: \n"
31294 ".section .fixup, \"ax\"\n"
31295- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31296+ "3: \n"
31297+
31298+#ifdef CONFIG_PAX_KERNEXEC
31299+ " movl %%cr0, %0\n"
31300+ " movl %0, %%eax\n"
31301+ " andl $0xFFFEFFFF, %%eax\n"
31302+ " movl %%eax, %%cr0\n"
31303+#endif
31304+
31305+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
31306+
31307+#ifdef CONFIG_PAX_KERNEXEC
31308+ " movl %0, %%cr0\n"
31309+#endif
31310+
31311 " jmp 2b\n"
31312 ".previous\n"
31313- _ASM_EXTABLE(1b, 3b) : : "r" (from));
31314+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
31315
31316 for (i = 0; i < 4096/64; i++) {
31317 __asm__ __volatile__ (
31318- "1: prefetch 320(%0)\n"
31319- "2: movq (%0), %%mm0\n"
31320- " movq 8(%0), %%mm1\n"
31321- " movq 16(%0), %%mm2\n"
31322- " movq 24(%0), %%mm3\n"
31323- " movq %%mm0, (%1)\n"
31324- " movq %%mm1, 8(%1)\n"
31325- " movq %%mm2, 16(%1)\n"
31326- " movq %%mm3, 24(%1)\n"
31327- " movq 32(%0), %%mm0\n"
31328- " movq 40(%0), %%mm1\n"
31329- " movq 48(%0), %%mm2\n"
31330- " movq 56(%0), %%mm3\n"
31331- " movq %%mm0, 32(%1)\n"
31332- " movq %%mm1, 40(%1)\n"
31333- " movq %%mm2, 48(%1)\n"
31334- " movq %%mm3, 56(%1)\n"
31335+ "1: prefetch 320(%1)\n"
31336+ "2: movq (%1), %%mm0\n"
31337+ " movq 8(%1), %%mm1\n"
31338+ " movq 16(%1), %%mm2\n"
31339+ " movq 24(%1), %%mm3\n"
31340+ " movq %%mm0, (%2)\n"
31341+ " movq %%mm1, 8(%2)\n"
31342+ " movq %%mm2, 16(%2)\n"
31343+ " movq %%mm3, 24(%2)\n"
31344+ " movq 32(%1), %%mm0\n"
31345+ " movq 40(%1), %%mm1\n"
31346+ " movq 48(%1), %%mm2\n"
31347+ " movq 56(%1), %%mm3\n"
31348+ " movq %%mm0, 32(%2)\n"
31349+ " movq %%mm1, 40(%2)\n"
31350+ " movq %%mm2, 48(%2)\n"
31351+ " movq %%mm3, 56(%2)\n"
31352 ".section .fixup, \"ax\"\n"
31353- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31354+ "3:\n"
31355+
31356+#ifdef CONFIG_PAX_KERNEXEC
31357+ " movl %%cr0, %0\n"
31358+ " movl %0, %%eax\n"
31359+ " andl $0xFFFEFFFF, %%eax\n"
31360+ " movl %%eax, %%cr0\n"
31361+#endif
31362+
31363+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
31364+
31365+#ifdef CONFIG_PAX_KERNEXEC
31366+ " movl %0, %%cr0\n"
31367+#endif
31368+
31369 " jmp 2b\n"
31370 ".previous\n"
31371 _ASM_EXTABLE(1b, 3b)
31372- : : "r" (from), "r" (to) : "memory");
31373+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
31374
31375 from += 64;
31376 to += 64;
31377diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
31378index f6d13ee..d789440 100644
31379--- a/arch/x86/lib/msr-reg.S
31380+++ b/arch/x86/lib/msr-reg.S
31381@@ -3,6 +3,7 @@
31382 #include <asm/dwarf2.h>
31383 #include <asm/asm.h>
31384 #include <asm/msr.h>
31385+#include <asm/alternative-asm.h>
31386
31387 #ifdef CONFIG_X86_64
31388 /*
31389@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
31390 movl %edi, 28(%r10)
31391 popq_cfi %rbp
31392 popq_cfi %rbx
31393+ pax_force_retaddr
31394 ret
31395 3:
31396 CFI_RESTORE_STATE
31397diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
31398index fc6ba17..d4d989d 100644
31399--- a/arch/x86/lib/putuser.S
31400+++ b/arch/x86/lib/putuser.S
31401@@ -16,7 +16,9 @@
31402 #include <asm/errno.h>
31403 #include <asm/asm.h>
31404 #include <asm/smap.h>
31405-
31406+#include <asm/segment.h>
31407+#include <asm/pgtable.h>
31408+#include <asm/alternative-asm.h>
31409
31410 /*
31411 * __put_user_X
31412@@ -30,57 +32,125 @@
31413 * as they get called from within inline assembly.
31414 */
31415
31416-#define ENTER CFI_STARTPROC ; \
31417- GET_THREAD_INFO(%_ASM_BX)
31418-#define EXIT ASM_CLAC ; \
31419- ret ; \
31420+#define ENTER CFI_STARTPROC
31421+#define EXIT ASM_CLAC ; \
31422+ pax_force_retaddr ; \
31423+ ret ; \
31424 CFI_ENDPROC
31425
31426+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31427+#define _DEST %_ASM_CX,%_ASM_BX
31428+#else
31429+#define _DEST %_ASM_CX
31430+#endif
31431+
31432+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
31433+#define __copyuser_seg gs;
31434+#else
31435+#define __copyuser_seg
31436+#endif
31437+
31438 .text
31439 ENTRY(__put_user_1)
31440 ENTER
31441+
31442+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31443+ GET_THREAD_INFO(%_ASM_BX)
31444 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
31445 jae bad_put_user
31446 ASM_STAC
31447-1: movb %al,(%_ASM_CX)
31448+
31449+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31450+ mov pax_user_shadow_base,%_ASM_BX
31451+ cmp %_ASM_BX,%_ASM_CX
31452+ jb 1234f
31453+ xor %ebx,%ebx
31454+1234:
31455+#endif
31456+
31457+#endif
31458+
31459+1: __copyuser_seg movb %al,(_DEST)
31460 xor %eax,%eax
31461 EXIT
31462 ENDPROC(__put_user_1)
31463
31464 ENTRY(__put_user_2)
31465 ENTER
31466+
31467+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31468+ GET_THREAD_INFO(%_ASM_BX)
31469 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31470 sub $1,%_ASM_BX
31471 cmp %_ASM_BX,%_ASM_CX
31472 jae bad_put_user
31473 ASM_STAC
31474-2: movw %ax,(%_ASM_CX)
31475+
31476+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31477+ mov pax_user_shadow_base,%_ASM_BX
31478+ cmp %_ASM_BX,%_ASM_CX
31479+ jb 1234f
31480+ xor %ebx,%ebx
31481+1234:
31482+#endif
31483+
31484+#endif
31485+
31486+2: __copyuser_seg movw %ax,(_DEST)
31487 xor %eax,%eax
31488 EXIT
31489 ENDPROC(__put_user_2)
31490
31491 ENTRY(__put_user_4)
31492 ENTER
31493+
31494+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31495+ GET_THREAD_INFO(%_ASM_BX)
31496 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31497 sub $3,%_ASM_BX
31498 cmp %_ASM_BX,%_ASM_CX
31499 jae bad_put_user
31500 ASM_STAC
31501-3: movl %eax,(%_ASM_CX)
31502+
31503+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31504+ mov pax_user_shadow_base,%_ASM_BX
31505+ cmp %_ASM_BX,%_ASM_CX
31506+ jb 1234f
31507+ xor %ebx,%ebx
31508+1234:
31509+#endif
31510+
31511+#endif
31512+
31513+3: __copyuser_seg movl %eax,(_DEST)
31514 xor %eax,%eax
31515 EXIT
31516 ENDPROC(__put_user_4)
31517
31518 ENTRY(__put_user_8)
31519 ENTER
31520+
31521+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
31522+ GET_THREAD_INFO(%_ASM_BX)
31523 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
31524 sub $7,%_ASM_BX
31525 cmp %_ASM_BX,%_ASM_CX
31526 jae bad_put_user
31527 ASM_STAC
31528-4: mov %_ASM_AX,(%_ASM_CX)
31529+
31530+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31531+ mov pax_user_shadow_base,%_ASM_BX
31532+ cmp %_ASM_BX,%_ASM_CX
31533+ jb 1234f
31534+ xor %ebx,%ebx
31535+1234:
31536+#endif
31537+
31538+#endif
31539+
31540+4: __copyuser_seg mov %_ASM_AX,(_DEST)
31541 #ifdef CONFIG_X86_32
31542-5: movl %edx,4(%_ASM_CX)
31543+5: __copyuser_seg movl %edx,4(_DEST)
31544 #endif
31545 xor %eax,%eax
31546 EXIT
31547diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
31548index 1cad221..de671ee 100644
31549--- a/arch/x86/lib/rwlock.S
31550+++ b/arch/x86/lib/rwlock.S
31551@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
31552 FRAME
31553 0: LOCK_PREFIX
31554 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31555+
31556+#ifdef CONFIG_PAX_REFCOUNT
31557+ jno 1234f
31558+ LOCK_PREFIX
31559+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31560+ int $4
31561+1234:
31562+ _ASM_EXTABLE(1234b, 1234b)
31563+#endif
31564+
31565 1: rep; nop
31566 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
31567 jne 1b
31568 LOCK_PREFIX
31569 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
31570+
31571+#ifdef CONFIG_PAX_REFCOUNT
31572+ jno 1234f
31573+ LOCK_PREFIX
31574+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
31575+ int $4
31576+1234:
31577+ _ASM_EXTABLE(1234b, 1234b)
31578+#endif
31579+
31580 jnz 0b
31581 ENDFRAME
31582+ pax_force_retaddr
31583 ret
31584 CFI_ENDPROC
31585 END(__write_lock_failed)
31586@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
31587 FRAME
31588 0: LOCK_PREFIX
31589 READ_LOCK_SIZE(inc) (%__lock_ptr)
31590+
31591+#ifdef CONFIG_PAX_REFCOUNT
31592+ jno 1234f
31593+ LOCK_PREFIX
31594+ READ_LOCK_SIZE(dec) (%__lock_ptr)
31595+ int $4
31596+1234:
31597+ _ASM_EXTABLE(1234b, 1234b)
31598+#endif
31599+
31600 1: rep; nop
31601 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
31602 js 1b
31603 LOCK_PREFIX
31604 READ_LOCK_SIZE(dec) (%__lock_ptr)
31605+
31606+#ifdef CONFIG_PAX_REFCOUNT
31607+ jno 1234f
31608+ LOCK_PREFIX
31609+ READ_LOCK_SIZE(inc) (%__lock_ptr)
31610+ int $4
31611+1234:
31612+ _ASM_EXTABLE(1234b, 1234b)
31613+#endif
31614+
31615 js 0b
31616 ENDFRAME
31617+ pax_force_retaddr
31618 ret
31619 CFI_ENDPROC
31620 END(__read_lock_failed)
31621diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
31622index 5dff5f0..cadebf4 100644
31623--- a/arch/x86/lib/rwsem.S
31624+++ b/arch/x86/lib/rwsem.S
31625@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
31626 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31627 CFI_RESTORE __ASM_REG(dx)
31628 restore_common_regs
31629+ pax_force_retaddr
31630 ret
31631 CFI_ENDPROC
31632 ENDPROC(call_rwsem_down_read_failed)
31633@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
31634 movq %rax,%rdi
31635 call rwsem_down_write_failed
31636 restore_common_regs
31637+ pax_force_retaddr
31638 ret
31639 CFI_ENDPROC
31640 ENDPROC(call_rwsem_down_write_failed)
31641@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
31642 movq %rax,%rdi
31643 call rwsem_wake
31644 restore_common_regs
31645-1: ret
31646+1: pax_force_retaddr
31647+ ret
31648 CFI_ENDPROC
31649 ENDPROC(call_rwsem_wake)
31650
31651@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
31652 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
31653 CFI_RESTORE __ASM_REG(dx)
31654 restore_common_regs
31655+ pax_force_retaddr
31656 ret
31657 CFI_ENDPROC
31658 ENDPROC(call_rwsem_downgrade_wake)
31659diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
31660index 92d9fea..b2762c8 100644
31661--- a/arch/x86/lib/thunk_64.S
31662+++ b/arch/x86/lib/thunk_64.S
31663@@ -9,6 +9,7 @@
31664 #include <asm/dwarf2.h>
31665 #include <asm/calling.h>
31666 #include <asm/asm.h>
31667+#include <asm/alternative-asm.h>
31668
31669 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
31670 .macro THUNK name, func, put_ret_addr_in_rdi=0
31671@@ -16,11 +17,11 @@
31672 \name:
31673 CFI_STARTPROC
31674
31675- /* this one pushes 9 elems, the next one would be %rIP */
31676- SAVE_ARGS
31677+ /* this one pushes 15+1 elems, the next one would be %rIP */
31678+ SAVE_ARGS 8
31679
31680 .if \put_ret_addr_in_rdi
31681- movq_cfi_restore 9*8, rdi
31682+ movq_cfi_restore RIP, rdi
31683 .endif
31684
31685 call \func
31686@@ -40,9 +41,10 @@
31687
31688 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
31689 CFI_STARTPROC
31690- SAVE_ARGS
31691+ SAVE_ARGS 8
31692 restore:
31693- RESTORE_ARGS
31694+ RESTORE_ARGS 1,8
31695+ pax_force_retaddr
31696 ret
31697 CFI_ENDPROC
31698 _ASM_NOKPROBE(restore)
31699diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
31700index e2f5e21..4b22130 100644
31701--- a/arch/x86/lib/usercopy_32.c
31702+++ b/arch/x86/lib/usercopy_32.c
31703@@ -42,11 +42,13 @@ do { \
31704 int __d0; \
31705 might_fault(); \
31706 __asm__ __volatile__( \
31707+ __COPYUSER_SET_ES \
31708 ASM_STAC "\n" \
31709 "0: rep; stosl\n" \
31710 " movl %2,%0\n" \
31711 "1: rep; stosb\n" \
31712 "2: " ASM_CLAC "\n" \
31713+ __COPYUSER_RESTORE_ES \
31714 ".section .fixup,\"ax\"\n" \
31715 "3: lea 0(%2,%0,4),%0\n" \
31716 " jmp 2b\n" \
31717@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
31718
31719 #ifdef CONFIG_X86_INTEL_USERCOPY
31720 static unsigned long
31721-__copy_user_intel(void __user *to, const void *from, unsigned long size)
31722+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
31723 {
31724 int d0, d1;
31725 __asm__ __volatile__(
31726@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31727 " .align 2,0x90\n"
31728 "3: movl 0(%4), %%eax\n"
31729 "4: movl 4(%4), %%edx\n"
31730- "5: movl %%eax, 0(%3)\n"
31731- "6: movl %%edx, 4(%3)\n"
31732+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
31733+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
31734 "7: movl 8(%4), %%eax\n"
31735 "8: movl 12(%4),%%edx\n"
31736- "9: movl %%eax, 8(%3)\n"
31737- "10: movl %%edx, 12(%3)\n"
31738+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
31739+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
31740 "11: movl 16(%4), %%eax\n"
31741 "12: movl 20(%4), %%edx\n"
31742- "13: movl %%eax, 16(%3)\n"
31743- "14: movl %%edx, 20(%3)\n"
31744+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
31745+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
31746 "15: movl 24(%4), %%eax\n"
31747 "16: movl 28(%4), %%edx\n"
31748- "17: movl %%eax, 24(%3)\n"
31749- "18: movl %%edx, 28(%3)\n"
31750+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
31751+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
31752 "19: movl 32(%4), %%eax\n"
31753 "20: movl 36(%4), %%edx\n"
31754- "21: movl %%eax, 32(%3)\n"
31755- "22: movl %%edx, 36(%3)\n"
31756+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
31757+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
31758 "23: movl 40(%4), %%eax\n"
31759 "24: movl 44(%4), %%edx\n"
31760- "25: movl %%eax, 40(%3)\n"
31761- "26: movl %%edx, 44(%3)\n"
31762+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
31763+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
31764 "27: movl 48(%4), %%eax\n"
31765 "28: movl 52(%4), %%edx\n"
31766- "29: movl %%eax, 48(%3)\n"
31767- "30: movl %%edx, 52(%3)\n"
31768+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
31769+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
31770 "31: movl 56(%4), %%eax\n"
31771 "32: movl 60(%4), %%edx\n"
31772- "33: movl %%eax, 56(%3)\n"
31773- "34: movl %%edx, 60(%3)\n"
31774+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
31775+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
31776 " addl $-64, %0\n"
31777 " addl $64, %4\n"
31778 " addl $64, %3\n"
31779@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
31780 " shrl $2, %0\n"
31781 " andl $3, %%eax\n"
31782 " cld\n"
31783+ __COPYUSER_SET_ES
31784 "99: rep; movsl\n"
31785 "36: movl %%eax, %0\n"
31786 "37: rep; movsb\n"
31787 "100:\n"
31788+ __COPYUSER_RESTORE_ES
31789+ ".section .fixup,\"ax\"\n"
31790+ "101: lea 0(%%eax,%0,4),%0\n"
31791+ " jmp 100b\n"
31792+ ".previous\n"
31793+ _ASM_EXTABLE(1b,100b)
31794+ _ASM_EXTABLE(2b,100b)
31795+ _ASM_EXTABLE(3b,100b)
31796+ _ASM_EXTABLE(4b,100b)
31797+ _ASM_EXTABLE(5b,100b)
31798+ _ASM_EXTABLE(6b,100b)
31799+ _ASM_EXTABLE(7b,100b)
31800+ _ASM_EXTABLE(8b,100b)
31801+ _ASM_EXTABLE(9b,100b)
31802+ _ASM_EXTABLE(10b,100b)
31803+ _ASM_EXTABLE(11b,100b)
31804+ _ASM_EXTABLE(12b,100b)
31805+ _ASM_EXTABLE(13b,100b)
31806+ _ASM_EXTABLE(14b,100b)
31807+ _ASM_EXTABLE(15b,100b)
31808+ _ASM_EXTABLE(16b,100b)
31809+ _ASM_EXTABLE(17b,100b)
31810+ _ASM_EXTABLE(18b,100b)
31811+ _ASM_EXTABLE(19b,100b)
31812+ _ASM_EXTABLE(20b,100b)
31813+ _ASM_EXTABLE(21b,100b)
31814+ _ASM_EXTABLE(22b,100b)
31815+ _ASM_EXTABLE(23b,100b)
31816+ _ASM_EXTABLE(24b,100b)
31817+ _ASM_EXTABLE(25b,100b)
31818+ _ASM_EXTABLE(26b,100b)
31819+ _ASM_EXTABLE(27b,100b)
31820+ _ASM_EXTABLE(28b,100b)
31821+ _ASM_EXTABLE(29b,100b)
31822+ _ASM_EXTABLE(30b,100b)
31823+ _ASM_EXTABLE(31b,100b)
31824+ _ASM_EXTABLE(32b,100b)
31825+ _ASM_EXTABLE(33b,100b)
31826+ _ASM_EXTABLE(34b,100b)
31827+ _ASM_EXTABLE(35b,100b)
31828+ _ASM_EXTABLE(36b,100b)
31829+ _ASM_EXTABLE(37b,100b)
31830+ _ASM_EXTABLE(99b,101b)
31831+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
31832+ : "1"(to), "2"(from), "0"(size)
31833+ : "eax", "edx", "memory");
31834+ return size;
31835+}
31836+
31837+static unsigned long
31838+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
31839+{
31840+ int d0, d1;
31841+ __asm__ __volatile__(
31842+ " .align 2,0x90\n"
31843+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
31844+ " cmpl $67, %0\n"
31845+ " jbe 3f\n"
31846+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
31847+ " .align 2,0x90\n"
31848+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
31849+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
31850+ "5: movl %%eax, 0(%3)\n"
31851+ "6: movl %%edx, 4(%3)\n"
31852+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
31853+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
31854+ "9: movl %%eax, 8(%3)\n"
31855+ "10: movl %%edx, 12(%3)\n"
31856+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
31857+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
31858+ "13: movl %%eax, 16(%3)\n"
31859+ "14: movl %%edx, 20(%3)\n"
31860+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
31861+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
31862+ "17: movl %%eax, 24(%3)\n"
31863+ "18: movl %%edx, 28(%3)\n"
31864+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
31865+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
31866+ "21: movl %%eax, 32(%3)\n"
31867+ "22: movl %%edx, 36(%3)\n"
31868+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
31869+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
31870+ "25: movl %%eax, 40(%3)\n"
31871+ "26: movl %%edx, 44(%3)\n"
31872+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
31873+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
31874+ "29: movl %%eax, 48(%3)\n"
31875+ "30: movl %%edx, 52(%3)\n"
31876+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
31877+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
31878+ "33: movl %%eax, 56(%3)\n"
31879+ "34: movl %%edx, 60(%3)\n"
31880+ " addl $-64, %0\n"
31881+ " addl $64, %4\n"
31882+ " addl $64, %3\n"
31883+ " cmpl $63, %0\n"
31884+ " ja 1b\n"
31885+ "35: movl %0, %%eax\n"
31886+ " shrl $2, %0\n"
31887+ " andl $3, %%eax\n"
31888+ " cld\n"
31889+ "99: rep; "__copyuser_seg" movsl\n"
31890+ "36: movl %%eax, %0\n"
31891+ "37: rep; "__copyuser_seg" movsb\n"
31892+ "100:\n"
31893 ".section .fixup,\"ax\"\n"
31894 "101: lea 0(%%eax,%0,4),%0\n"
31895 " jmp 100b\n"
31896@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31897 int d0, d1;
31898 __asm__ __volatile__(
31899 " .align 2,0x90\n"
31900- "0: movl 32(%4), %%eax\n"
31901+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31902 " cmpl $67, %0\n"
31903 " jbe 2f\n"
31904- "1: movl 64(%4), %%eax\n"
31905+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31906 " .align 2,0x90\n"
31907- "2: movl 0(%4), %%eax\n"
31908- "21: movl 4(%4), %%edx\n"
31909+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31910+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31911 " movl %%eax, 0(%3)\n"
31912 " movl %%edx, 4(%3)\n"
31913- "3: movl 8(%4), %%eax\n"
31914- "31: movl 12(%4),%%edx\n"
31915+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31916+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31917 " movl %%eax, 8(%3)\n"
31918 " movl %%edx, 12(%3)\n"
31919- "4: movl 16(%4), %%eax\n"
31920- "41: movl 20(%4), %%edx\n"
31921+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31922+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31923 " movl %%eax, 16(%3)\n"
31924 " movl %%edx, 20(%3)\n"
31925- "10: movl 24(%4), %%eax\n"
31926- "51: movl 28(%4), %%edx\n"
31927+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31928+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31929 " movl %%eax, 24(%3)\n"
31930 " movl %%edx, 28(%3)\n"
31931- "11: movl 32(%4), %%eax\n"
31932- "61: movl 36(%4), %%edx\n"
31933+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31934+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31935 " movl %%eax, 32(%3)\n"
31936 " movl %%edx, 36(%3)\n"
31937- "12: movl 40(%4), %%eax\n"
31938- "71: movl 44(%4), %%edx\n"
31939+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31940+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31941 " movl %%eax, 40(%3)\n"
31942 " movl %%edx, 44(%3)\n"
31943- "13: movl 48(%4), %%eax\n"
31944- "81: movl 52(%4), %%edx\n"
31945+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31946+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31947 " movl %%eax, 48(%3)\n"
31948 " movl %%edx, 52(%3)\n"
31949- "14: movl 56(%4), %%eax\n"
31950- "91: movl 60(%4), %%edx\n"
31951+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31952+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31953 " movl %%eax, 56(%3)\n"
31954 " movl %%edx, 60(%3)\n"
31955 " addl $-64, %0\n"
31956@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
31957 " shrl $2, %0\n"
31958 " andl $3, %%eax\n"
31959 " cld\n"
31960- "6: rep; movsl\n"
31961+ "6: rep; "__copyuser_seg" movsl\n"
31962 " movl %%eax,%0\n"
31963- "7: rep; movsb\n"
31964+ "7: rep; "__copyuser_seg" movsb\n"
31965 "8:\n"
31966 ".section .fixup,\"ax\"\n"
31967 "9: lea 0(%%eax,%0,4),%0\n"
31968@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
31969
31970 __asm__ __volatile__(
31971 " .align 2,0x90\n"
31972- "0: movl 32(%4), %%eax\n"
31973+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31974 " cmpl $67, %0\n"
31975 " jbe 2f\n"
31976- "1: movl 64(%4), %%eax\n"
31977+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31978 " .align 2,0x90\n"
31979- "2: movl 0(%4), %%eax\n"
31980- "21: movl 4(%4), %%edx\n"
31981+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31982+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31983 " movnti %%eax, 0(%3)\n"
31984 " movnti %%edx, 4(%3)\n"
31985- "3: movl 8(%4), %%eax\n"
31986- "31: movl 12(%4),%%edx\n"
31987+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31988+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31989 " movnti %%eax, 8(%3)\n"
31990 " movnti %%edx, 12(%3)\n"
31991- "4: movl 16(%4), %%eax\n"
31992- "41: movl 20(%4), %%edx\n"
31993+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31994+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31995 " movnti %%eax, 16(%3)\n"
31996 " movnti %%edx, 20(%3)\n"
31997- "10: movl 24(%4), %%eax\n"
31998- "51: movl 28(%4), %%edx\n"
31999+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
32000+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
32001 " movnti %%eax, 24(%3)\n"
32002 " movnti %%edx, 28(%3)\n"
32003- "11: movl 32(%4), %%eax\n"
32004- "61: movl 36(%4), %%edx\n"
32005+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
32006+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
32007 " movnti %%eax, 32(%3)\n"
32008 " movnti %%edx, 36(%3)\n"
32009- "12: movl 40(%4), %%eax\n"
32010- "71: movl 44(%4), %%edx\n"
32011+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
32012+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
32013 " movnti %%eax, 40(%3)\n"
32014 " movnti %%edx, 44(%3)\n"
32015- "13: movl 48(%4), %%eax\n"
32016- "81: movl 52(%4), %%edx\n"
32017+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
32018+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
32019 " movnti %%eax, 48(%3)\n"
32020 " movnti %%edx, 52(%3)\n"
32021- "14: movl 56(%4), %%eax\n"
32022- "91: movl 60(%4), %%edx\n"
32023+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
32024+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
32025 " movnti %%eax, 56(%3)\n"
32026 " movnti %%edx, 60(%3)\n"
32027 " addl $-64, %0\n"
32028@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
32029 " shrl $2, %0\n"
32030 " andl $3, %%eax\n"
32031 " cld\n"
32032- "6: rep; movsl\n"
32033+ "6: rep; "__copyuser_seg" movsl\n"
32034 " movl %%eax,%0\n"
32035- "7: rep; movsb\n"
32036+ "7: rep; "__copyuser_seg" movsb\n"
32037 "8:\n"
32038 ".section .fixup,\"ax\"\n"
32039 "9: lea 0(%%eax,%0,4),%0\n"
32040@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
32041
32042 __asm__ __volatile__(
32043 " .align 2,0x90\n"
32044- "0: movl 32(%4), %%eax\n"
32045+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
32046 " cmpl $67, %0\n"
32047 " jbe 2f\n"
32048- "1: movl 64(%4), %%eax\n"
32049+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
32050 " .align 2,0x90\n"
32051- "2: movl 0(%4), %%eax\n"
32052- "21: movl 4(%4), %%edx\n"
32053+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
32054+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
32055 " movnti %%eax, 0(%3)\n"
32056 " movnti %%edx, 4(%3)\n"
32057- "3: movl 8(%4), %%eax\n"
32058- "31: movl 12(%4),%%edx\n"
32059+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
32060+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
32061 " movnti %%eax, 8(%3)\n"
32062 " movnti %%edx, 12(%3)\n"
32063- "4: movl 16(%4), %%eax\n"
32064- "41: movl 20(%4), %%edx\n"
32065+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
32066+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
32067 " movnti %%eax, 16(%3)\n"
32068 " movnti %%edx, 20(%3)\n"
32069- "10: movl 24(%4), %%eax\n"
32070- "51: movl 28(%4), %%edx\n"
32071+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
32072+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
32073 " movnti %%eax, 24(%3)\n"
32074 " movnti %%edx, 28(%3)\n"
32075- "11: movl 32(%4), %%eax\n"
32076- "61: movl 36(%4), %%edx\n"
32077+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
32078+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
32079 " movnti %%eax, 32(%3)\n"
32080 " movnti %%edx, 36(%3)\n"
32081- "12: movl 40(%4), %%eax\n"
32082- "71: movl 44(%4), %%edx\n"
32083+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
32084+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
32085 " movnti %%eax, 40(%3)\n"
32086 " movnti %%edx, 44(%3)\n"
32087- "13: movl 48(%4), %%eax\n"
32088- "81: movl 52(%4), %%edx\n"
32089+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
32090+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
32091 " movnti %%eax, 48(%3)\n"
32092 " movnti %%edx, 52(%3)\n"
32093- "14: movl 56(%4), %%eax\n"
32094- "91: movl 60(%4), %%edx\n"
32095+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
32096+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
32097 " movnti %%eax, 56(%3)\n"
32098 " movnti %%edx, 60(%3)\n"
32099 " addl $-64, %0\n"
32100@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
32101 " shrl $2, %0\n"
32102 " andl $3, %%eax\n"
32103 " cld\n"
32104- "6: rep; movsl\n"
32105+ "6: rep; "__copyuser_seg" movsl\n"
32106 " movl %%eax,%0\n"
32107- "7: rep; movsb\n"
32108+ "7: rep; "__copyuser_seg" movsb\n"
32109 "8:\n"
32110 ".section .fixup,\"ax\"\n"
32111 "9: lea 0(%%eax,%0,4),%0\n"
32112@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
32113 */
32114 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
32115 unsigned long size);
32116-unsigned long __copy_user_intel(void __user *to, const void *from,
32117+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
32118+ unsigned long size);
32119+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
32120 unsigned long size);
32121 unsigned long __copy_user_zeroing_intel_nocache(void *to,
32122 const void __user *from, unsigned long size);
32123 #endif /* CONFIG_X86_INTEL_USERCOPY */
32124
32125 /* Generic arbitrary sized copy. */
32126-#define __copy_user(to, from, size) \
32127+#define __copy_user(to, from, size, prefix, set, restore) \
32128 do { \
32129 int __d0, __d1, __d2; \
32130 __asm__ __volatile__( \
32131+ set \
32132 " cmp $7,%0\n" \
32133 " jbe 1f\n" \
32134 " movl %1,%0\n" \
32135 " negl %0\n" \
32136 " andl $7,%0\n" \
32137 " subl %0,%3\n" \
32138- "4: rep; movsb\n" \
32139+ "4: rep; "prefix"movsb\n" \
32140 " movl %3,%0\n" \
32141 " shrl $2,%0\n" \
32142 " andl $3,%3\n" \
32143 " .align 2,0x90\n" \
32144- "0: rep; movsl\n" \
32145+ "0: rep; "prefix"movsl\n" \
32146 " movl %3,%0\n" \
32147- "1: rep; movsb\n" \
32148+ "1: rep; "prefix"movsb\n" \
32149 "2:\n" \
32150+ restore \
32151 ".section .fixup,\"ax\"\n" \
32152 "5: addl %3,%0\n" \
32153 " jmp 2b\n" \
32154@@ -538,14 +650,14 @@ do { \
32155 " negl %0\n" \
32156 " andl $7,%0\n" \
32157 " subl %0,%3\n" \
32158- "4: rep; movsb\n" \
32159+ "4: rep; "__copyuser_seg"movsb\n" \
32160 " movl %3,%0\n" \
32161 " shrl $2,%0\n" \
32162 " andl $3,%3\n" \
32163 " .align 2,0x90\n" \
32164- "0: rep; movsl\n" \
32165+ "0: rep; "__copyuser_seg"movsl\n" \
32166 " movl %3,%0\n" \
32167- "1: rep; movsb\n" \
32168+ "1: rep; "__copyuser_seg"movsb\n" \
32169 "2:\n" \
32170 ".section .fixup,\"ax\"\n" \
32171 "5: addl %3,%0\n" \
32172@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
32173 {
32174 stac();
32175 if (movsl_is_ok(to, from, n))
32176- __copy_user(to, from, n);
32177+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
32178 else
32179- n = __copy_user_intel(to, from, n);
32180+ n = __generic_copy_to_user_intel(to, from, n);
32181 clac();
32182 return n;
32183 }
32184@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
32185 {
32186 stac();
32187 if (movsl_is_ok(to, from, n))
32188- __copy_user(to, from, n);
32189+ __copy_user(to, from, n, __copyuser_seg, "", "");
32190 else
32191- n = __copy_user_intel((void __user *)to,
32192- (const void *)from, n);
32193+ n = __generic_copy_from_user_intel(to, from, n);
32194 clac();
32195 return n;
32196 }
32197@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
32198 if (n > 64 && cpu_has_xmm2)
32199 n = __copy_user_intel_nocache(to, from, n);
32200 else
32201- __copy_user(to, from, n);
32202+ __copy_user(to, from, n, __copyuser_seg, "", "");
32203 #else
32204- __copy_user(to, from, n);
32205+ __copy_user(to, from, n, __copyuser_seg, "", "");
32206 #endif
32207 clac();
32208 return n;
32209 }
32210 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
32211
32212-/**
32213- * copy_to_user: - Copy a block of data into user space.
32214- * @to: Destination address, in user space.
32215- * @from: Source address, in kernel space.
32216- * @n: Number of bytes to copy.
32217- *
32218- * Context: User context only. This function may sleep.
32219- *
32220- * Copy data from kernel space to user space.
32221- *
32222- * Returns number of bytes that could not be copied.
32223- * On success, this will be zero.
32224- */
32225-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
32226+#ifdef CONFIG_PAX_MEMORY_UDEREF
32227+void __set_fs(mm_segment_t x)
32228 {
32229- if (access_ok(VERIFY_WRITE, to, n))
32230- n = __copy_to_user(to, from, n);
32231- return n;
32232+ switch (x.seg) {
32233+ case 0:
32234+ loadsegment(gs, 0);
32235+ break;
32236+ case TASK_SIZE_MAX:
32237+ loadsegment(gs, __USER_DS);
32238+ break;
32239+ case -1UL:
32240+ loadsegment(gs, __KERNEL_DS);
32241+ break;
32242+ default:
32243+ BUG();
32244+ }
32245 }
32246-EXPORT_SYMBOL(_copy_to_user);
32247+EXPORT_SYMBOL(__set_fs);
32248
32249-/**
32250- * copy_from_user: - Copy a block of data from user space.
32251- * @to: Destination address, in kernel space.
32252- * @from: Source address, in user space.
32253- * @n: Number of bytes to copy.
32254- *
32255- * Context: User context only. This function may sleep.
32256- *
32257- * Copy data from user space to kernel space.
32258- *
32259- * Returns number of bytes that could not be copied.
32260- * On success, this will be zero.
32261- *
32262- * If some data could not be copied, this function will pad the copied
32263- * data to the requested size using zero bytes.
32264- */
32265-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
32266+void set_fs(mm_segment_t x)
32267 {
32268- if (access_ok(VERIFY_READ, from, n))
32269- n = __copy_from_user(to, from, n);
32270- else
32271- memset(to, 0, n);
32272- return n;
32273+ current_thread_info()->addr_limit = x;
32274+ __set_fs(x);
32275 }
32276-EXPORT_SYMBOL(_copy_from_user);
32277+EXPORT_SYMBOL(set_fs);
32278+#endif
32279diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
32280index c905e89..01ab928 100644
32281--- a/arch/x86/lib/usercopy_64.c
32282+++ b/arch/x86/lib/usercopy_64.c
32283@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
32284 might_fault();
32285 /* no memory constraint because it doesn't change any memory gcc knows
32286 about */
32287+ pax_open_userland();
32288 stac();
32289 asm volatile(
32290 " testq %[size8],%[size8]\n"
32291@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
32292 _ASM_EXTABLE(0b,3b)
32293 _ASM_EXTABLE(1b,2b)
32294 : [size8] "=&c"(size), [dst] "=&D" (__d0)
32295- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
32296+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
32297 [zero] "r" (0UL), [eight] "r" (8UL));
32298 clac();
32299+ pax_close_userland();
32300 return size;
32301 }
32302 EXPORT_SYMBOL(__clear_user);
32303@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
32304 }
32305 EXPORT_SYMBOL(clear_user);
32306
32307-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
32308+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
32309 {
32310- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
32311- return copy_user_generic((__force void *)to, (__force void *)from, len);
32312- }
32313- return len;
32314+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
32315+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
32316+ return len;
32317 }
32318 EXPORT_SYMBOL(copy_in_user);
32319
32320@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
32321 * it is not necessary to optimize tail handling.
32322 */
32323 __visible unsigned long
32324-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
32325+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
32326 {
32327 char c;
32328 unsigned zero_len;
32329
32330+ clac();
32331+ pax_close_userland();
32332 for (; len; --len, to++) {
32333 if (__get_user_nocheck(c, from++, sizeof(char)))
32334 break;
32335@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
32336 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
32337 if (__put_user_nocheck(c, to++, sizeof(char)))
32338 break;
32339- clac();
32340 return len;
32341 }
32342diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
32343index 6a19ad9..1c48f9a 100644
32344--- a/arch/x86/mm/Makefile
32345+++ b/arch/x86/mm/Makefile
32346@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
32347 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
32348
32349 obj-$(CONFIG_MEMTEST) += memtest.o
32350+
32351+quote:="
32352+obj-$(CONFIG_X86_64) += uderef_64.o
32353+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
32354diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
32355index 903ec1e..c4166b2 100644
32356--- a/arch/x86/mm/extable.c
32357+++ b/arch/x86/mm/extable.c
32358@@ -6,12 +6,24 @@
32359 static inline unsigned long
32360 ex_insn_addr(const struct exception_table_entry *x)
32361 {
32362- return (unsigned long)&x->insn + x->insn;
32363+ unsigned long reloc = 0;
32364+
32365+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32366+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32367+#endif
32368+
32369+ return (unsigned long)&x->insn + x->insn + reloc;
32370 }
32371 static inline unsigned long
32372 ex_fixup_addr(const struct exception_table_entry *x)
32373 {
32374- return (unsigned long)&x->fixup + x->fixup;
32375+ unsigned long reloc = 0;
32376+
32377+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32378+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32379+#endif
32380+
32381+ return (unsigned long)&x->fixup + x->fixup + reloc;
32382 }
32383
32384 int fixup_exception(struct pt_regs *regs)
32385@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
32386 unsigned long new_ip;
32387
32388 #ifdef CONFIG_PNPBIOS
32389- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
32390+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
32391 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
32392 extern u32 pnp_bios_is_utter_crap;
32393 pnp_bios_is_utter_crap = 1;
32394@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
32395 i += 4;
32396 p->fixup -= i;
32397 i += 4;
32398+
32399+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
32400+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
32401+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32402+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
32403+#endif
32404+
32405 }
32406 }
32407
32408diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
32409index a241946..d7a04cf 100644
32410--- a/arch/x86/mm/fault.c
32411+++ b/arch/x86/mm/fault.c
32412@@ -14,12 +14,19 @@
32413 #include <linux/hugetlb.h> /* hstate_index_to_shift */
32414 #include <linux/prefetch.h> /* prefetchw */
32415 #include <linux/context_tracking.h> /* exception_enter(), ... */
32416+#include <linux/unistd.h>
32417+#include <linux/compiler.h>
32418
32419 #include <asm/traps.h> /* dotraplinkage, ... */
32420 #include <asm/pgalloc.h> /* pgd_*(), ... */
32421 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
32422 #include <asm/fixmap.h> /* VSYSCALL_ADDR */
32423 #include <asm/vsyscall.h> /* emulate_vsyscall */
32424+#include <asm/tlbflush.h>
32425+
32426+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32427+#include <asm/stacktrace.h>
32428+#endif
32429
32430 #define CREATE_TRACE_POINTS
32431 #include <asm/trace/exceptions.h>
32432@@ -60,7 +67,7 @@ static nokprobe_inline int kprobes_fault(struct pt_regs *regs)
32433 int ret = 0;
32434
32435 /* kprobe_running() needs smp_processor_id() */
32436- if (kprobes_built_in() && !user_mode_vm(regs)) {
32437+ if (kprobes_built_in() && !user_mode(regs)) {
32438 preempt_disable();
32439 if (kprobe_running() && kprobe_fault_handler(regs, 14))
32440 ret = 1;
32441@@ -121,7 +128,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
32442 return !instr_lo || (instr_lo>>1) == 1;
32443 case 0x00:
32444 /* Prefetch instruction is 0x0F0D or 0x0F18 */
32445- if (probe_kernel_address(instr, opcode))
32446+ if (user_mode(regs)) {
32447+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
32448+ return 0;
32449+ } else if (probe_kernel_address(instr, opcode))
32450 return 0;
32451
32452 *prefetch = (instr_lo == 0xF) &&
32453@@ -155,7 +165,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
32454 while (instr < max_instr) {
32455 unsigned char opcode;
32456
32457- if (probe_kernel_address(instr, opcode))
32458+ if (user_mode(regs)) {
32459+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
32460+ break;
32461+ } else if (probe_kernel_address(instr, opcode))
32462 break;
32463
32464 instr++;
32465@@ -186,6 +199,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
32466 force_sig_info(si_signo, &info, tsk);
32467 }
32468
32469+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32470+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
32471+#endif
32472+
32473+#ifdef CONFIG_PAX_EMUTRAMP
32474+static int pax_handle_fetch_fault(struct pt_regs *regs);
32475+#endif
32476+
32477+#ifdef CONFIG_PAX_PAGEEXEC
32478+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
32479+{
32480+ pgd_t *pgd;
32481+ pud_t *pud;
32482+ pmd_t *pmd;
32483+
32484+ pgd = pgd_offset(mm, address);
32485+ if (!pgd_present(*pgd))
32486+ return NULL;
32487+ pud = pud_offset(pgd, address);
32488+ if (!pud_present(*pud))
32489+ return NULL;
32490+ pmd = pmd_offset(pud, address);
32491+ if (!pmd_present(*pmd))
32492+ return NULL;
32493+ return pmd;
32494+}
32495+#endif
32496+
32497 DEFINE_SPINLOCK(pgd_lock);
32498 LIST_HEAD(pgd_list);
32499
32500@@ -236,10 +277,27 @@ void vmalloc_sync_all(void)
32501 for (address = VMALLOC_START & PMD_MASK;
32502 address >= TASK_SIZE && address < FIXADDR_TOP;
32503 address += PMD_SIZE) {
32504+
32505+#ifdef CONFIG_PAX_PER_CPU_PGD
32506+ unsigned long cpu;
32507+#else
32508 struct page *page;
32509+#endif
32510
32511 spin_lock(&pgd_lock);
32512+
32513+#ifdef CONFIG_PAX_PER_CPU_PGD
32514+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32515+ pgd_t *pgd = get_cpu_pgd(cpu, user);
32516+ pmd_t *ret;
32517+
32518+ ret = vmalloc_sync_one(pgd, address);
32519+ if (!ret)
32520+ break;
32521+ pgd = get_cpu_pgd(cpu, kernel);
32522+#else
32523 list_for_each_entry(page, &pgd_list, lru) {
32524+ pgd_t *pgd;
32525 spinlock_t *pgt_lock;
32526 pmd_t *ret;
32527
32528@@ -247,8 +305,14 @@ void vmalloc_sync_all(void)
32529 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32530
32531 spin_lock(pgt_lock);
32532- ret = vmalloc_sync_one(page_address(page), address);
32533+ pgd = page_address(page);
32534+#endif
32535+
32536+ ret = vmalloc_sync_one(pgd, address);
32537+
32538+#ifndef CONFIG_PAX_PER_CPU_PGD
32539 spin_unlock(pgt_lock);
32540+#endif
32541
32542 if (!ret)
32543 break;
32544@@ -282,6 +346,12 @@ static noinline int vmalloc_fault(unsigned long address)
32545 * an interrupt in the middle of a task switch..
32546 */
32547 pgd_paddr = read_cr3();
32548+
32549+#ifdef CONFIG_PAX_PER_CPU_PGD
32550+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
32551+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
32552+#endif
32553+
32554 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
32555 if (!pmd_k)
32556 return -1;
32557@@ -378,11 +448,25 @@ static noinline int vmalloc_fault(unsigned long address)
32558 * happen within a race in page table update. In the later
32559 * case just flush:
32560 */
32561- pgd = pgd_offset(current->active_mm, address);
32562+
32563 pgd_ref = pgd_offset_k(address);
32564 if (pgd_none(*pgd_ref))
32565 return -1;
32566
32567+#ifdef CONFIG_PAX_PER_CPU_PGD
32568+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
32569+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
32570+ if (pgd_none(*pgd)) {
32571+ set_pgd(pgd, *pgd_ref);
32572+ arch_flush_lazy_mmu_mode();
32573+ } else {
32574+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
32575+ }
32576+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
32577+#else
32578+ pgd = pgd_offset(current->active_mm, address);
32579+#endif
32580+
32581 if (pgd_none(*pgd)) {
32582 set_pgd(pgd, *pgd_ref);
32583 arch_flush_lazy_mmu_mode();
32584@@ -549,7 +633,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
32585 static int is_errata100(struct pt_regs *regs, unsigned long address)
32586 {
32587 #ifdef CONFIG_X86_64
32588- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
32589+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
32590 return 1;
32591 #endif
32592 return 0;
32593@@ -576,9 +660,9 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
32594 }
32595
32596 static const char nx_warning[] = KERN_CRIT
32597-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
32598+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
32599 static const char smep_warning[] = KERN_CRIT
32600-"unable to execute userspace code (SMEP?) (uid: %d)\n";
32601+"unable to execute userspace code (SMEP?) (uid: %d, task: %s, pid: %d)\n";
32602
32603 static void
32604 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32605@@ -587,7 +671,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32606 if (!oops_may_print())
32607 return;
32608
32609- if (error_code & PF_INSTR) {
32610+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
32611 unsigned int level;
32612 pgd_t *pgd;
32613 pte_t *pte;
32614@@ -598,13 +682,25 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
32615 pte = lookup_address_in_pgd(pgd, address, &level);
32616
32617 if (pte && pte_present(*pte) && !pte_exec(*pte))
32618- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
32619+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32620 if (pte && pte_present(*pte) && pte_exec(*pte) &&
32621 (pgd_flags(*pgd) & _PAGE_USER) &&
32622 (read_cr4() & X86_CR4_SMEP))
32623- printk(smep_warning, from_kuid(&init_user_ns, current_uid()));
32624+ printk(smep_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
32625 }
32626
32627+#ifdef CONFIG_PAX_KERNEXEC
32628+ if (init_mm.start_code <= address && address < init_mm.end_code) {
32629+ if (current->signal->curr_ip)
32630+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
32631+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
32632+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32633+ else
32634+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
32635+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
32636+ }
32637+#endif
32638+
32639 printk(KERN_ALERT "BUG: unable to handle kernel ");
32640 if (address < PAGE_SIZE)
32641 printk(KERN_CONT "NULL pointer dereference");
32642@@ -785,6 +881,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
32643 return;
32644 }
32645 #endif
32646+
32647+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32648+ if (pax_is_fetch_fault(regs, error_code, address)) {
32649+
32650+#ifdef CONFIG_PAX_EMUTRAMP
32651+ switch (pax_handle_fetch_fault(regs)) {
32652+ case 2:
32653+ return;
32654+ }
32655+#endif
32656+
32657+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32658+ do_group_exit(SIGKILL);
32659+ }
32660+#endif
32661+
32662 /* Kernel addresses are always protection faults: */
32663 if (address >= TASK_SIZE)
32664 error_code |= PF_PROT;
32665@@ -870,7 +982,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
32666 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
32667 printk(KERN_ERR
32668 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
32669- tsk->comm, tsk->pid, address);
32670+ tsk->comm, task_pid_nr(tsk), address);
32671 code = BUS_MCEERR_AR;
32672 }
32673 #endif
32674@@ -924,6 +1036,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
32675 return 1;
32676 }
32677
32678+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32679+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
32680+{
32681+ pte_t *pte;
32682+ pmd_t *pmd;
32683+ spinlock_t *ptl;
32684+ unsigned char pte_mask;
32685+
32686+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
32687+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
32688+ return 0;
32689+
32690+ /* PaX: it's our fault, let's handle it if we can */
32691+
32692+ /* PaX: take a look at read faults before acquiring any locks */
32693+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
32694+ /* instruction fetch attempt from a protected page in user mode */
32695+ up_read(&mm->mmap_sem);
32696+
32697+#ifdef CONFIG_PAX_EMUTRAMP
32698+ switch (pax_handle_fetch_fault(regs)) {
32699+ case 2:
32700+ return 1;
32701+ }
32702+#endif
32703+
32704+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
32705+ do_group_exit(SIGKILL);
32706+ }
32707+
32708+ pmd = pax_get_pmd(mm, address);
32709+ if (unlikely(!pmd))
32710+ return 0;
32711+
32712+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
32713+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
32714+ pte_unmap_unlock(pte, ptl);
32715+ return 0;
32716+ }
32717+
32718+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
32719+ /* write attempt to a protected page in user mode */
32720+ pte_unmap_unlock(pte, ptl);
32721+ return 0;
32722+ }
32723+
32724+#ifdef CONFIG_SMP
32725+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
32726+#else
32727+ if (likely(address > get_limit(regs->cs)))
32728+#endif
32729+ {
32730+ set_pte(pte, pte_mkread(*pte));
32731+ __flush_tlb_one(address);
32732+ pte_unmap_unlock(pte, ptl);
32733+ up_read(&mm->mmap_sem);
32734+ return 1;
32735+ }
32736+
32737+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
32738+
32739+ /*
32740+ * PaX: fill DTLB with user rights and retry
32741+ */
32742+ __asm__ __volatile__ (
32743+ "orb %2,(%1)\n"
32744+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
32745+/*
32746+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
32747+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
32748+ * page fault when examined during a TLB load attempt. this is true not only
32749+ * for PTEs holding a non-present entry but also present entries that will
32750+ * raise a page fault (such as those set up by PaX, or the copy-on-write
32751+ * mechanism). in effect it means that we do *not* need to flush the TLBs
32752+ * for our target pages since their PTEs are simply not in the TLBs at all.
32753+
32754+ * the best thing in omitting it is that we gain around 15-20% speed in the
32755+ * fast path of the page fault handler and can get rid of tracing since we
32756+ * can no longer flush unintended entries.
32757+ */
32758+ "invlpg (%0)\n"
32759+#endif
32760+ __copyuser_seg"testb $0,(%0)\n"
32761+ "xorb %3,(%1)\n"
32762+ :
32763+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
32764+ : "memory", "cc");
32765+ pte_unmap_unlock(pte, ptl);
32766+ up_read(&mm->mmap_sem);
32767+ return 1;
32768+}
32769+#endif
32770+
32771 /*
32772 * Handle a spurious fault caused by a stale TLB entry.
32773 *
32774@@ -991,6 +1196,9 @@ int show_unhandled_signals = 1;
32775 static inline int
32776 access_error(unsigned long error_code, struct vm_area_struct *vma)
32777 {
32778+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
32779+ return 1;
32780+
32781 if (error_code & PF_WRITE) {
32782 /* write, present and write, not present: */
32783 if (unlikely(!(vma->vm_flags & VM_WRITE)))
32784@@ -1025,7 +1233,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
32785 if (error_code & PF_USER)
32786 return false;
32787
32788- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
32789+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
32790 return false;
32791
32792 return true;
32793@@ -1053,6 +1261,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32794 tsk = current;
32795 mm = tsk->mm;
32796
32797+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32798+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
32799+ if (!search_exception_tables(regs->ip)) {
32800+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32801+ bad_area_nosemaphore(regs, error_code, address);
32802+ return;
32803+ }
32804+ if (address < pax_user_shadow_base) {
32805+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
32806+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
32807+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
32808+ } else
32809+ address -= pax_user_shadow_base;
32810+ }
32811+#endif
32812+
32813 /*
32814 * Detect and handle instructions that would cause a page fault for
32815 * both a tracked kernel page and a userspace page.
32816@@ -1130,7 +1354,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
32817 * User-mode registers count as a user access even for any
32818 * potential system fault or CPU buglet:
32819 */
32820- if (user_mode_vm(regs)) {
32821+ if (user_mode(regs)) {
32822 local_irq_enable();
32823 error_code |= PF_USER;
32824 flags |= FAULT_FLAG_USER;
32825@@ -1177,6 +1401,11 @@ retry:
32826 might_sleep();
32827 }
32828
32829+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
32830+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
32831+ return;
32832+#endif
32833+
32834 vma = find_vma(mm, address);
32835 if (unlikely(!vma)) {
32836 bad_area(regs, error_code, address);
32837@@ -1188,18 +1417,24 @@ retry:
32838 bad_area(regs, error_code, address);
32839 return;
32840 }
32841- if (error_code & PF_USER) {
32842- /*
32843- * Accessing the stack below %sp is always a bug.
32844- * The large cushion allows instructions like enter
32845- * and pusha to work. ("enter $65535, $31" pushes
32846- * 32 pointers and then decrements %sp by 65535.)
32847- */
32848- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
32849- bad_area(regs, error_code, address);
32850- return;
32851- }
32852+ /*
32853+ * Accessing the stack below %sp is always a bug.
32854+ * The large cushion allows instructions like enter
32855+ * and pusha to work. ("enter $65535, $31" pushes
32856+ * 32 pointers and then decrements %sp by 65535.)
32857+ */
32858+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
32859+ bad_area(regs, error_code, address);
32860+ return;
32861 }
32862+
32863+#ifdef CONFIG_PAX_SEGMEXEC
32864+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
32865+ bad_area(regs, error_code, address);
32866+ return;
32867+ }
32868+#endif
32869+
32870 if (unlikely(expand_stack(vma, address))) {
32871 bad_area(regs, error_code, address);
32872 return;
32873@@ -1316,3 +1551,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
32874 }
32875 NOKPROBE_SYMBOL(trace_do_page_fault);
32876 #endif /* CONFIG_TRACING */
32877+
32878+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32879+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
32880+{
32881+ struct mm_struct *mm = current->mm;
32882+ unsigned long ip = regs->ip;
32883+
32884+ if (v8086_mode(regs))
32885+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
32886+
32887+#ifdef CONFIG_PAX_PAGEEXEC
32888+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
32889+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
32890+ return true;
32891+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
32892+ return true;
32893+ return false;
32894+ }
32895+#endif
32896+
32897+#ifdef CONFIG_PAX_SEGMEXEC
32898+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
32899+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
32900+ return true;
32901+ return false;
32902+ }
32903+#endif
32904+
32905+ return false;
32906+}
32907+#endif
32908+
32909+#ifdef CONFIG_PAX_EMUTRAMP
32910+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
32911+{
32912+ int err;
32913+
32914+ do { /* PaX: libffi trampoline emulation */
32915+ unsigned char mov, jmp;
32916+ unsigned int addr1, addr2;
32917+
32918+#ifdef CONFIG_X86_64
32919+ if ((regs->ip + 9) >> 32)
32920+ break;
32921+#endif
32922+
32923+ err = get_user(mov, (unsigned char __user *)regs->ip);
32924+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32925+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32926+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32927+
32928+ if (err)
32929+ break;
32930+
32931+ if (mov == 0xB8 && jmp == 0xE9) {
32932+ regs->ax = addr1;
32933+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32934+ return 2;
32935+ }
32936+ } while (0);
32937+
32938+ do { /* PaX: gcc trampoline emulation #1 */
32939+ unsigned char mov1, mov2;
32940+ unsigned short jmp;
32941+ unsigned int addr1, addr2;
32942+
32943+#ifdef CONFIG_X86_64
32944+ if ((regs->ip + 11) >> 32)
32945+ break;
32946+#endif
32947+
32948+ err = get_user(mov1, (unsigned char __user *)regs->ip);
32949+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32950+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
32951+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32952+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
32953+
32954+ if (err)
32955+ break;
32956+
32957+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
32958+ regs->cx = addr1;
32959+ regs->ax = addr2;
32960+ regs->ip = addr2;
32961+ return 2;
32962+ }
32963+ } while (0);
32964+
32965+ do { /* PaX: gcc trampoline emulation #2 */
32966+ unsigned char mov, jmp;
32967+ unsigned int addr1, addr2;
32968+
32969+#ifdef CONFIG_X86_64
32970+ if ((regs->ip + 9) >> 32)
32971+ break;
32972+#endif
32973+
32974+ err = get_user(mov, (unsigned char __user *)regs->ip);
32975+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
32976+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
32977+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
32978+
32979+ if (err)
32980+ break;
32981+
32982+ if (mov == 0xB9 && jmp == 0xE9) {
32983+ regs->cx = addr1;
32984+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
32985+ return 2;
32986+ }
32987+ } while (0);
32988+
32989+ return 1; /* PaX in action */
32990+}
32991+
32992+#ifdef CONFIG_X86_64
32993+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
32994+{
32995+ int err;
32996+
32997+ do { /* PaX: libffi trampoline emulation */
32998+ unsigned short mov1, mov2, jmp1;
32999+ unsigned char stcclc, jmp2;
33000+ unsigned long addr1, addr2;
33001+
33002+ err = get_user(mov1, (unsigned short __user *)regs->ip);
33003+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
33004+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
33005+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
33006+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
33007+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
33008+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
33009+
33010+ if (err)
33011+ break;
33012+
33013+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33014+ regs->r11 = addr1;
33015+ regs->r10 = addr2;
33016+ if (stcclc == 0xF8)
33017+ regs->flags &= ~X86_EFLAGS_CF;
33018+ else
33019+ regs->flags |= X86_EFLAGS_CF;
33020+ regs->ip = addr1;
33021+ return 2;
33022+ }
33023+ } while (0);
33024+
33025+ do { /* PaX: gcc trampoline emulation #1 */
33026+ unsigned short mov1, mov2, jmp1;
33027+ unsigned char jmp2;
33028+ unsigned int addr1;
33029+ unsigned long addr2;
33030+
33031+ err = get_user(mov1, (unsigned short __user *)regs->ip);
33032+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
33033+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
33034+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
33035+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
33036+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
33037+
33038+ if (err)
33039+ break;
33040+
33041+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33042+ regs->r11 = addr1;
33043+ regs->r10 = addr2;
33044+ regs->ip = addr1;
33045+ return 2;
33046+ }
33047+ } while (0);
33048+
33049+ do { /* PaX: gcc trampoline emulation #2 */
33050+ unsigned short mov1, mov2, jmp1;
33051+ unsigned char jmp2;
33052+ unsigned long addr1, addr2;
33053+
33054+ err = get_user(mov1, (unsigned short __user *)regs->ip);
33055+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
33056+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
33057+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
33058+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
33059+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
33060+
33061+ if (err)
33062+ break;
33063+
33064+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
33065+ regs->r11 = addr1;
33066+ regs->r10 = addr2;
33067+ regs->ip = addr1;
33068+ return 2;
33069+ }
33070+ } while (0);
33071+
33072+ return 1; /* PaX in action */
33073+}
33074+#endif
33075+
33076+/*
33077+ * PaX: decide what to do with offenders (regs->ip = fault address)
33078+ *
33079+ * returns 1 when task should be killed
33080+ * 2 when gcc trampoline was detected
33081+ */
33082+static int pax_handle_fetch_fault(struct pt_regs *regs)
33083+{
33084+ if (v8086_mode(regs))
33085+ return 1;
33086+
33087+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
33088+ return 1;
33089+
33090+#ifdef CONFIG_X86_32
33091+ return pax_handle_fetch_fault_32(regs);
33092+#else
33093+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
33094+ return pax_handle_fetch_fault_32(regs);
33095+ else
33096+ return pax_handle_fetch_fault_64(regs);
33097+#endif
33098+}
33099+#endif
33100+
33101+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33102+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
33103+{
33104+ long i;
33105+
33106+ printk(KERN_ERR "PAX: bytes at PC: ");
33107+ for (i = 0; i < 20; i++) {
33108+ unsigned char c;
33109+ if (get_user(c, (unsigned char __force_user *)pc+i))
33110+ printk(KERN_CONT "?? ");
33111+ else
33112+ printk(KERN_CONT "%02x ", c);
33113+ }
33114+ printk("\n");
33115+
33116+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
33117+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
33118+ unsigned long c;
33119+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
33120+#ifdef CONFIG_X86_32
33121+ printk(KERN_CONT "???????? ");
33122+#else
33123+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
33124+ printk(KERN_CONT "???????? ???????? ");
33125+ else
33126+ printk(KERN_CONT "???????????????? ");
33127+#endif
33128+ } else {
33129+#ifdef CONFIG_X86_64
33130+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
33131+ printk(KERN_CONT "%08x ", (unsigned int)c);
33132+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
33133+ } else
33134+#endif
33135+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
33136+ }
33137+ }
33138+ printk("\n");
33139+}
33140+#endif
33141+
33142+/**
33143+ * probe_kernel_write(): safely attempt to write to a location
33144+ * @dst: address to write to
33145+ * @src: pointer to the data that shall be written
33146+ * @size: size of the data chunk
33147+ *
33148+ * Safely write to address @dst from the buffer at @src. If a kernel fault
33149+ * happens, handle that and return -EFAULT.
33150+ */
33151+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
33152+{
33153+ long ret;
33154+ mm_segment_t old_fs = get_fs();
33155+
33156+ set_fs(KERNEL_DS);
33157+ pagefault_disable();
33158+ pax_open_kernel();
33159+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
33160+ pax_close_kernel();
33161+ pagefault_enable();
33162+ set_fs(old_fs);
33163+
33164+ return ret ? -EFAULT : 0;
33165+}
33166diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
33167index 207d9aef..69030980 100644
33168--- a/arch/x86/mm/gup.c
33169+++ b/arch/x86/mm/gup.c
33170@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
33171 addr = start;
33172 len = (unsigned long) nr_pages << PAGE_SHIFT;
33173 end = start + len;
33174- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
33175+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
33176 (void __user *)start, len)))
33177 return 0;
33178
33179@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
33180 goto slow_irqon;
33181 #endif
33182
33183+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
33184+ (void __user *)start, len)))
33185+ return 0;
33186+
33187 /*
33188 * XXX: batch / limit 'nr', to avoid large irq off latency
33189 * needs some instrumenting to determine the common sizes used by
33190diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
33191index 4500142..53a363c 100644
33192--- a/arch/x86/mm/highmem_32.c
33193+++ b/arch/x86/mm/highmem_32.c
33194@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
33195 idx = type + KM_TYPE_NR*smp_processor_id();
33196 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33197 BUG_ON(!pte_none(*(kmap_pte-idx)));
33198+
33199+ pax_open_kernel();
33200 set_pte(kmap_pte-idx, mk_pte(page, prot));
33201+ pax_close_kernel();
33202+
33203 arch_flush_lazy_mmu_mode();
33204
33205 return (void *)vaddr;
33206diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
33207index 8b977eb..4732c33 100644
33208--- a/arch/x86/mm/hugetlbpage.c
33209+++ b/arch/x86/mm/hugetlbpage.c
33210@@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
33211 #ifdef CONFIG_HUGETLB_PAGE
33212 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
33213 unsigned long addr, unsigned long len,
33214- unsigned long pgoff, unsigned long flags)
33215+ unsigned long pgoff, unsigned long flags, unsigned long offset)
33216 {
33217 struct hstate *h = hstate_file(file);
33218 struct vm_unmapped_area_info info;
33219-
33220+
33221 info.flags = 0;
33222 info.length = len;
33223 info.low_limit = current->mm->mmap_legacy_base;
33224 info.high_limit = TASK_SIZE;
33225 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
33226 info.align_offset = 0;
33227+ info.threadstack_offset = offset;
33228 return vm_unmapped_area(&info);
33229 }
33230
33231 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33232 unsigned long addr0, unsigned long len,
33233- unsigned long pgoff, unsigned long flags)
33234+ unsigned long pgoff, unsigned long flags, unsigned long offset)
33235 {
33236 struct hstate *h = hstate_file(file);
33237 struct vm_unmapped_area_info info;
33238@@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33239 info.high_limit = current->mm->mmap_base;
33240 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
33241 info.align_offset = 0;
33242+ info.threadstack_offset = offset;
33243 addr = vm_unmapped_area(&info);
33244
33245 /*
33246@@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
33247 VM_BUG_ON(addr != -ENOMEM);
33248 info.flags = 0;
33249 info.low_limit = TASK_UNMAPPED_BASE;
33250+
33251+#ifdef CONFIG_PAX_RANDMMAP
33252+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
33253+ info.low_limit += current->mm->delta_mmap;
33254+#endif
33255+
33256 info.high_limit = TASK_SIZE;
33257 addr = vm_unmapped_area(&info);
33258 }
33259@@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
33260 struct hstate *h = hstate_file(file);
33261 struct mm_struct *mm = current->mm;
33262 struct vm_area_struct *vma;
33263+ unsigned long pax_task_size = TASK_SIZE;
33264+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
33265
33266 if (len & ~huge_page_mask(h))
33267 return -EINVAL;
33268- if (len > TASK_SIZE)
33269+
33270+#ifdef CONFIG_PAX_SEGMEXEC
33271+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
33272+ pax_task_size = SEGMEXEC_TASK_SIZE;
33273+#endif
33274+
33275+ pax_task_size -= PAGE_SIZE;
33276+
33277+ if (len > pax_task_size)
33278 return -ENOMEM;
33279
33280 if (flags & MAP_FIXED) {
33281@@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
33282 return addr;
33283 }
33284
33285+#ifdef CONFIG_PAX_RANDMMAP
33286+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
33287+#endif
33288+
33289 if (addr) {
33290 addr = ALIGN(addr, huge_page_size(h));
33291 vma = find_vma(mm, addr);
33292- if (TASK_SIZE - len >= addr &&
33293- (!vma || addr + len <= vma->vm_start))
33294+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
33295 return addr;
33296 }
33297 if (mm->get_unmapped_area == arch_get_unmapped_area)
33298 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
33299- pgoff, flags);
33300+ pgoff, flags, offset);
33301 else
33302 return hugetlb_get_unmapped_area_topdown(file, addr, len,
33303- pgoff, flags);
33304+ pgoff, flags, offset);
33305 }
33306 #endif /* CONFIG_HUGETLB_PAGE */
33307
33308diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
33309index 66dba36..f8082ec 100644
33310--- a/arch/x86/mm/init.c
33311+++ b/arch/x86/mm/init.c
33312@@ -4,6 +4,7 @@
33313 #include <linux/swap.h>
33314 #include <linux/memblock.h>
33315 #include <linux/bootmem.h> /* for max_low_pfn */
33316+#include <linux/tboot.h>
33317
33318 #include <asm/cacheflush.h>
33319 #include <asm/e820.h>
33320@@ -17,6 +18,8 @@
33321 #include <asm/proto.h>
33322 #include <asm/dma.h> /* for MAX_DMA_PFN */
33323 #include <asm/microcode.h>
33324+#include <asm/desc.h>
33325+#include <asm/bios_ebda.h>
33326
33327 /*
33328 * We need to define the tracepoints somewhere, and tlb.c
33329@@ -570,7 +573,18 @@ void __init init_mem_mapping(void)
33330 early_ioremap_page_table_range_init();
33331 #endif
33332
33333+#ifdef CONFIG_PAX_PER_CPU_PGD
33334+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
33335+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
33336+ KERNEL_PGD_PTRS);
33337+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
33338+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
33339+ KERNEL_PGD_PTRS);
33340+ load_cr3(get_cpu_pgd(0, kernel));
33341+#else
33342 load_cr3(swapper_pg_dir);
33343+#endif
33344+
33345 __flush_tlb_all();
33346
33347 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
33348@@ -586,10 +600,40 @@ void __init init_mem_mapping(void)
33349 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
33350 * mmio resources as well as potential bios/acpi data regions.
33351 */
33352+
33353+#ifdef CONFIG_GRKERNSEC_KMEM
33354+static unsigned int ebda_start __read_only;
33355+static unsigned int ebda_end __read_only;
33356+#endif
33357+
33358 int devmem_is_allowed(unsigned long pagenr)
33359 {
33360- if (pagenr < 256)
33361+#ifdef CONFIG_GRKERNSEC_KMEM
33362+ /* allow BDA */
33363+ if (!pagenr)
33364 return 1;
33365+ /* allow EBDA */
33366+ if (pagenr >= ebda_start && pagenr < ebda_end)
33367+ return 1;
33368+ /* if tboot is in use, allow access to its hardcoded serial log range */
33369+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
33370+ return 1;
33371+#else
33372+ if (!pagenr)
33373+ return 1;
33374+#ifdef CONFIG_VM86
33375+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
33376+ return 1;
33377+#endif
33378+#endif
33379+
33380+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
33381+ return 1;
33382+#ifdef CONFIG_GRKERNSEC_KMEM
33383+ /* throw out everything else below 1MB */
33384+ if (pagenr <= 256)
33385+ return 0;
33386+#endif
33387 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
33388 return 0;
33389 if (!page_is_ram(pagenr))
33390@@ -635,8 +679,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
33391 #endif
33392 }
33393
33394+#ifdef CONFIG_GRKERNSEC_KMEM
33395+static inline void gr_init_ebda(void)
33396+{
33397+ unsigned int ebda_addr;
33398+ unsigned int ebda_size = 0;
33399+
33400+ ebda_addr = get_bios_ebda();
33401+ if (ebda_addr) {
33402+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
33403+ ebda_size <<= 10;
33404+ }
33405+ if (ebda_addr && ebda_size) {
33406+ ebda_start = ebda_addr >> PAGE_SHIFT;
33407+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
33408+ } else {
33409+ ebda_start = 0x9f000 >> PAGE_SHIFT;
33410+ ebda_end = 0xa0000 >> PAGE_SHIFT;
33411+ }
33412+}
33413+#else
33414+static inline void gr_init_ebda(void) { }
33415+#endif
33416+
33417 void free_initmem(void)
33418 {
33419+#ifdef CONFIG_PAX_KERNEXEC
33420+#ifdef CONFIG_X86_32
33421+ /* PaX: limit KERNEL_CS to actual size */
33422+ unsigned long addr, limit;
33423+ struct desc_struct d;
33424+ int cpu;
33425+#else
33426+ pgd_t *pgd;
33427+ pud_t *pud;
33428+ pmd_t *pmd;
33429+ unsigned long addr, end;
33430+#endif
33431+#endif
33432+
33433+ gr_init_ebda();
33434+
33435+#ifdef CONFIG_PAX_KERNEXEC
33436+#ifdef CONFIG_X86_32
33437+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
33438+ limit = (limit - 1UL) >> PAGE_SHIFT;
33439+
33440+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
33441+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
33442+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
33443+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
33444+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
33445+ }
33446+
33447+ /* PaX: make KERNEL_CS read-only */
33448+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
33449+ if (!paravirt_enabled())
33450+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
33451+/*
33452+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
33453+ pgd = pgd_offset_k(addr);
33454+ pud = pud_offset(pgd, addr);
33455+ pmd = pmd_offset(pud, addr);
33456+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33457+ }
33458+*/
33459+#ifdef CONFIG_X86_PAE
33460+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
33461+/*
33462+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
33463+ pgd = pgd_offset_k(addr);
33464+ pud = pud_offset(pgd, addr);
33465+ pmd = pmd_offset(pud, addr);
33466+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
33467+ }
33468+*/
33469+#endif
33470+
33471+#ifdef CONFIG_MODULES
33472+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
33473+#endif
33474+
33475+#else
33476+ /* PaX: make kernel code/rodata read-only, rest non-executable */
33477+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
33478+ pgd = pgd_offset_k(addr);
33479+ pud = pud_offset(pgd, addr);
33480+ pmd = pmd_offset(pud, addr);
33481+ if (!pmd_present(*pmd))
33482+ continue;
33483+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
33484+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33485+ else
33486+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
33487+ }
33488+
33489+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
33490+ end = addr + KERNEL_IMAGE_SIZE;
33491+ for (; addr < end; addr += PMD_SIZE) {
33492+ pgd = pgd_offset_k(addr);
33493+ pud = pud_offset(pgd, addr);
33494+ pmd = pmd_offset(pud, addr);
33495+ if (!pmd_present(*pmd))
33496+ continue;
33497+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
33498+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
33499+ }
33500+#endif
33501+
33502+ flush_tlb_all();
33503+#endif
33504+
33505 free_init_pages("unused kernel",
33506 (unsigned long)(&__init_begin),
33507 (unsigned long)(&__init_end));
33508diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
33509index 7d05565..bfc5338 100644
33510--- a/arch/x86/mm/init_32.c
33511+++ b/arch/x86/mm/init_32.c
33512@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
33513 bool __read_mostly __vmalloc_start_set = false;
33514
33515 /*
33516- * Creates a middle page table and puts a pointer to it in the
33517- * given global directory entry. This only returns the gd entry
33518- * in non-PAE compilation mode, since the middle layer is folded.
33519- */
33520-static pmd_t * __init one_md_table_init(pgd_t *pgd)
33521-{
33522- pud_t *pud;
33523- pmd_t *pmd_table;
33524-
33525-#ifdef CONFIG_X86_PAE
33526- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
33527- pmd_table = (pmd_t *)alloc_low_page();
33528- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
33529- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
33530- pud = pud_offset(pgd, 0);
33531- BUG_ON(pmd_table != pmd_offset(pud, 0));
33532-
33533- return pmd_table;
33534- }
33535-#endif
33536- pud = pud_offset(pgd, 0);
33537- pmd_table = pmd_offset(pud, 0);
33538-
33539- return pmd_table;
33540-}
33541-
33542-/*
33543 * Create a page table and place a pointer to it in a middle page
33544 * directory entry:
33545 */
33546@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
33547 pte_t *page_table = (pte_t *)alloc_low_page();
33548
33549 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
33550+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
33551+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
33552+#else
33553 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
33554+#endif
33555 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
33556 }
33557
33558 return pte_offset_kernel(pmd, 0);
33559 }
33560
33561+static pmd_t * __init one_md_table_init(pgd_t *pgd)
33562+{
33563+ pud_t *pud;
33564+ pmd_t *pmd_table;
33565+
33566+ pud = pud_offset(pgd, 0);
33567+ pmd_table = pmd_offset(pud, 0);
33568+
33569+ return pmd_table;
33570+}
33571+
33572 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
33573 {
33574 int pgd_idx = pgd_index(vaddr);
33575@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33576 int pgd_idx, pmd_idx;
33577 unsigned long vaddr;
33578 pgd_t *pgd;
33579+ pud_t *pud;
33580 pmd_t *pmd;
33581 pte_t *pte = NULL;
33582 unsigned long count = page_table_range_init_count(start, end);
33583@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33584 pgd = pgd_base + pgd_idx;
33585
33586 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
33587- pmd = one_md_table_init(pgd);
33588- pmd = pmd + pmd_index(vaddr);
33589+ pud = pud_offset(pgd, vaddr);
33590+ pmd = pmd_offset(pud, vaddr);
33591+
33592+#ifdef CONFIG_X86_PAE
33593+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33594+#endif
33595+
33596 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
33597 pmd++, pmd_idx++) {
33598 pte = page_table_kmap_check(one_page_table_init(pmd),
33599@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
33600 }
33601 }
33602
33603-static inline int is_kernel_text(unsigned long addr)
33604+static inline int is_kernel_text(unsigned long start, unsigned long end)
33605 {
33606- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
33607- return 1;
33608- return 0;
33609+ if ((start >= ktla_ktva((unsigned long)_etext) ||
33610+ end <= ktla_ktva((unsigned long)_stext)) &&
33611+ (start >= ktla_ktva((unsigned long)_einittext) ||
33612+ end <= ktla_ktva((unsigned long)_sinittext)) &&
33613+
33614+#ifdef CONFIG_ACPI_SLEEP
33615+ (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
33616+#endif
33617+
33618+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
33619+ return 0;
33620+ return 1;
33621 }
33622
33623 /*
33624@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
33625 unsigned long last_map_addr = end;
33626 unsigned long start_pfn, end_pfn;
33627 pgd_t *pgd_base = swapper_pg_dir;
33628- int pgd_idx, pmd_idx, pte_ofs;
33629+ unsigned int pgd_idx, pmd_idx, pte_ofs;
33630 unsigned long pfn;
33631 pgd_t *pgd;
33632+ pud_t *pud;
33633 pmd_t *pmd;
33634 pte_t *pte;
33635 unsigned pages_2m, pages_4k;
33636@@ -291,8 +295,13 @@ repeat:
33637 pfn = start_pfn;
33638 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33639 pgd = pgd_base + pgd_idx;
33640- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
33641- pmd = one_md_table_init(pgd);
33642+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
33643+ pud = pud_offset(pgd, 0);
33644+ pmd = pmd_offset(pud, 0);
33645+
33646+#ifdef CONFIG_X86_PAE
33647+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
33648+#endif
33649
33650 if (pfn >= end_pfn)
33651 continue;
33652@@ -304,14 +313,13 @@ repeat:
33653 #endif
33654 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
33655 pmd++, pmd_idx++) {
33656- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
33657+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
33658
33659 /*
33660 * Map with big pages if possible, otherwise
33661 * create normal page tables:
33662 */
33663 if (use_pse) {
33664- unsigned int addr2;
33665 pgprot_t prot = PAGE_KERNEL_LARGE;
33666 /*
33667 * first pass will use the same initial
33668@@ -322,11 +330,7 @@ repeat:
33669 _PAGE_PSE);
33670
33671 pfn &= PMD_MASK >> PAGE_SHIFT;
33672- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
33673- PAGE_OFFSET + PAGE_SIZE-1;
33674-
33675- if (is_kernel_text(addr) ||
33676- is_kernel_text(addr2))
33677+ if (is_kernel_text(address, address + PMD_SIZE))
33678 prot = PAGE_KERNEL_LARGE_EXEC;
33679
33680 pages_2m++;
33681@@ -343,7 +347,7 @@ repeat:
33682 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
33683 pte += pte_ofs;
33684 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
33685- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
33686+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
33687 pgprot_t prot = PAGE_KERNEL;
33688 /*
33689 * first pass will use the same initial
33690@@ -351,7 +355,7 @@ repeat:
33691 */
33692 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
33693
33694- if (is_kernel_text(addr))
33695+ if (is_kernel_text(address, address + PAGE_SIZE))
33696 prot = PAGE_KERNEL_EXEC;
33697
33698 pages_4k++;
33699@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
33700
33701 pud = pud_offset(pgd, va);
33702 pmd = pmd_offset(pud, va);
33703- if (!pmd_present(*pmd))
33704+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
33705 break;
33706
33707 /* should not be large page here */
33708@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
33709
33710 static void __init pagetable_init(void)
33711 {
33712- pgd_t *pgd_base = swapper_pg_dir;
33713-
33714- permanent_kmaps_init(pgd_base);
33715+ permanent_kmaps_init(swapper_pg_dir);
33716 }
33717
33718-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33719+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
33720 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33721
33722 /* user-defined highmem size */
33723@@ -787,10 +789,10 @@ void __init mem_init(void)
33724 ((unsigned long)&__init_end -
33725 (unsigned long)&__init_begin) >> 10,
33726
33727- (unsigned long)&_etext, (unsigned long)&_edata,
33728- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
33729+ (unsigned long)&_sdata, (unsigned long)&_edata,
33730+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
33731
33732- (unsigned long)&_text, (unsigned long)&_etext,
33733+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
33734 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
33735
33736 /*
33737@@ -884,6 +886,7 @@ void set_kernel_text_rw(void)
33738 if (!kernel_set_to_readonly)
33739 return;
33740
33741+ start = ktla_ktva(start);
33742 pr_debug("Set kernel text: %lx - %lx for read write\n",
33743 start, start+size);
33744
33745@@ -898,6 +901,7 @@ void set_kernel_text_ro(void)
33746 if (!kernel_set_to_readonly)
33747 return;
33748
33749+ start = ktla_ktva(start);
33750 pr_debug("Set kernel text: %lx - %lx for read only\n",
33751 start, start+size);
33752
33753@@ -926,6 +930,7 @@ void mark_rodata_ro(void)
33754 unsigned long start = PFN_ALIGN(_text);
33755 unsigned long size = PFN_ALIGN(_etext) - start;
33756
33757+ start = ktla_ktva(start);
33758 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
33759 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
33760 size >> 10);
33761diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
33762index 5621c47..5e17b7390 100644
33763--- a/arch/x86/mm/init_64.c
33764+++ b/arch/x86/mm/init_64.c
33765@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
33766 * around without checking the pgd every time.
33767 */
33768
33769-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
33770+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
33771 EXPORT_SYMBOL_GPL(__supported_pte_mask);
33772
33773 int force_personality32;
33774@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33775
33776 for (address = start; address <= end; address += PGDIR_SIZE) {
33777 const pgd_t *pgd_ref = pgd_offset_k(address);
33778+
33779+#ifdef CONFIG_PAX_PER_CPU_PGD
33780+ unsigned long cpu;
33781+#else
33782 struct page *page;
33783+#endif
33784
33785 if (pgd_none(*pgd_ref))
33786 continue;
33787
33788 spin_lock(&pgd_lock);
33789+
33790+#ifdef CONFIG_PAX_PER_CPU_PGD
33791+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33792+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
33793+
33794+ if (pgd_none(*pgd))
33795+ set_pgd(pgd, *pgd_ref);
33796+ else
33797+ BUG_ON(pgd_page_vaddr(*pgd)
33798+ != pgd_page_vaddr(*pgd_ref));
33799+ pgd = pgd_offset_cpu(cpu, kernel, address);
33800+#else
33801 list_for_each_entry(page, &pgd_list, lru) {
33802 pgd_t *pgd;
33803 spinlock_t *pgt_lock;
33804@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33805 /* the pgt_lock only for Xen */
33806 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
33807 spin_lock(pgt_lock);
33808+#endif
33809
33810 if (pgd_none(*pgd))
33811 set_pgd(pgd, *pgd_ref);
33812@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
33813 BUG_ON(pgd_page_vaddr(*pgd)
33814 != pgd_page_vaddr(*pgd_ref));
33815
33816+#ifndef CONFIG_PAX_PER_CPU_PGD
33817 spin_unlock(pgt_lock);
33818+#endif
33819+
33820 }
33821 spin_unlock(&pgd_lock);
33822 }
33823@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
33824 {
33825 if (pgd_none(*pgd)) {
33826 pud_t *pud = (pud_t *)spp_getpage();
33827- pgd_populate(&init_mm, pgd, pud);
33828+ pgd_populate_kernel(&init_mm, pgd, pud);
33829 if (pud != pud_offset(pgd, 0))
33830 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
33831 pud, pud_offset(pgd, 0));
33832@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
33833 {
33834 if (pud_none(*pud)) {
33835 pmd_t *pmd = (pmd_t *) spp_getpage();
33836- pud_populate(&init_mm, pud, pmd);
33837+ pud_populate_kernel(&init_mm, pud, pmd);
33838 if (pmd != pmd_offset(pud, 0))
33839 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
33840 pmd, pmd_offset(pud, 0));
33841@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
33842 pmd = fill_pmd(pud, vaddr);
33843 pte = fill_pte(pmd, vaddr);
33844
33845+ pax_open_kernel();
33846 set_pte(pte, new_pte);
33847+ pax_close_kernel();
33848
33849 /*
33850 * It's enough to flush this one mapping.
33851@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
33852 pgd = pgd_offset_k((unsigned long)__va(phys));
33853 if (pgd_none(*pgd)) {
33854 pud = (pud_t *) spp_getpage();
33855- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
33856- _PAGE_USER));
33857+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
33858 }
33859 pud = pud_offset(pgd, (unsigned long)__va(phys));
33860 if (pud_none(*pud)) {
33861 pmd = (pmd_t *) spp_getpage();
33862- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
33863- _PAGE_USER));
33864+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
33865 }
33866 pmd = pmd_offset(pud, phys);
33867 BUG_ON(!pmd_none(*pmd));
33868@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
33869 prot);
33870
33871 spin_lock(&init_mm.page_table_lock);
33872- pud_populate(&init_mm, pud, pmd);
33873+ pud_populate_kernel(&init_mm, pud, pmd);
33874 spin_unlock(&init_mm.page_table_lock);
33875 }
33876 __flush_tlb_all();
33877@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
33878 page_size_mask);
33879
33880 spin_lock(&init_mm.page_table_lock);
33881- pgd_populate(&init_mm, pgd, pud);
33882+ pgd_populate_kernel(&init_mm, pgd, pud);
33883 spin_unlock(&init_mm.page_table_lock);
33884 pgd_changed = true;
33885 }
33886@@ -1196,8 +1217,8 @@ static struct vm_operations_struct gate_vma_ops = {
33887 static struct vm_area_struct gate_vma = {
33888 .vm_start = VSYSCALL_ADDR,
33889 .vm_end = VSYSCALL_ADDR + PAGE_SIZE,
33890- .vm_page_prot = PAGE_READONLY_EXEC,
33891- .vm_flags = VM_READ | VM_EXEC,
33892+ .vm_page_prot = PAGE_READONLY,
33893+ .vm_flags = VM_READ,
33894 .vm_ops = &gate_vma_ops,
33895 };
33896
33897diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
33898index 7b179b49..6bd17777 100644
33899--- a/arch/x86/mm/iomap_32.c
33900+++ b/arch/x86/mm/iomap_32.c
33901@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
33902 type = kmap_atomic_idx_push();
33903 idx = type + KM_TYPE_NR * smp_processor_id();
33904 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
33905+
33906+ pax_open_kernel();
33907 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
33908+ pax_close_kernel();
33909+
33910 arch_flush_lazy_mmu_mode();
33911
33912 return (void *)vaddr;
33913diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
33914index baff1da..2816ef4 100644
33915--- a/arch/x86/mm/ioremap.c
33916+++ b/arch/x86/mm/ioremap.c
33917@@ -56,8 +56,8 @@ static int __ioremap_check_ram(unsigned long start_pfn, unsigned long nr_pages,
33918 unsigned long i;
33919
33920 for (i = 0; i < nr_pages; ++i)
33921- if (pfn_valid(start_pfn + i) &&
33922- !PageReserved(pfn_to_page(start_pfn + i)))
33923+ if (pfn_valid(start_pfn + i) && (start_pfn + i >= 0x100 ||
33924+ !PageReserved(pfn_to_page(start_pfn + i))))
33925 return 1;
33926
33927 WARN_ONCE(1, "ioremap on RAM pfn 0x%lx\n", start_pfn);
33928@@ -268,7 +268,7 @@ EXPORT_SYMBOL(ioremap_prot);
33929 *
33930 * Caller must ensure there is only one unmapping for the same pointer.
33931 */
33932-void iounmap(volatile void __iomem *addr)
33933+void iounmap(const volatile void __iomem *addr)
33934 {
33935 struct vm_struct *p, *o;
33936
33937@@ -322,6 +322,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33938
33939 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
33940 if (page_is_ram(start >> PAGE_SHIFT))
33941+#ifdef CONFIG_HIGHMEM
33942+ if ((start >> PAGE_SHIFT) < max_low_pfn)
33943+#endif
33944 return __va(phys);
33945
33946 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
33947@@ -334,13 +337,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
33948 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
33949 {
33950 if (page_is_ram(phys >> PAGE_SHIFT))
33951+#ifdef CONFIG_HIGHMEM
33952+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
33953+#endif
33954 return;
33955
33956 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
33957 return;
33958 }
33959
33960-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
33961+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
33962
33963 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
33964 {
33965@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
33966 early_ioremap_setup();
33967
33968 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
33969- memset(bm_pte, 0, sizeof(bm_pte));
33970- pmd_populate_kernel(&init_mm, pmd, bm_pte);
33971+ pmd_populate_user(&init_mm, pmd, bm_pte);
33972
33973 /*
33974 * The boot-ioremap range spans multiple pmds, for which
33975diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
33976index dd89a13..d77bdcc 100644
33977--- a/arch/x86/mm/kmemcheck/kmemcheck.c
33978+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
33979@@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
33980 * memory (e.g. tracked pages)? For now, we need this to avoid
33981 * invoking kmemcheck for PnP BIOS calls.
33982 */
33983- if (regs->flags & X86_VM_MASK)
33984+ if (v8086_mode(regs))
33985 return false;
33986- if (regs->cs != __KERNEL_CS)
33987+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
33988 return false;
33989
33990 pte = kmemcheck_pte_lookup(address);
33991diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
33992index 919b912..9267313 100644
33993--- a/arch/x86/mm/mmap.c
33994+++ b/arch/x86/mm/mmap.c
33995@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
33996 * Leave an at least ~128 MB hole with possible stack randomization.
33997 */
33998 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
33999-#define MAX_GAP (TASK_SIZE/6*5)
34000+#define MAX_GAP (pax_task_size/6*5)
34001
34002 static int mmap_is_legacy(void)
34003 {
34004@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
34005 return rnd << PAGE_SHIFT;
34006 }
34007
34008-static unsigned long mmap_base(void)
34009+static unsigned long mmap_base(struct mm_struct *mm)
34010 {
34011 unsigned long gap = rlimit(RLIMIT_STACK);
34012+ unsigned long pax_task_size = TASK_SIZE;
34013+
34014+#ifdef CONFIG_PAX_SEGMEXEC
34015+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
34016+ pax_task_size = SEGMEXEC_TASK_SIZE;
34017+#endif
34018
34019 if (gap < MIN_GAP)
34020 gap = MIN_GAP;
34021 else if (gap > MAX_GAP)
34022 gap = MAX_GAP;
34023
34024- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
34025+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
34026 }
34027
34028 /*
34029 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
34030 * does, but not when emulating X86_32
34031 */
34032-static unsigned long mmap_legacy_base(void)
34033+static unsigned long mmap_legacy_base(struct mm_struct *mm)
34034 {
34035- if (mmap_is_ia32())
34036+ if (mmap_is_ia32()) {
34037+
34038+#ifdef CONFIG_PAX_SEGMEXEC
34039+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
34040+ return SEGMEXEC_TASK_UNMAPPED_BASE;
34041+ else
34042+#endif
34043+
34044 return TASK_UNMAPPED_BASE;
34045- else
34046+ } else
34047 return TASK_UNMAPPED_BASE + mmap_rnd();
34048 }
34049
34050@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
34051 */
34052 void arch_pick_mmap_layout(struct mm_struct *mm)
34053 {
34054- mm->mmap_legacy_base = mmap_legacy_base();
34055- mm->mmap_base = mmap_base();
34056+ mm->mmap_legacy_base = mmap_legacy_base(mm);
34057+ mm->mmap_base = mmap_base(mm);
34058+
34059+#ifdef CONFIG_PAX_RANDMMAP
34060+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
34061+ mm->mmap_legacy_base += mm->delta_mmap;
34062+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
34063+ }
34064+#endif
34065
34066 if (mmap_is_legacy()) {
34067 mm->mmap_base = mm->mmap_legacy_base;
34068diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
34069index 0057a7a..95c7edd 100644
34070--- a/arch/x86/mm/mmio-mod.c
34071+++ b/arch/x86/mm/mmio-mod.c
34072@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
34073 break;
34074 default:
34075 {
34076- unsigned char *ip = (unsigned char *)instptr;
34077+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
34078 my_trace->opcode = MMIO_UNKNOWN_OP;
34079 my_trace->width = 0;
34080 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
34081@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
34082 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
34083 void __iomem *addr)
34084 {
34085- static atomic_t next_id;
34086+ static atomic_unchecked_t next_id;
34087 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
34088 /* These are page-unaligned. */
34089 struct mmiotrace_map map = {
34090@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
34091 .private = trace
34092 },
34093 .phys = offset,
34094- .id = atomic_inc_return(&next_id)
34095+ .id = atomic_inc_return_unchecked(&next_id)
34096 };
34097 map.map_id = trace->id;
34098
34099@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
34100 ioremap_trace_core(offset, size, addr);
34101 }
34102
34103-static void iounmap_trace_core(volatile void __iomem *addr)
34104+static void iounmap_trace_core(const volatile void __iomem *addr)
34105 {
34106 struct mmiotrace_map map = {
34107 .phys = 0,
34108@@ -328,7 +328,7 @@ not_enabled:
34109 }
34110 }
34111
34112-void mmiotrace_iounmap(volatile void __iomem *addr)
34113+void mmiotrace_iounmap(const volatile void __iomem *addr)
34114 {
34115 might_sleep();
34116 if (is_enabled()) /* recheck and proper locking in *_core() */
34117diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
34118index a32b706..efb308b 100644
34119--- a/arch/x86/mm/numa.c
34120+++ b/arch/x86/mm/numa.c
34121@@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
34122 return true;
34123 }
34124
34125-static int __init numa_register_memblks(struct numa_meminfo *mi)
34126+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
34127 {
34128 unsigned long uninitialized_var(pfn_align);
34129 int i, nid;
34130diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
34131index 36de293..b820ddc 100644
34132--- a/arch/x86/mm/pageattr.c
34133+++ b/arch/x86/mm/pageattr.c
34134@@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34135 */
34136 #ifdef CONFIG_PCI_BIOS
34137 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
34138- pgprot_val(forbidden) |= _PAGE_NX;
34139+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34140 #endif
34141
34142 /*
34143@@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34144 * Does not cover __inittext since that is gone later on. On
34145 * 64bit we do not enforce !NX on the low mapping
34146 */
34147- if (within(address, (unsigned long)_text, (unsigned long)_etext))
34148- pgprot_val(forbidden) |= _PAGE_NX;
34149+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
34150+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34151
34152+#ifdef CONFIG_DEBUG_RODATA
34153 /*
34154 * The .rodata section needs to be read-only. Using the pfn
34155 * catches all aliases.
34156@@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34157 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
34158 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
34159 pgprot_val(forbidden) |= _PAGE_RW;
34160+#endif
34161
34162 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
34163 /*
34164@@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
34165 }
34166 #endif
34167
34168+#ifdef CONFIG_PAX_KERNEXEC
34169+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
34170+ pgprot_val(forbidden) |= _PAGE_RW;
34171+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
34172+ }
34173+#endif
34174+
34175 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
34176
34177 return prot;
34178@@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
34179 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
34180 {
34181 /* change init_mm */
34182+ pax_open_kernel();
34183 set_pte_atomic(kpte, pte);
34184+
34185 #ifdef CONFIG_X86_32
34186 if (!SHARED_KERNEL_PMD) {
34187+
34188+#ifdef CONFIG_PAX_PER_CPU_PGD
34189+ unsigned long cpu;
34190+#else
34191 struct page *page;
34192+#endif
34193
34194+#ifdef CONFIG_PAX_PER_CPU_PGD
34195+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
34196+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
34197+#else
34198 list_for_each_entry(page, &pgd_list, lru) {
34199- pgd_t *pgd;
34200+ pgd_t *pgd = (pgd_t *)page_address(page);
34201+#endif
34202+
34203 pud_t *pud;
34204 pmd_t *pmd;
34205
34206- pgd = (pgd_t *)page_address(page) + pgd_index(address);
34207+ pgd += pgd_index(address);
34208 pud = pud_offset(pgd, address);
34209 pmd = pmd_offset(pud, address);
34210 set_pte_atomic((pte_t *)pmd, pte);
34211 }
34212 }
34213 #endif
34214+ pax_close_kernel();
34215 }
34216
34217 static int
34218diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
34219index 6574388..87e9bef 100644
34220--- a/arch/x86/mm/pat.c
34221+++ b/arch/x86/mm/pat.c
34222@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
34223
34224 if (!entry) {
34225 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
34226- current->comm, current->pid, start, end - 1);
34227+ current->comm, task_pid_nr(current), start, end - 1);
34228 return -EINVAL;
34229 }
34230
34231@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
34232
34233 while (cursor < to) {
34234 if (!devmem_is_allowed(pfn)) {
34235- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
34236- current->comm, from, to - 1);
34237+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
34238+ current->comm, from, to - 1, cursor);
34239 return 0;
34240 }
34241 cursor += PAGE_SIZE;
34242@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
34243 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
34244 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
34245 "for [mem %#010Lx-%#010Lx]\n",
34246- current->comm, current->pid,
34247+ current->comm, task_pid_nr(current),
34248 cattr_name(flags),
34249 base, (unsigned long long)(base + size-1));
34250 return -EINVAL;
34251@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
34252 flags = lookup_memtype(paddr);
34253 if (want_flags != flags) {
34254 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
34255- current->comm, current->pid,
34256+ current->comm, task_pid_nr(current),
34257 cattr_name(want_flags),
34258 (unsigned long long)paddr,
34259 (unsigned long long)(paddr + size - 1),
34260@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
34261 free_memtype(paddr, paddr + size);
34262 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
34263 " for [mem %#010Lx-%#010Lx], got %s\n",
34264- current->comm, current->pid,
34265+ current->comm, task_pid_nr(current),
34266 cattr_name(want_flags),
34267 (unsigned long long)paddr,
34268 (unsigned long long)(paddr + size - 1),
34269diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
34270index 415f6c4..d319983 100644
34271--- a/arch/x86/mm/pat_rbtree.c
34272+++ b/arch/x86/mm/pat_rbtree.c
34273@@ -160,7 +160,7 @@ success:
34274
34275 failure:
34276 printk(KERN_INFO "%s:%d conflicting memory types "
34277- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
34278+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
34279 end, cattr_name(found_type), cattr_name(match->type));
34280 return -EBUSY;
34281 }
34282diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
34283index 9f0614d..92ae64a 100644
34284--- a/arch/x86/mm/pf_in.c
34285+++ b/arch/x86/mm/pf_in.c
34286@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
34287 int i;
34288 enum reason_type rv = OTHERS;
34289
34290- p = (unsigned char *)ins_addr;
34291+ p = (unsigned char *)ktla_ktva(ins_addr);
34292 p += skip_prefix(p, &prf);
34293 p += get_opcode(p, &opcode);
34294
34295@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
34296 struct prefix_bits prf;
34297 int i;
34298
34299- p = (unsigned char *)ins_addr;
34300+ p = (unsigned char *)ktla_ktva(ins_addr);
34301 p += skip_prefix(p, &prf);
34302 p += get_opcode(p, &opcode);
34303
34304@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
34305 struct prefix_bits prf;
34306 int i;
34307
34308- p = (unsigned char *)ins_addr;
34309+ p = (unsigned char *)ktla_ktva(ins_addr);
34310 p += skip_prefix(p, &prf);
34311 p += get_opcode(p, &opcode);
34312
34313@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
34314 struct prefix_bits prf;
34315 int i;
34316
34317- p = (unsigned char *)ins_addr;
34318+ p = (unsigned char *)ktla_ktva(ins_addr);
34319 p += skip_prefix(p, &prf);
34320 p += get_opcode(p, &opcode);
34321 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
34322@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
34323 struct prefix_bits prf;
34324 int i;
34325
34326- p = (unsigned char *)ins_addr;
34327+ p = (unsigned char *)ktla_ktva(ins_addr);
34328 p += skip_prefix(p, &prf);
34329 p += get_opcode(p, &opcode);
34330 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
34331diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
34332index 6fb6927..4fc13c0 100644
34333--- a/arch/x86/mm/pgtable.c
34334+++ b/arch/x86/mm/pgtable.c
34335@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
34336 list_del(&page->lru);
34337 }
34338
34339-#define UNSHARED_PTRS_PER_PGD \
34340- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
34341+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
34342+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
34343
34344+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
34345+{
34346+ unsigned int count = USER_PGD_PTRS;
34347
34348+ if (!pax_user_shadow_base)
34349+ return;
34350+
34351+ while (count--)
34352+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
34353+}
34354+#endif
34355+
34356+#ifdef CONFIG_PAX_PER_CPU_PGD
34357+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
34358+{
34359+ unsigned int count = USER_PGD_PTRS;
34360+
34361+ while (count--) {
34362+ pgd_t pgd;
34363+
34364+#ifdef CONFIG_X86_64
34365+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
34366+#else
34367+ pgd = *src++;
34368+#endif
34369+
34370+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
34371+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
34372+#endif
34373+
34374+ *dst++ = pgd;
34375+ }
34376+
34377+}
34378+#endif
34379+
34380+#ifdef CONFIG_X86_64
34381+#define pxd_t pud_t
34382+#define pyd_t pgd_t
34383+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
34384+#define pgtable_pxd_page_ctor(page) true
34385+#define pgtable_pxd_page_dtor(page)
34386+#define pxd_free(mm, pud) pud_free((mm), (pud))
34387+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
34388+#define pyd_offset(mm, address) pgd_offset((mm), (address))
34389+#define PYD_SIZE PGDIR_SIZE
34390+#else
34391+#define pxd_t pmd_t
34392+#define pyd_t pud_t
34393+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
34394+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
34395+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
34396+#define pxd_free(mm, pud) pmd_free((mm), (pud))
34397+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
34398+#define pyd_offset(mm, address) pud_offset((mm), (address))
34399+#define PYD_SIZE PUD_SIZE
34400+#endif
34401+
34402+#ifdef CONFIG_PAX_PER_CPU_PGD
34403+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
34404+static inline void pgd_dtor(pgd_t *pgd) {}
34405+#else
34406 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
34407 {
34408 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
34409@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
34410 pgd_list_del(pgd);
34411 spin_unlock(&pgd_lock);
34412 }
34413+#endif
34414
34415 /*
34416 * List of all pgd's needed for non-PAE so it can invalidate entries
34417@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
34418 * -- nyc
34419 */
34420
34421-#ifdef CONFIG_X86_PAE
34422+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
34423 /*
34424 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
34425 * updating the top-level pagetable entries to guarantee the
34426@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
34427 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
34428 * and initialize the kernel pmds here.
34429 */
34430-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
34431+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
34432
34433 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
34434 {
34435@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
34436 */
34437 flush_tlb_mm(mm);
34438 }
34439+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
34440+#define PREALLOCATED_PXDS USER_PGD_PTRS
34441 #else /* !CONFIG_X86_PAE */
34442
34443 /* No need to prepopulate any pagetable entries in non-PAE modes. */
34444-#define PREALLOCATED_PMDS 0
34445+#define PREALLOCATED_PXDS 0
34446
34447 #endif /* CONFIG_X86_PAE */
34448
34449-static void free_pmds(pmd_t *pmds[])
34450+static void free_pxds(pxd_t *pxds[])
34451 {
34452 int i;
34453
34454- for(i = 0; i < PREALLOCATED_PMDS; i++)
34455- if (pmds[i]) {
34456- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
34457- free_page((unsigned long)pmds[i]);
34458+ for(i = 0; i < PREALLOCATED_PXDS; i++)
34459+ if (pxds[i]) {
34460+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
34461+ free_page((unsigned long)pxds[i]);
34462 }
34463 }
34464
34465-static int preallocate_pmds(pmd_t *pmds[])
34466+static int preallocate_pxds(pxd_t *pxds[])
34467 {
34468 int i;
34469 bool failed = false;
34470
34471- for(i = 0; i < PREALLOCATED_PMDS; i++) {
34472- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
34473- if (!pmd)
34474+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
34475+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
34476+ if (!pxd)
34477 failed = true;
34478- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
34479- free_page((unsigned long)pmd);
34480- pmd = NULL;
34481+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
34482+ free_page((unsigned long)pxd);
34483+ pxd = NULL;
34484 failed = true;
34485 }
34486- pmds[i] = pmd;
34487+ pxds[i] = pxd;
34488 }
34489
34490 if (failed) {
34491- free_pmds(pmds);
34492+ free_pxds(pxds);
34493 return -ENOMEM;
34494 }
34495
34496@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
34497 * preallocate which never got a corresponding vma will need to be
34498 * freed manually.
34499 */
34500-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
34501+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
34502 {
34503 int i;
34504
34505- for(i = 0; i < PREALLOCATED_PMDS; i++) {
34506+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
34507 pgd_t pgd = pgdp[i];
34508
34509 if (pgd_val(pgd) != 0) {
34510- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
34511+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
34512
34513- pgdp[i] = native_make_pgd(0);
34514+ set_pgd(pgdp + i, native_make_pgd(0));
34515
34516- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
34517- pmd_free(mm, pmd);
34518+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
34519+ pxd_free(mm, pxd);
34520 }
34521 }
34522 }
34523
34524-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
34525+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
34526 {
34527- pud_t *pud;
34528+ pyd_t *pyd;
34529 int i;
34530
34531- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
34532+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
34533 return;
34534
34535- pud = pud_offset(pgd, 0);
34536-
34537- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
34538- pmd_t *pmd = pmds[i];
34539+#ifdef CONFIG_X86_64
34540+ pyd = pyd_offset(mm, 0L);
34541+#else
34542+ pyd = pyd_offset(pgd, 0L);
34543+#endif
34544
34545+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
34546+ pxd_t *pxd = pxds[i];
34547 if (i >= KERNEL_PGD_BOUNDARY)
34548- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34549- sizeof(pmd_t) * PTRS_PER_PMD);
34550+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
34551+ sizeof(pxd_t) * PTRS_PER_PMD);
34552
34553- pud_populate(mm, pud, pmd);
34554+ pyd_populate(mm, pyd, pxd);
34555 }
34556 }
34557
34558 pgd_t *pgd_alloc(struct mm_struct *mm)
34559 {
34560 pgd_t *pgd;
34561- pmd_t *pmds[PREALLOCATED_PMDS];
34562+ pxd_t *pxds[PREALLOCATED_PXDS];
34563
34564 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
34565
34566@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34567
34568 mm->pgd = pgd;
34569
34570- if (preallocate_pmds(pmds) != 0)
34571+ if (preallocate_pxds(pxds) != 0)
34572 goto out_free_pgd;
34573
34574 if (paravirt_pgd_alloc(mm) != 0)
34575- goto out_free_pmds;
34576+ goto out_free_pxds;
34577
34578 /*
34579 * Make sure that pre-populating the pmds is atomic with
34580@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
34581 spin_lock(&pgd_lock);
34582
34583 pgd_ctor(mm, pgd);
34584- pgd_prepopulate_pmd(mm, pgd, pmds);
34585+ pgd_prepopulate_pxd(mm, pgd, pxds);
34586
34587 spin_unlock(&pgd_lock);
34588
34589 return pgd;
34590
34591-out_free_pmds:
34592- free_pmds(pmds);
34593+out_free_pxds:
34594+ free_pxds(pxds);
34595 out_free_pgd:
34596 free_page((unsigned long)pgd);
34597 out:
34598@@ -313,7 +380,7 @@ out:
34599
34600 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
34601 {
34602- pgd_mop_up_pmds(mm, pgd);
34603+ pgd_mop_up_pxds(mm, pgd);
34604 pgd_dtor(pgd);
34605 paravirt_pgd_free(mm, pgd);
34606 free_page((unsigned long)pgd);
34607diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
34608index 4dd8cf6..f9d143e 100644
34609--- a/arch/x86/mm/pgtable_32.c
34610+++ b/arch/x86/mm/pgtable_32.c
34611@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
34612 return;
34613 }
34614 pte = pte_offset_kernel(pmd, vaddr);
34615+
34616+ pax_open_kernel();
34617 if (pte_val(pteval))
34618 set_pte_at(&init_mm, vaddr, pte, pteval);
34619 else
34620 pte_clear(&init_mm, vaddr, pte);
34621+ pax_close_kernel();
34622
34623 /*
34624 * It's enough to flush this one mapping.
34625diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
34626index e666cbb..61788c45 100644
34627--- a/arch/x86/mm/physaddr.c
34628+++ b/arch/x86/mm/physaddr.c
34629@@ -10,7 +10,7 @@
34630 #ifdef CONFIG_X86_64
34631
34632 #ifdef CONFIG_DEBUG_VIRTUAL
34633-unsigned long __phys_addr(unsigned long x)
34634+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34635 {
34636 unsigned long y = x - __START_KERNEL_map;
34637
34638@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
34639 #else
34640
34641 #ifdef CONFIG_DEBUG_VIRTUAL
34642-unsigned long __phys_addr(unsigned long x)
34643+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
34644 {
34645 unsigned long phys_addr = x - PAGE_OFFSET;
34646 /* VMALLOC_* aren't constants */
34647diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
34648index 90555bf..f5f1828 100644
34649--- a/arch/x86/mm/setup_nx.c
34650+++ b/arch/x86/mm/setup_nx.c
34651@@ -5,8 +5,10 @@
34652 #include <asm/pgtable.h>
34653 #include <asm/proto.h>
34654
34655+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34656 static int disable_nx;
34657
34658+#ifndef CONFIG_PAX_PAGEEXEC
34659 /*
34660 * noexec = on|off
34661 *
34662@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
34663 return 0;
34664 }
34665 early_param("noexec", noexec_setup);
34666+#endif
34667+
34668+#endif
34669
34670 void x86_configure_nx(void)
34671 {
34672+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34673 if (cpu_has_nx && !disable_nx)
34674 __supported_pte_mask |= _PAGE_NX;
34675 else
34676+#endif
34677 __supported_pte_mask &= ~_PAGE_NX;
34678 }
34679
34680diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
34681index ee61c36..e6fedeb 100644
34682--- a/arch/x86/mm/tlb.c
34683+++ b/arch/x86/mm/tlb.c
34684@@ -48,7 +48,11 @@ void leave_mm(int cpu)
34685 BUG();
34686 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
34687 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
34688+
34689+#ifndef CONFIG_PAX_PER_CPU_PGD
34690 load_cr3(swapper_pg_dir);
34691+#endif
34692+
34693 /*
34694 * This gets called in the idle path where RCU
34695 * functions differently. Tracing normally
34696diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
34697new file mode 100644
34698index 0000000..dace51c
34699--- /dev/null
34700+++ b/arch/x86/mm/uderef_64.c
34701@@ -0,0 +1,37 @@
34702+#include <linux/mm.h>
34703+#include <asm/pgtable.h>
34704+#include <asm/uaccess.h>
34705+
34706+#ifdef CONFIG_PAX_MEMORY_UDEREF
34707+/* PaX: due to the special call convention these functions must
34708+ * - remain leaf functions under all configurations,
34709+ * - never be called directly, only dereferenced from the wrappers.
34710+ */
34711+void __pax_open_userland(void)
34712+{
34713+ unsigned int cpu;
34714+
34715+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
34716+ return;
34717+
34718+ cpu = raw_get_cpu();
34719+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
34720+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
34721+ raw_put_cpu_no_resched();
34722+}
34723+EXPORT_SYMBOL(__pax_open_userland);
34724+
34725+void __pax_close_userland(void)
34726+{
34727+ unsigned int cpu;
34728+
34729+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
34730+ return;
34731+
34732+ cpu = raw_get_cpu();
34733+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
34734+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
34735+ raw_put_cpu_no_resched();
34736+}
34737+EXPORT_SYMBOL(__pax_close_userland);
34738+#endif
34739diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
34740index 6440221..f84b5c7 100644
34741--- a/arch/x86/net/bpf_jit.S
34742+++ b/arch/x86/net/bpf_jit.S
34743@@ -9,6 +9,7 @@
34744 */
34745 #include <linux/linkage.h>
34746 #include <asm/dwarf2.h>
34747+#include <asm/alternative-asm.h>
34748
34749 /*
34750 * Calling convention :
34751@@ -38,6 +39,7 @@ sk_load_word_positive_offset:
34752 jle bpf_slow_path_word
34753 mov (SKBDATA,%rsi),%eax
34754 bswap %eax /* ntohl() */
34755+ pax_force_retaddr
34756 ret
34757
34758 sk_load_half:
34759@@ -55,6 +57,7 @@ sk_load_half_positive_offset:
34760 jle bpf_slow_path_half
34761 movzwl (SKBDATA,%rsi),%eax
34762 rol $8,%ax # ntohs()
34763+ pax_force_retaddr
34764 ret
34765
34766 sk_load_byte:
34767@@ -69,6 +72,7 @@ sk_load_byte_positive_offset:
34768 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
34769 jle bpf_slow_path_byte
34770 movzbl (SKBDATA,%rsi),%eax
34771+ pax_force_retaddr
34772 ret
34773
34774 /* rsi contains offset and can be scratched */
34775@@ -90,6 +94,7 @@ bpf_slow_path_word:
34776 js bpf_error
34777 mov - MAX_BPF_STACK + 32(%rbp),%eax
34778 bswap %eax
34779+ pax_force_retaddr
34780 ret
34781
34782 bpf_slow_path_half:
34783@@ -98,12 +103,14 @@ bpf_slow_path_half:
34784 mov - MAX_BPF_STACK + 32(%rbp),%ax
34785 rol $8,%ax
34786 movzwl %ax,%eax
34787+ pax_force_retaddr
34788 ret
34789
34790 bpf_slow_path_byte:
34791 bpf_slow_path_common(1)
34792 js bpf_error
34793 movzbl - MAX_BPF_STACK + 32(%rbp),%eax
34794+ pax_force_retaddr
34795 ret
34796
34797 #define sk_negative_common(SIZE) \
34798@@ -126,6 +133,7 @@ sk_load_word_negative_offset:
34799 sk_negative_common(4)
34800 mov (%rax), %eax
34801 bswap %eax
34802+ pax_force_retaddr
34803 ret
34804
34805 bpf_slow_path_half_neg:
34806@@ -137,6 +145,7 @@ sk_load_half_negative_offset:
34807 mov (%rax),%ax
34808 rol $8,%ax
34809 movzwl %ax,%eax
34810+ pax_force_retaddr
34811 ret
34812
34813 bpf_slow_path_byte_neg:
34814@@ -146,6 +155,7 @@ sk_load_byte_negative_offset:
34815 .globl sk_load_byte_negative_offset
34816 sk_negative_common(1)
34817 movzbl (%rax), %eax
34818+ pax_force_retaddr
34819 ret
34820
34821 bpf_error:
34822@@ -156,4 +166,5 @@ bpf_error:
34823 mov - MAX_BPF_STACK + 16(%rbp),%r14
34824 mov - MAX_BPF_STACK + 24(%rbp),%r15
34825 leaveq
34826+ pax_force_retaddr
34827 ret
34828diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
34829index c881ba8..71aca2e 100644
34830--- a/arch/x86/net/bpf_jit_comp.c
34831+++ b/arch/x86/net/bpf_jit_comp.c
34832@@ -15,7 +15,11 @@
34833 #include <linux/if_vlan.h>
34834 #include <linux/random.h>
34835
34836+#ifdef CONFIG_GRKERNSEC_BPF_HARDEN
34837+int bpf_jit_enable __read_only;
34838+#else
34839 int bpf_jit_enable __read_mostly;
34840+#endif
34841
34842 /*
34843 * assembly code in arch/x86/net/bpf_jit.S
34844@@ -109,36 +113,32 @@ static inline void bpf_flush_icache(void *start, void *end)
34845 #define CHOOSE_LOAD_FUNC(K, func) \
34846 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
34847
34848-struct bpf_binary_header {
34849- unsigned int pages;
34850- /* Note : for security reasons, bpf code will follow a randomly
34851- * sized amount of int3 instructions
34852- */
34853- u8 image[];
34854-};
34855-
34856-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
34857+/* Note : for security reasons, bpf code will follow a randomly
34858+ * sized amount of int3 instructions
34859+ */
34860+static u8 *bpf_alloc_binary(unsigned int proglen,
34861 u8 **image_ptr)
34862 {
34863 unsigned int sz, hole;
34864- struct bpf_binary_header *header;
34865+ u8 *header;
34866
34867 /* Most of BPF filters are really small,
34868 * but if some of them fill a page, allow at least
34869 * 128 extra bytes to insert a random section of int3
34870 */
34871- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
34872- header = module_alloc(sz);
34873+ sz = round_up(proglen + 128, PAGE_SIZE);
34874+ header = module_alloc_exec(sz);
34875 if (!header)
34876 return NULL;
34877
34878+ pax_open_kernel();
34879 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
34880+ pax_close_kernel();
34881
34882- header->pages = sz / PAGE_SIZE;
34883- hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
34884+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34885
34886 /* insert a random number of int3 instructions before BPF code */
34887- *image_ptr = &header->image[prandom_u32() % hole];
34888+ *image_ptr = &header[prandom_u32() % hole];
34889 return header;
34890 }
34891
34892@@ -864,7 +864,9 @@ common_load:
34893 pr_err("bpf_jit_compile fatal error\n");
34894 return -EFAULT;
34895 }
34896+ pax_open_kernel();
34897 memcpy(image + proglen, temp, ilen);
34898+ pax_close_kernel();
34899 }
34900 proglen += ilen;
34901 addrs[i] = proglen;
34902@@ -879,7 +881,7 @@ void bpf_jit_compile(struct bpf_prog *prog)
34903
34904 void bpf_int_jit_compile(struct bpf_prog *prog)
34905 {
34906- struct bpf_binary_header *header = NULL;
34907+ u8 *header = NULL;
34908 int proglen, oldproglen = 0;
34909 struct jit_context ctx = {};
34910 u8 *image = NULL;
34911@@ -911,7 +913,7 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
34912 if (proglen <= 0) {
34913 image = NULL;
34914 if (header)
34915- module_free(NULL, header);
34916+ module_free_exec(NULL, image);
34917 goto out;
34918 }
34919 if (image) {
34920@@ -935,7 +937,6 @@ void bpf_int_jit_compile(struct bpf_prog *prog)
34921
34922 if (image) {
34923 bpf_flush_icache(header, image + proglen);
34924- set_memory_ro((unsigned long)header, header->pages);
34925 prog->bpf_func = (void *)image;
34926 prog->jited = 1;
34927 }
34928@@ -943,23 +944,15 @@ out:
34929 kfree(addrs);
34930 }
34931
34932-static void bpf_jit_free_deferred(struct work_struct *work)
34933-{
34934- struct bpf_prog *fp = container_of(work, struct bpf_prog, work);
34935- unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34936- struct bpf_binary_header *header = (void *)addr;
34937-
34938- set_memory_rw(addr, header->pages);
34939- module_free(NULL, header);
34940- kfree(fp);
34941-}
34942-
34943 void bpf_jit_free(struct bpf_prog *fp)
34944 {
34945- if (fp->jited) {
34946- INIT_WORK(&fp->work, bpf_jit_free_deferred);
34947- schedule_work(&fp->work);
34948- } else {
34949- kfree(fp);
34950- }
34951+ unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34952+
34953+ if (!fp->jited)
34954+ goto free_filter;
34955+
34956+ module_free_exec(NULL, (void *)addr);
34957+
34958+free_filter:
34959+ bpf_prog_unlock_free(fp);
34960 }
34961diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34962index 5d04be5..2beeaa2 100644
34963--- a/arch/x86/oprofile/backtrace.c
34964+++ b/arch/x86/oprofile/backtrace.c
34965@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34966 struct stack_frame_ia32 *fp;
34967 unsigned long bytes;
34968
34969- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34970+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34971 if (bytes != 0)
34972 return NULL;
34973
34974- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34975+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34976
34977 oprofile_add_trace(bufhead[0].return_address);
34978
34979@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34980 struct stack_frame bufhead[2];
34981 unsigned long bytes;
34982
34983- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34984+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34985 if (bytes != 0)
34986 return NULL;
34987
34988@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34989 {
34990 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34991
34992- if (!user_mode_vm(regs)) {
34993+ if (!user_mode(regs)) {
34994 unsigned long stack = kernel_stack_pointer(regs);
34995 if (depth)
34996 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34997diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34998index 379e8bd..6386e09 100644
34999--- a/arch/x86/oprofile/nmi_int.c
35000+++ b/arch/x86/oprofile/nmi_int.c
35001@@ -23,6 +23,7 @@
35002 #include <asm/nmi.h>
35003 #include <asm/msr.h>
35004 #include <asm/apic.h>
35005+#include <asm/pgtable.h>
35006
35007 #include "op_counter.h"
35008 #include "op_x86_model.h"
35009@@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
35010 if (ret)
35011 return ret;
35012
35013- if (!model->num_virt_counters)
35014- model->num_virt_counters = model->num_counters;
35015+ if (!model->num_virt_counters) {
35016+ pax_open_kernel();
35017+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
35018+ pax_close_kernel();
35019+ }
35020
35021 mux_init(ops);
35022
35023diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
35024index 50d86c0..7985318 100644
35025--- a/arch/x86/oprofile/op_model_amd.c
35026+++ b/arch/x86/oprofile/op_model_amd.c
35027@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
35028 num_counters = AMD64_NUM_COUNTERS;
35029 }
35030
35031- op_amd_spec.num_counters = num_counters;
35032- op_amd_spec.num_controls = num_counters;
35033- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
35034+ pax_open_kernel();
35035+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
35036+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
35037+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
35038+ pax_close_kernel();
35039
35040 return 0;
35041 }
35042diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
35043index d90528e..0127e2b 100644
35044--- a/arch/x86/oprofile/op_model_ppro.c
35045+++ b/arch/x86/oprofile/op_model_ppro.c
35046@@ -19,6 +19,7 @@
35047 #include <asm/msr.h>
35048 #include <asm/apic.h>
35049 #include <asm/nmi.h>
35050+#include <asm/pgtable.h>
35051
35052 #include "op_x86_model.h"
35053 #include "op_counter.h"
35054@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
35055
35056 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
35057
35058- op_arch_perfmon_spec.num_counters = num_counters;
35059- op_arch_perfmon_spec.num_controls = num_counters;
35060+ pax_open_kernel();
35061+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
35062+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
35063+ pax_close_kernel();
35064 }
35065
35066 static int arch_perfmon_init(struct oprofile_operations *ignore)
35067diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
35068index 71e8a67..6a313bb 100644
35069--- a/arch/x86/oprofile/op_x86_model.h
35070+++ b/arch/x86/oprofile/op_x86_model.h
35071@@ -52,7 +52,7 @@ struct op_x86_model_spec {
35072 void (*switch_ctrl)(struct op_x86_model_spec const *model,
35073 struct op_msrs const * const msrs);
35074 #endif
35075-};
35076+} __do_const;
35077
35078 struct op_counter_config;
35079
35080diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
35081index b9958c3..24229ab 100644
35082--- a/arch/x86/pci/intel_mid_pci.c
35083+++ b/arch/x86/pci/intel_mid_pci.c
35084@@ -250,7 +250,7 @@ int __init intel_mid_pci_init(void)
35085 pci_mmcfg_late_init();
35086 pcibios_enable_irq = intel_mid_pci_irq_enable;
35087 pcibios_disable_irq = intel_mid_pci_irq_disable;
35088- pci_root_ops = intel_mid_pci_ops;
35089+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
35090 pci_soc_mode = 1;
35091 /* Continue with standard init */
35092 return 1;
35093diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
35094index eb500c2..eab9e70 100644
35095--- a/arch/x86/pci/irq.c
35096+++ b/arch/x86/pci/irq.c
35097@@ -51,7 +51,7 @@ struct irq_router {
35098 struct irq_router_handler {
35099 u16 vendor;
35100 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
35101-};
35102+} __do_const;
35103
35104 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
35105 void (*pcibios_disable_irq)(struct pci_dev *dev) = pirq_disable_irq;
35106@@ -791,7 +791,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
35107 return 0;
35108 }
35109
35110-static __initdata struct irq_router_handler pirq_routers[] = {
35111+static __initconst const struct irq_router_handler pirq_routers[] = {
35112 { PCI_VENDOR_ID_INTEL, intel_router_probe },
35113 { PCI_VENDOR_ID_AL, ali_router_probe },
35114 { PCI_VENDOR_ID_ITE, ite_router_probe },
35115@@ -818,7 +818,7 @@ static struct pci_dev *pirq_router_dev;
35116 static void __init pirq_find_router(struct irq_router *r)
35117 {
35118 struct irq_routing_table *rt = pirq_table;
35119- struct irq_router_handler *h;
35120+ const struct irq_router_handler *h;
35121
35122 #ifdef CONFIG_PCI_BIOS
35123 if (!rt->signature) {
35124@@ -1091,7 +1091,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
35125 return 0;
35126 }
35127
35128-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
35129+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
35130 {
35131 .callback = fix_broken_hp_bios_irq9,
35132 .ident = "HP Pavilion N5400 Series Laptop",
35133diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
35134index c77b24a..c979855 100644
35135--- a/arch/x86/pci/pcbios.c
35136+++ b/arch/x86/pci/pcbios.c
35137@@ -79,7 +79,7 @@ union bios32 {
35138 static struct {
35139 unsigned long address;
35140 unsigned short segment;
35141-} bios32_indirect = { 0, __KERNEL_CS };
35142+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
35143
35144 /*
35145 * Returns the entry point for the given service, NULL on error
35146@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
35147 unsigned long length; /* %ecx */
35148 unsigned long entry; /* %edx */
35149 unsigned long flags;
35150+ struct desc_struct d, *gdt;
35151
35152 local_irq_save(flags);
35153- __asm__("lcall *(%%edi); cld"
35154+
35155+ gdt = get_cpu_gdt_table(smp_processor_id());
35156+
35157+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
35158+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
35159+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
35160+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
35161+
35162+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
35163 : "=a" (return_code),
35164 "=b" (address),
35165 "=c" (length),
35166 "=d" (entry)
35167 : "0" (service),
35168 "1" (0),
35169- "D" (&bios32_indirect));
35170+ "D" (&bios32_indirect),
35171+ "r"(__PCIBIOS_DS)
35172+ : "memory");
35173+
35174+ pax_open_kernel();
35175+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
35176+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
35177+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
35178+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
35179+ pax_close_kernel();
35180+
35181 local_irq_restore(flags);
35182
35183 switch (return_code) {
35184- case 0:
35185- return address + entry;
35186- case 0x80: /* Not present */
35187- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
35188- return 0;
35189- default: /* Shouldn't happen */
35190- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
35191- service, return_code);
35192+ case 0: {
35193+ int cpu;
35194+ unsigned char flags;
35195+
35196+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
35197+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
35198+ printk(KERN_WARNING "bios32_service: not valid\n");
35199 return 0;
35200+ }
35201+ address = address + PAGE_OFFSET;
35202+ length += 16UL; /* some BIOSs underreport this... */
35203+ flags = 4;
35204+ if (length >= 64*1024*1024) {
35205+ length >>= PAGE_SHIFT;
35206+ flags |= 8;
35207+ }
35208+
35209+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
35210+ gdt = get_cpu_gdt_table(cpu);
35211+ pack_descriptor(&d, address, length, 0x9b, flags);
35212+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
35213+ pack_descriptor(&d, address, length, 0x93, flags);
35214+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
35215+ }
35216+ return entry;
35217+ }
35218+ case 0x80: /* Not present */
35219+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
35220+ return 0;
35221+ default: /* Shouldn't happen */
35222+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
35223+ service, return_code);
35224+ return 0;
35225 }
35226 }
35227
35228 static struct {
35229 unsigned long address;
35230 unsigned short segment;
35231-} pci_indirect = { 0, __KERNEL_CS };
35232+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
35233
35234-static int pci_bios_present;
35235+static int pci_bios_present __read_only;
35236
35237 static int check_pcibios(void)
35238 {
35239@@ -131,11 +174,13 @@ static int check_pcibios(void)
35240 unsigned long flags, pcibios_entry;
35241
35242 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
35243- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
35244+ pci_indirect.address = pcibios_entry;
35245
35246 local_irq_save(flags);
35247- __asm__(
35248- "lcall *(%%edi); cld\n\t"
35249+ __asm__("movw %w6, %%ds\n\t"
35250+ "lcall *%%ss:(%%edi); cld\n\t"
35251+ "push %%ss\n\t"
35252+ "pop %%ds\n\t"
35253 "jc 1f\n\t"
35254 "xor %%ah, %%ah\n"
35255 "1:"
35256@@ -144,7 +189,8 @@ static int check_pcibios(void)
35257 "=b" (ebx),
35258 "=c" (ecx)
35259 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
35260- "D" (&pci_indirect)
35261+ "D" (&pci_indirect),
35262+ "r" (__PCIBIOS_DS)
35263 : "memory");
35264 local_irq_restore(flags);
35265
35266@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35267
35268 switch (len) {
35269 case 1:
35270- __asm__("lcall *(%%esi); cld\n\t"
35271+ __asm__("movw %w6, %%ds\n\t"
35272+ "lcall *%%ss:(%%esi); cld\n\t"
35273+ "push %%ss\n\t"
35274+ "pop %%ds\n\t"
35275 "jc 1f\n\t"
35276 "xor %%ah, %%ah\n"
35277 "1:"
35278@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35279 : "1" (PCIBIOS_READ_CONFIG_BYTE),
35280 "b" (bx),
35281 "D" ((long)reg),
35282- "S" (&pci_indirect));
35283+ "S" (&pci_indirect),
35284+ "r" (__PCIBIOS_DS));
35285 /*
35286 * Zero-extend the result beyond 8 bits, do not trust the
35287 * BIOS having done it:
35288@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35289 *value &= 0xff;
35290 break;
35291 case 2:
35292- __asm__("lcall *(%%esi); cld\n\t"
35293+ __asm__("movw %w6, %%ds\n\t"
35294+ "lcall *%%ss:(%%esi); cld\n\t"
35295+ "push %%ss\n\t"
35296+ "pop %%ds\n\t"
35297 "jc 1f\n\t"
35298 "xor %%ah, %%ah\n"
35299 "1:"
35300@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35301 : "1" (PCIBIOS_READ_CONFIG_WORD),
35302 "b" (bx),
35303 "D" ((long)reg),
35304- "S" (&pci_indirect));
35305+ "S" (&pci_indirect),
35306+ "r" (__PCIBIOS_DS));
35307 /*
35308 * Zero-extend the result beyond 16 bits, do not trust the
35309 * BIOS having done it:
35310@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35311 *value &= 0xffff;
35312 break;
35313 case 4:
35314- __asm__("lcall *(%%esi); cld\n\t"
35315+ __asm__("movw %w6, %%ds\n\t"
35316+ "lcall *%%ss:(%%esi); cld\n\t"
35317+ "push %%ss\n\t"
35318+ "pop %%ds\n\t"
35319 "jc 1f\n\t"
35320 "xor %%ah, %%ah\n"
35321 "1:"
35322@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
35323 : "1" (PCIBIOS_READ_CONFIG_DWORD),
35324 "b" (bx),
35325 "D" ((long)reg),
35326- "S" (&pci_indirect));
35327+ "S" (&pci_indirect),
35328+ "r" (__PCIBIOS_DS));
35329 break;
35330 }
35331
35332@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35333
35334 switch (len) {
35335 case 1:
35336- __asm__("lcall *(%%esi); cld\n\t"
35337+ __asm__("movw %w6, %%ds\n\t"
35338+ "lcall *%%ss:(%%esi); cld\n\t"
35339+ "push %%ss\n\t"
35340+ "pop %%ds\n\t"
35341 "jc 1f\n\t"
35342 "xor %%ah, %%ah\n"
35343 "1:"
35344@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35345 "c" (value),
35346 "b" (bx),
35347 "D" ((long)reg),
35348- "S" (&pci_indirect));
35349+ "S" (&pci_indirect),
35350+ "r" (__PCIBIOS_DS));
35351 break;
35352 case 2:
35353- __asm__("lcall *(%%esi); cld\n\t"
35354+ __asm__("movw %w6, %%ds\n\t"
35355+ "lcall *%%ss:(%%esi); cld\n\t"
35356+ "push %%ss\n\t"
35357+ "pop %%ds\n\t"
35358 "jc 1f\n\t"
35359 "xor %%ah, %%ah\n"
35360 "1:"
35361@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35362 "c" (value),
35363 "b" (bx),
35364 "D" ((long)reg),
35365- "S" (&pci_indirect));
35366+ "S" (&pci_indirect),
35367+ "r" (__PCIBIOS_DS));
35368 break;
35369 case 4:
35370- __asm__("lcall *(%%esi); cld\n\t"
35371+ __asm__("movw %w6, %%ds\n\t"
35372+ "lcall *%%ss:(%%esi); cld\n\t"
35373+ "push %%ss\n\t"
35374+ "pop %%ds\n\t"
35375 "jc 1f\n\t"
35376 "xor %%ah, %%ah\n"
35377 "1:"
35378@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
35379 "c" (value),
35380 "b" (bx),
35381 "D" ((long)reg),
35382- "S" (&pci_indirect));
35383+ "S" (&pci_indirect),
35384+ "r" (__PCIBIOS_DS));
35385 break;
35386 }
35387
35388@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
35389
35390 DBG("PCI: Fetching IRQ routing table... ");
35391 __asm__("push %%es\n\t"
35392+ "movw %w8, %%ds\n\t"
35393 "push %%ds\n\t"
35394 "pop %%es\n\t"
35395- "lcall *(%%esi); cld\n\t"
35396+ "lcall *%%ss:(%%esi); cld\n\t"
35397 "pop %%es\n\t"
35398+ "push %%ss\n\t"
35399+ "pop %%ds\n"
35400 "jc 1f\n\t"
35401 "xor %%ah, %%ah\n"
35402 "1:"
35403@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
35404 "1" (0),
35405 "D" ((long) &opt),
35406 "S" (&pci_indirect),
35407- "m" (opt)
35408+ "m" (opt),
35409+ "r" (__PCIBIOS_DS)
35410 : "memory");
35411 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
35412 if (ret & 0xff00)
35413@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
35414 {
35415 int ret;
35416
35417- __asm__("lcall *(%%esi); cld\n\t"
35418+ __asm__("movw %w5, %%ds\n\t"
35419+ "lcall *%%ss:(%%esi); cld\n\t"
35420+ "push %%ss\n\t"
35421+ "pop %%ds\n"
35422 "jc 1f\n\t"
35423 "xor %%ah, %%ah\n"
35424 "1:"
35425@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
35426 : "0" (PCIBIOS_SET_PCI_HW_INT),
35427 "b" ((dev->bus->number << 8) | dev->devfn),
35428 "c" ((irq << 8) | (pin + 10)),
35429- "S" (&pci_indirect));
35430+ "S" (&pci_indirect),
35431+ "r" (__PCIBIOS_DS));
35432 return !(ret & 0xff00);
35433 }
35434 EXPORT_SYMBOL(pcibios_set_irq_routing);
35435diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
35436index 9ee3491..872192f 100644
35437--- a/arch/x86/platform/efi/efi_32.c
35438+++ b/arch/x86/platform/efi/efi_32.c
35439@@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
35440 {
35441 struct desc_ptr gdt_descr;
35442
35443+#ifdef CONFIG_PAX_KERNEXEC
35444+ struct desc_struct d;
35445+#endif
35446+
35447 local_irq_save(efi_rt_eflags);
35448
35449 load_cr3(initial_page_table);
35450 __flush_tlb_all();
35451
35452+#ifdef CONFIG_PAX_KERNEXEC
35453+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
35454+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
35455+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
35456+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
35457+#endif
35458+
35459 gdt_descr.address = __pa(get_cpu_gdt_table(0));
35460 gdt_descr.size = GDT_SIZE - 1;
35461 load_gdt(&gdt_descr);
35462@@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
35463 {
35464 struct desc_ptr gdt_descr;
35465
35466+#ifdef CONFIG_PAX_KERNEXEC
35467+ struct desc_struct d;
35468+
35469+ memset(&d, 0, sizeof d);
35470+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
35471+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
35472+#endif
35473+
35474 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
35475 gdt_descr.size = GDT_SIZE - 1;
35476 load_gdt(&gdt_descr);
35477
35478+#ifdef CONFIG_PAX_PER_CPU_PGD
35479+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
35480+#else
35481 load_cr3(swapper_pg_dir);
35482+#endif
35483+
35484 __flush_tlb_all();
35485
35486 local_irq_restore(efi_rt_eflags);
35487diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
35488index 290d397..e09d270 100644
35489--- a/arch/x86/platform/efi/efi_64.c
35490+++ b/arch/x86/platform/efi/efi_64.c
35491@@ -99,6 +99,11 @@ void __init efi_call_phys_prelog(void)
35492 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
35493 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
35494 }
35495+
35496+#ifdef CONFIG_PAX_PER_CPU_PGD
35497+ load_cr3(swapper_pg_dir);
35498+#endif
35499+
35500 __flush_tlb_all();
35501 }
35502
35503@@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
35504 for (pgd = 0; pgd < n_pgds; pgd++)
35505 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
35506 kfree(save_pgd);
35507+
35508+#ifdef CONFIG_PAX_PER_CPU_PGD
35509+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
35510+#endif
35511+
35512 __flush_tlb_all();
35513 local_irq_restore(efi_flags);
35514 early_code_mapping_set_exec(0);
35515@@ -146,8 +156,23 @@ int efi_setup_page_tables(unsigned long pa_memmap, unsigned num_pages)
35516 unsigned npages;
35517 pgd_t *pgd;
35518
35519- if (efi_enabled(EFI_OLD_MEMMAP))
35520+ if (efi_enabled(EFI_OLD_MEMMAP)) {
35521+ /* PaX: We need to disable the NX bit in the PGD, otherwise we won't be
35522+ * able to execute the EFI services.
35523+ */
35524+ if (__supported_pte_mask & _PAGE_NX) {
35525+ unsigned long addr = (unsigned long) __va(0);
35526+ pgd_t pe = __pgd(pgd_val(*pgd_offset_k(addr)) & ~_PAGE_NX);
35527+
35528+ pr_alert("PAX: Disabling NX protection for low memory map. Try booting without \"efi=old_map\"\n");
35529+#ifdef CONFIG_PAX_PER_CPU_PGD
35530+ set_pgd(pgd_offset_cpu(0, kernel, addr), pe);
35531+#endif
35532+ set_pgd(pgd_offset_k(addr), pe);
35533+ }
35534+
35535 return 0;
35536+ }
35537
35538 efi_scratch.efi_pgt = (pgd_t *)(unsigned long)real_mode_header->trampoline_pgd;
35539 pgd = __va(efi_scratch.efi_pgt);
35540diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
35541index fbe66e6..eae5e38 100644
35542--- a/arch/x86/platform/efi/efi_stub_32.S
35543+++ b/arch/x86/platform/efi/efi_stub_32.S
35544@@ -6,7 +6,9 @@
35545 */
35546
35547 #include <linux/linkage.h>
35548+#include <linux/init.h>
35549 #include <asm/page_types.h>
35550+#include <asm/segment.h>
35551
35552 /*
35553 * efi_call_phys(void *, ...) is a function with variable parameters.
35554@@ -20,7 +22,7 @@
35555 * service functions will comply with gcc calling convention, too.
35556 */
35557
35558-.text
35559+__INIT
35560 ENTRY(efi_call_phys)
35561 /*
35562 * 0. The function can only be called in Linux kernel. So CS has been
35563@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
35564 * The mapping of lower virtual memory has been created in prelog and
35565 * epilog.
35566 */
35567- movl $1f, %edx
35568- subl $__PAGE_OFFSET, %edx
35569- jmp *%edx
35570+#ifdef CONFIG_PAX_KERNEXEC
35571+ movl $(__KERNEXEC_EFI_DS), %edx
35572+ mov %edx, %ds
35573+ mov %edx, %es
35574+ mov %edx, %ss
35575+ addl $2f,(1f)
35576+ ljmp *(1f)
35577+
35578+__INITDATA
35579+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
35580+.previous
35581+
35582+2:
35583+ subl $2b,(1b)
35584+#else
35585+ jmp 1f-__PAGE_OFFSET
35586 1:
35587+#endif
35588
35589 /*
35590 * 2. Now on the top of stack is the return
35591@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
35592 * parameter 2, ..., param n. To make things easy, we save the return
35593 * address of efi_call_phys in a global variable.
35594 */
35595- popl %edx
35596- movl %edx, saved_return_addr
35597- /* get the function pointer into ECX*/
35598- popl %ecx
35599- movl %ecx, efi_rt_function_ptr
35600- movl $2f, %edx
35601- subl $__PAGE_OFFSET, %edx
35602- pushl %edx
35603+ popl (saved_return_addr)
35604+ popl (efi_rt_function_ptr)
35605
35606 /*
35607 * 3. Clear PG bit in %CR0.
35608@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
35609 /*
35610 * 5. Call the physical function.
35611 */
35612- jmp *%ecx
35613+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
35614
35615-2:
35616 /*
35617 * 6. After EFI runtime service returns, control will return to
35618 * following instruction. We'd better readjust stack pointer first.
35619@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
35620 movl %cr0, %edx
35621 orl $0x80000000, %edx
35622 movl %edx, %cr0
35623- jmp 1f
35624-1:
35625+
35626 /*
35627 * 8. Now restore the virtual mode from flat mode by
35628 * adding EIP with PAGE_OFFSET.
35629 */
35630- movl $1f, %edx
35631- jmp *%edx
35632+#ifdef CONFIG_PAX_KERNEXEC
35633+ movl $(__KERNEL_DS), %edx
35634+ mov %edx, %ds
35635+ mov %edx, %es
35636+ mov %edx, %ss
35637+ ljmp $(__KERNEL_CS),$1f
35638+#else
35639+ jmp 1f+__PAGE_OFFSET
35640+#endif
35641 1:
35642
35643 /*
35644 * 9. Balance the stack. And because EAX contain the return value,
35645 * we'd better not clobber it.
35646 */
35647- leal efi_rt_function_ptr, %edx
35648- movl (%edx), %ecx
35649- pushl %ecx
35650+ pushl (efi_rt_function_ptr)
35651
35652 /*
35653- * 10. Push the saved return address onto the stack and return.
35654+ * 10. Return to the saved return address.
35655 */
35656- leal saved_return_addr, %edx
35657- movl (%edx), %ecx
35658- pushl %ecx
35659- ret
35660+ jmpl *(saved_return_addr)
35661 ENDPROC(efi_call_phys)
35662 .previous
35663
35664-.data
35665+__INITDATA
35666 saved_return_addr:
35667 .long 0
35668 efi_rt_function_ptr:
35669diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
35670index 5fcda72..cd4dc41 100644
35671--- a/arch/x86/platform/efi/efi_stub_64.S
35672+++ b/arch/x86/platform/efi/efi_stub_64.S
35673@@ -11,6 +11,7 @@
35674 #include <asm/msr.h>
35675 #include <asm/processor-flags.h>
35676 #include <asm/page_types.h>
35677+#include <asm/alternative-asm.h>
35678
35679 #define SAVE_XMM \
35680 mov %rsp, %rax; \
35681@@ -88,6 +89,7 @@ ENTRY(efi_call)
35682 RESTORE_PGT
35683 addq $48, %rsp
35684 RESTORE_XMM
35685+ pax_force_retaddr 0, 1
35686 ret
35687 ENDPROC(efi_call)
35688
35689@@ -245,8 +247,8 @@ efi_gdt64:
35690 .long 0 /* Filled out by user */
35691 .word 0
35692 .quad 0x0000000000000000 /* NULL descriptor */
35693- .quad 0x00af9a000000ffff /* __KERNEL_CS */
35694- .quad 0x00cf92000000ffff /* __KERNEL_DS */
35695+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
35696+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
35697 .quad 0x0080890000000000 /* TS descriptor */
35698 .quad 0x0000000000000000 /* TS continued */
35699 efi_gdt64_end:
35700diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
35701index 1bbedc4..eb795b5 100644
35702--- a/arch/x86/platform/intel-mid/intel-mid.c
35703+++ b/arch/x86/platform/intel-mid/intel-mid.c
35704@@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
35705 {
35706 };
35707
35708-static void intel_mid_reboot(void)
35709+static void __noreturn intel_mid_reboot(void)
35710 {
35711 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
35712+ BUG();
35713 }
35714
35715 static unsigned long __init intel_mid_calibrate_tsc(void)
35716diff --git a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35717index 46aa25c..59a68ed 100644
35718--- a/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35719+++ b/arch/x86/platform/intel-mid/intel_mid_weak_decls.h
35720@@ -10,10 +10,9 @@
35721 */
35722
35723
35724-/* __attribute__((weak)) makes these declarations overridable */
35725 /* For every CPU addition a new get_<cpuname>_ops interface needs
35726 * to be added.
35727 */
35728-extern void *get_penwell_ops(void) __attribute__((weak));
35729-extern void *get_cloverview_ops(void) __attribute__((weak));
35730-extern void *get_tangier_ops(void) __attribute__((weak));
35731+extern const void *get_penwell_ops(void);
35732+extern const void *get_cloverview_ops(void);
35733+extern const void *get_tangier_ops(void);
35734diff --git a/arch/x86/platform/intel-mid/mfld.c b/arch/x86/platform/intel-mid/mfld.c
35735index 23381d2..8ddc10e 100644
35736--- a/arch/x86/platform/intel-mid/mfld.c
35737+++ b/arch/x86/platform/intel-mid/mfld.c
35738@@ -64,12 +64,12 @@ static void __init penwell_arch_setup(void)
35739 pm_power_off = mfld_power_off;
35740 }
35741
35742-void *get_penwell_ops(void)
35743+const void *get_penwell_ops(void)
35744 {
35745 return &penwell_ops;
35746 }
35747
35748-void *get_cloverview_ops(void)
35749+const void *get_cloverview_ops(void)
35750 {
35751 return &penwell_ops;
35752 }
35753diff --git a/arch/x86/platform/intel-mid/mrfl.c b/arch/x86/platform/intel-mid/mrfl.c
35754index aaca917..66eadbc 100644
35755--- a/arch/x86/platform/intel-mid/mrfl.c
35756+++ b/arch/x86/platform/intel-mid/mrfl.c
35757@@ -97,7 +97,7 @@ static struct intel_mid_ops tangier_ops = {
35758 .arch_setup = tangier_arch_setup,
35759 };
35760
35761-void *get_tangier_ops(void)
35762+const void *get_tangier_ops(void)
35763 {
35764 return &tangier_ops;
35765 }
35766diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
35767index d6ee929..3637cb5 100644
35768--- a/arch/x86/platform/olpc/olpc_dt.c
35769+++ b/arch/x86/platform/olpc/olpc_dt.c
35770@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
35771 return res;
35772 }
35773
35774-static struct of_pdt_ops prom_olpc_ops __initdata = {
35775+static struct of_pdt_ops prom_olpc_ops __initconst = {
35776 .nextprop = olpc_dt_nextprop,
35777 .getproplen = olpc_dt_getproplen,
35778 .getproperty = olpc_dt_getproperty,
35779diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
35780index 6ec7910..ecdbb11 100644
35781--- a/arch/x86/power/cpu.c
35782+++ b/arch/x86/power/cpu.c
35783@@ -137,11 +137,8 @@ static void do_fpu_end(void)
35784 static void fix_processor_context(void)
35785 {
35786 int cpu = smp_processor_id();
35787- struct tss_struct *t = &per_cpu(init_tss, cpu);
35788-#ifdef CONFIG_X86_64
35789- struct desc_struct *desc = get_cpu_gdt_table(cpu);
35790- tss_desc tss;
35791-#endif
35792+ struct tss_struct *t = init_tss + cpu;
35793+
35794 set_tss_desc(cpu, t); /*
35795 * This just modifies memory; should not be
35796 * necessary. But... This is necessary, because
35797@@ -150,10 +147,6 @@ static void fix_processor_context(void)
35798 */
35799
35800 #ifdef CONFIG_X86_64
35801- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
35802- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
35803- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
35804-
35805 syscall_init(); /* This sets MSR_*STAR and related */
35806 #endif
35807 load_TR_desc(); /* This does ltr */
35808diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
35809index bad628a..a102610 100644
35810--- a/arch/x86/realmode/init.c
35811+++ b/arch/x86/realmode/init.c
35812@@ -68,7 +68,13 @@ void __init setup_real_mode(void)
35813 __va(real_mode_header->trampoline_header);
35814
35815 #ifdef CONFIG_X86_32
35816- trampoline_header->start = __pa_symbol(startup_32_smp);
35817+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
35818+
35819+#ifdef CONFIG_PAX_KERNEXEC
35820+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
35821+#endif
35822+
35823+ trampoline_header->boot_cs = __BOOT_CS;
35824 trampoline_header->gdt_limit = __BOOT_DS + 7;
35825 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
35826 #else
35827@@ -84,7 +90,7 @@ void __init setup_real_mode(void)
35828 *trampoline_cr4_features = read_cr4();
35829
35830 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
35831- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
35832+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
35833 trampoline_pgd[511] = init_level4_pgt[511].pgd;
35834 #endif
35835 }
35836diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
35837index 7c0d7be..d24dc88 100644
35838--- a/arch/x86/realmode/rm/Makefile
35839+++ b/arch/x86/realmode/rm/Makefile
35840@@ -67,5 +67,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
35841
35842 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
35843 -I$(srctree)/arch/x86/boot
35844+ifdef CONSTIFY_PLUGIN
35845+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
35846+endif
35847 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
35848 GCOV_PROFILE := n
35849diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
35850index a28221d..93c40f1 100644
35851--- a/arch/x86/realmode/rm/header.S
35852+++ b/arch/x86/realmode/rm/header.S
35853@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
35854 #endif
35855 /* APM/BIOS reboot */
35856 .long pa_machine_real_restart_asm
35857-#ifdef CONFIG_X86_64
35858+#ifdef CONFIG_X86_32
35859+ .long __KERNEL_CS
35860+#else
35861 .long __KERNEL32_CS
35862 #endif
35863 END(real_mode_header)
35864diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35865index 48ddd76..c26749f 100644
35866--- a/arch/x86/realmode/rm/trampoline_32.S
35867+++ b/arch/x86/realmode/rm/trampoline_32.S
35868@@ -24,6 +24,12 @@
35869 #include <asm/page_types.h>
35870 #include "realmode.h"
35871
35872+#ifdef CONFIG_PAX_KERNEXEC
35873+#define ta(X) (X)
35874+#else
35875+#define ta(X) (pa_ ## X)
35876+#endif
35877+
35878 .text
35879 .code16
35880
35881@@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35882
35883 cli # We should be safe anyway
35884
35885- movl tr_start, %eax # where we need to go
35886-
35887 movl $0xA5A5A5A5, trampoline_status
35888 # write marker for master knows we're running
35889
35890@@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35891 movw $1, %dx # protected mode (PE) bit
35892 lmsw %dx # into protected mode
35893
35894- ljmpl $__BOOT_CS, $pa_startup_32
35895+ ljmpl *(trampoline_header)
35896
35897 .section ".text32","ax"
35898 .code32
35899@@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35900 .balign 8
35901 GLOBAL(trampoline_header)
35902 tr_start: .space 4
35903- tr_gdt_pad: .space 2
35904+ tr_boot_cs: .space 2
35905 tr_gdt: .space 6
35906 END(trampoline_header)
35907
35908diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35909index dac7b20..72dbaca 100644
35910--- a/arch/x86/realmode/rm/trampoline_64.S
35911+++ b/arch/x86/realmode/rm/trampoline_64.S
35912@@ -93,6 +93,7 @@ ENTRY(startup_32)
35913 movl %edx, %gs
35914
35915 movl pa_tr_cr4, %eax
35916+ andl $~X86_CR4_PCIDE, %eax
35917 movl %eax, %cr4 # Enable PAE mode
35918
35919 # Setup trampoline 4 level pagetables
35920@@ -106,7 +107,7 @@ ENTRY(startup_32)
35921 wrmsr
35922
35923 # Enable paging and in turn activate Long Mode
35924- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35925+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
35926 movl %eax, %cr0
35927
35928 /*
35929diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35930index 9e7e147..25a4158 100644
35931--- a/arch/x86/realmode/rm/wakeup_asm.S
35932+++ b/arch/x86/realmode/rm/wakeup_asm.S
35933@@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35934 lgdtl pmode_gdt
35935
35936 /* This really couldn't... */
35937- movl pmode_entry, %eax
35938 movl pmode_cr0, %ecx
35939 movl %ecx, %cr0
35940- ljmpl $__KERNEL_CS, $pa_startup_32
35941- /* -> jmp *%eax in trampoline_32.S */
35942+
35943+ ljmpl *pmode_entry
35944 #else
35945 jmp trampoline_start
35946 #endif
35947diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35948index 604a37e..e49702a 100644
35949--- a/arch/x86/tools/Makefile
35950+++ b/arch/x86/tools/Makefile
35951@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35952
35953 $(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
35954
35955-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35956+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35957 hostprogs-y += relocs
35958 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35959 PHONY += relocs
35960diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35961index bbb1d22..e505211 100644
35962--- a/arch/x86/tools/relocs.c
35963+++ b/arch/x86/tools/relocs.c
35964@@ -1,5 +1,7 @@
35965 /* This is included from relocs_32/64.c */
35966
35967+#include "../../../include/generated/autoconf.h"
35968+
35969 #define ElfW(type) _ElfW(ELF_BITS, type)
35970 #define _ElfW(bits, type) __ElfW(bits, type)
35971 #define __ElfW(bits, type) Elf##bits##_##type
35972@@ -11,6 +13,7 @@
35973 #define Elf_Sym ElfW(Sym)
35974
35975 static Elf_Ehdr ehdr;
35976+static Elf_Phdr *phdr;
35977
35978 struct relocs {
35979 uint32_t *offset;
35980@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35981 }
35982 }
35983
35984+static void read_phdrs(FILE *fp)
35985+{
35986+ unsigned int i;
35987+
35988+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35989+ if (!phdr) {
35990+ die("Unable to allocate %d program headers\n",
35991+ ehdr.e_phnum);
35992+ }
35993+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35994+ die("Seek to %d failed: %s\n",
35995+ ehdr.e_phoff, strerror(errno));
35996+ }
35997+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35998+ die("Cannot read ELF program headers: %s\n",
35999+ strerror(errno));
36000+ }
36001+ for(i = 0; i < ehdr.e_phnum; i++) {
36002+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
36003+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
36004+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
36005+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
36006+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
36007+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
36008+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
36009+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
36010+ }
36011+
36012+}
36013+
36014 static void read_shdrs(FILE *fp)
36015 {
36016- int i;
36017+ unsigned int i;
36018 Elf_Shdr shdr;
36019
36020 secs = calloc(ehdr.e_shnum, sizeof(struct section));
36021@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
36022
36023 static void read_strtabs(FILE *fp)
36024 {
36025- int i;
36026+ unsigned int i;
36027 for (i = 0; i < ehdr.e_shnum; i++) {
36028 struct section *sec = &secs[i];
36029 if (sec->shdr.sh_type != SHT_STRTAB) {
36030@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
36031
36032 static void read_symtabs(FILE *fp)
36033 {
36034- int i,j;
36035+ unsigned int i,j;
36036 for (i = 0; i < ehdr.e_shnum; i++) {
36037 struct section *sec = &secs[i];
36038 if (sec->shdr.sh_type != SHT_SYMTAB) {
36039@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
36040 }
36041
36042
36043-static void read_relocs(FILE *fp)
36044+static void read_relocs(FILE *fp, int use_real_mode)
36045 {
36046- int i,j;
36047+ unsigned int i,j;
36048+ uint32_t base;
36049+
36050 for (i = 0; i < ehdr.e_shnum; i++) {
36051 struct section *sec = &secs[i];
36052 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36053@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
36054 die("Cannot read symbol table: %s\n",
36055 strerror(errno));
36056 }
36057+ base = 0;
36058+
36059+#ifdef CONFIG_X86_32
36060+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
36061+ if (phdr[j].p_type != PT_LOAD )
36062+ continue;
36063+ 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)
36064+ continue;
36065+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
36066+ break;
36067+ }
36068+#endif
36069+
36070 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
36071 Elf_Rel *rel = &sec->reltab[j];
36072- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
36073+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
36074 rel->r_info = elf_xword_to_cpu(rel->r_info);
36075 #if (SHT_REL_TYPE == SHT_RELA)
36076 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
36077@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
36078
36079 static void print_absolute_symbols(void)
36080 {
36081- int i;
36082+ unsigned int i;
36083 const char *format;
36084
36085 if (ELF_BITS == 64)
36086@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
36087 for (i = 0; i < ehdr.e_shnum; i++) {
36088 struct section *sec = &secs[i];
36089 char *sym_strtab;
36090- int j;
36091+ unsigned int j;
36092
36093 if (sec->shdr.sh_type != SHT_SYMTAB) {
36094 continue;
36095@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
36096
36097 static void print_absolute_relocs(void)
36098 {
36099- int i, printed = 0;
36100+ unsigned int i, printed = 0;
36101 const char *format;
36102
36103 if (ELF_BITS == 64)
36104@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
36105 struct section *sec_applies, *sec_symtab;
36106 char *sym_strtab;
36107 Elf_Sym *sh_symtab;
36108- int j;
36109+ unsigned int j;
36110 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36111 continue;
36112 }
36113@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
36114 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
36115 Elf_Sym *sym, const char *symname))
36116 {
36117- int i;
36118+ unsigned int i;
36119 /* Walk through the relocations */
36120 for (i = 0; i < ehdr.e_shnum; i++) {
36121 char *sym_strtab;
36122 Elf_Sym *sh_symtab;
36123 struct section *sec_applies, *sec_symtab;
36124- int j;
36125+ unsigned int j;
36126 struct section *sec = &secs[i];
36127
36128 if (sec->shdr.sh_type != SHT_REL_TYPE) {
36129@@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
36130 {
36131 unsigned r_type = ELF32_R_TYPE(rel->r_info);
36132 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
36133+ char *sym_strtab = sec->link->link->strtab;
36134+
36135+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
36136+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
36137+ return 0;
36138+
36139+#ifdef CONFIG_PAX_KERNEXEC
36140+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
36141+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
36142+ return 0;
36143+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
36144+ return 0;
36145+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
36146+ return 0;
36147+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
36148+ return 0;
36149+#endif
36150
36151 switch (r_type) {
36152 case R_386_NONE:
36153@@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
36154
36155 static void emit_relocs(int as_text, int use_real_mode)
36156 {
36157- int i;
36158+ unsigned int i;
36159 int (*write_reloc)(uint32_t, FILE *) = write32;
36160 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
36161 const char *symname);
36162@@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
36163 {
36164 regex_init(use_real_mode);
36165 read_ehdr(fp);
36166+ read_phdrs(fp);
36167 read_shdrs(fp);
36168 read_strtabs(fp);
36169 read_symtabs(fp);
36170- read_relocs(fp);
36171+ read_relocs(fp, use_real_mode);
36172 if (ELF_BITS == 64)
36173 percpu_init();
36174 if (show_absolute_syms) {
36175diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
36176index f40281e..92728c9 100644
36177--- a/arch/x86/um/mem_32.c
36178+++ b/arch/x86/um/mem_32.c
36179@@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
36180 gate_vma.vm_start = FIXADDR_USER_START;
36181 gate_vma.vm_end = FIXADDR_USER_END;
36182 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
36183- gate_vma.vm_page_prot = __P101;
36184+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
36185
36186 return 0;
36187 }
36188diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
36189index 80ffa5b..a33bd15 100644
36190--- a/arch/x86/um/tls_32.c
36191+++ b/arch/x86/um/tls_32.c
36192@@ -260,7 +260,7 @@ out:
36193 if (unlikely(task == current &&
36194 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
36195 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
36196- "without flushed TLS.", current->pid);
36197+ "without flushed TLS.", task_pid_nr(current));
36198 }
36199
36200 return 0;
36201diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
36202index 5a4affe..9e2d522 100644
36203--- a/arch/x86/vdso/Makefile
36204+++ b/arch/x86/vdso/Makefile
36205@@ -174,7 +174,7 @@ quiet_cmd_vdso = VDSO $@
36206 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
36207 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
36208
36209-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
36210+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
36211 $(call cc-ldoption, -Wl$(comma)--build-id) -Wl,-Bsymbolic $(LTO_CFLAGS)
36212 GCOV_PROFILE := n
36213
36214diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
36215index e904c27..b9eaa03 100644
36216--- a/arch/x86/vdso/vdso32-setup.c
36217+++ b/arch/x86/vdso/vdso32-setup.c
36218@@ -14,6 +14,7 @@
36219 #include <asm/cpufeature.h>
36220 #include <asm/processor.h>
36221 #include <asm/vdso.h>
36222+#include <asm/mman.h>
36223
36224 #ifdef CONFIG_COMPAT_VDSO
36225 #define VDSO_DEFAULT 0
36226diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
36227index 970463b..da82d3e 100644
36228--- a/arch/x86/vdso/vma.c
36229+++ b/arch/x86/vdso/vma.c
36230@@ -16,10 +16,9 @@
36231 #include <asm/vdso.h>
36232 #include <asm/page.h>
36233 #include <asm/hpet.h>
36234+#include <asm/mman.h>
36235
36236 #if defined(CONFIG_X86_64)
36237-unsigned int __read_mostly vdso64_enabled = 1;
36238-
36239 extern unsigned short vdso_sync_cpuid;
36240 #endif
36241
36242@@ -101,6 +100,11 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36243 .pages = no_pages,
36244 };
36245
36246+#ifdef CONFIG_PAX_RANDMMAP
36247+ if (mm->pax_flags & MF_PAX_RANDMMAP)
36248+ calculate_addr = false;
36249+#endif
36250+
36251 if (calculate_addr) {
36252 addr = vdso_addr(current->mm->start_stack,
36253 image->size - image->sym_vvar_start);
36254@@ -111,14 +115,14 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36255 down_write(&mm->mmap_sem);
36256
36257 addr = get_unmapped_area(NULL, addr,
36258- image->size - image->sym_vvar_start, 0, 0);
36259+ image->size - image->sym_vvar_start, 0, MAP_EXECUTABLE);
36260 if (IS_ERR_VALUE(addr)) {
36261 ret = addr;
36262 goto up_fail;
36263 }
36264
36265 text_start = addr - image->sym_vvar_start;
36266- current->mm->context.vdso = (void __user *)text_start;
36267+ mm->context.vdso = text_start;
36268
36269 /*
36270 * MAYWRITE to allow gdb to COW and set breakpoints
36271@@ -163,15 +167,12 @@ static int map_vdso(const struct vdso_image *image, bool calculate_addr)
36272 hpet_address >> PAGE_SHIFT,
36273 PAGE_SIZE,
36274 pgprot_noncached(PAGE_READONLY));
36275-
36276- if (ret)
36277- goto up_fail;
36278 }
36279 #endif
36280
36281 up_fail:
36282 if (ret)
36283- current->mm->context.vdso = NULL;
36284+ current->mm->context.vdso = 0;
36285
36286 up_write(&mm->mmap_sem);
36287 return ret;
36288@@ -191,8 +192,8 @@ static int load_vdso32(void)
36289
36290 if (selected_vdso32->sym_VDSO32_SYSENTER_RETURN)
36291 current_thread_info()->sysenter_return =
36292- current->mm->context.vdso +
36293- selected_vdso32->sym_VDSO32_SYSENTER_RETURN;
36294+ (void __force_user *)(current->mm->context.vdso +
36295+ selected_vdso32->sym_VDSO32_SYSENTER_RETURN);
36296
36297 return 0;
36298 }
36299@@ -201,9 +202,6 @@ static int load_vdso32(void)
36300 #ifdef CONFIG_X86_64
36301 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
36302 {
36303- if (!vdso64_enabled)
36304- return 0;
36305-
36306 return map_vdso(&vdso_image_64, true);
36307 }
36308
36309@@ -212,12 +210,8 @@ int compat_arch_setup_additional_pages(struct linux_binprm *bprm,
36310 int uses_interp)
36311 {
36312 #ifdef CONFIG_X86_X32_ABI
36313- if (test_thread_flag(TIF_X32)) {
36314- if (!vdso64_enabled)
36315- return 0;
36316-
36317+ if (test_thread_flag(TIF_X32))
36318 return map_vdso(&vdso_image_x32, true);
36319- }
36320 #endif
36321
36322 return load_vdso32();
36323@@ -229,12 +223,3 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
36324 return load_vdso32();
36325 }
36326 #endif
36327-
36328-#ifdef CONFIG_X86_64
36329-static __init int vdso_setup(char *s)
36330-{
36331- vdso64_enabled = simple_strtoul(s, NULL, 0);
36332- return 0;
36333-}
36334-__setup("vdso=", vdso_setup);
36335-#endif
36336diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
36337index e88fda8..76ce7ce 100644
36338--- a/arch/x86/xen/Kconfig
36339+++ b/arch/x86/xen/Kconfig
36340@@ -9,6 +9,7 @@ config XEN
36341 select XEN_HAVE_PVMMU
36342 depends on X86_64 || (X86_32 && X86_PAE)
36343 depends on X86_TSC
36344+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
36345 help
36346 This is the Linux Xen port. Enabling this will allow the
36347 kernel to boot in a paravirtualized environment under the
36348diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
36349index c0cb11f..bed56ff 100644
36350--- a/arch/x86/xen/enlighten.c
36351+++ b/arch/x86/xen/enlighten.c
36352@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
36353
36354 struct shared_info xen_dummy_shared_info;
36355
36356-void *xen_initial_gdt;
36357-
36358 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
36359 __read_mostly int xen_have_vector_callback;
36360 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
36361@@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
36362 {
36363 unsigned long va = dtr->address;
36364 unsigned int size = dtr->size + 1;
36365- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
36366- unsigned long frames[pages];
36367+ unsigned long frames[65536 / PAGE_SIZE];
36368 int f;
36369
36370 /*
36371@@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
36372 {
36373 unsigned long va = dtr->address;
36374 unsigned int size = dtr->size + 1;
36375- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
36376- unsigned long frames[pages];
36377+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
36378 int f;
36379
36380 /*
36381@@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
36382 * 8-byte entries, or 16 4k pages..
36383 */
36384
36385- BUG_ON(size > 65536);
36386+ BUG_ON(size > GDT_SIZE);
36387 BUG_ON(va & ~PAGE_MASK);
36388
36389 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
36390@@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
36391 return 0;
36392 }
36393
36394-static void set_xen_basic_apic_ops(void)
36395+static void __init set_xen_basic_apic_ops(void)
36396 {
36397 apic->read = xen_apic_read;
36398 apic->write = xen_apic_write;
36399@@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
36400 #endif
36401 };
36402
36403-static void xen_reboot(int reason)
36404+static __noreturn void xen_reboot(int reason)
36405 {
36406 struct sched_shutdown r = { .reason = reason };
36407
36408- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
36409- BUG();
36410+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
36411+ BUG();
36412 }
36413
36414-static void xen_restart(char *msg)
36415+static __noreturn void xen_restart(char *msg)
36416 {
36417 xen_reboot(SHUTDOWN_reboot);
36418 }
36419
36420-static void xen_emergency_restart(void)
36421+static __noreturn void xen_emergency_restart(void)
36422 {
36423 xen_reboot(SHUTDOWN_reboot);
36424 }
36425
36426-static void xen_machine_halt(void)
36427+static __noreturn void xen_machine_halt(void)
36428 {
36429 xen_reboot(SHUTDOWN_poweroff);
36430 }
36431
36432-static void xen_machine_power_off(void)
36433+static __noreturn void xen_machine_power_off(void)
36434 {
36435 if (pm_power_off)
36436 pm_power_off();
36437@@ -1568,7 +1564,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
36438 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
36439
36440 /* Work out if we support NX */
36441- x86_configure_nx();
36442+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
36443+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
36444+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
36445+ unsigned l, h;
36446+
36447+ __supported_pte_mask |= _PAGE_NX;
36448+ rdmsr(MSR_EFER, l, h);
36449+ l |= EFER_NX;
36450+ wrmsr(MSR_EFER, l, h);
36451+ }
36452+#endif
36453
36454 /* Get mfn list */
36455 xen_build_dynamic_phys_to_machine();
36456@@ -1596,13 +1602,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
36457
36458 machine_ops = xen_machine_ops;
36459
36460- /*
36461- * The only reliable way to retain the initial address of the
36462- * percpu gdt_page is to remember it here, so we can go and
36463- * mark it RW later, when the initial percpu area is freed.
36464- */
36465- xen_initial_gdt = &per_cpu(gdt_page, 0);
36466-
36467 xen_smp_init();
36468
36469 #ifdef CONFIG_ACPI_NUMA
36470diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
36471index 16fb009..02b7801 100644
36472--- a/arch/x86/xen/mmu.c
36473+++ b/arch/x86/xen/mmu.c
36474@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
36475 return val;
36476 }
36477
36478-static pteval_t pte_pfn_to_mfn(pteval_t val)
36479+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
36480 {
36481 if (val & _PAGE_PRESENT) {
36482 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
36483@@ -1904,7 +1904,11 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
36484 * L3_k[511] -> level2_fixmap_pgt */
36485 convert_pfn_mfn(level3_kernel_pgt);
36486
36487+ convert_pfn_mfn(level3_vmalloc_start_pgt);
36488+ convert_pfn_mfn(level3_vmalloc_end_pgt);
36489+ convert_pfn_mfn(level3_vmemmap_pgt);
36490 /* L3_k[511][506] -> level1_fixmap_pgt */
36491+ /* L3_k[511][507] -> level1_vsyscall_pgt */
36492 convert_pfn_mfn(level2_fixmap_pgt);
36493 }
36494 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
36495@@ -1929,11 +1933,16 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
36496 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
36497 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
36498 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
36499+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
36500+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
36501+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
36502 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
36503 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
36504+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
36505 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
36506 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
36507 set_page_prot(level1_fixmap_pgt, PAGE_KERNEL_RO);
36508+ set_page_prot(level1_vsyscall_pgt, PAGE_KERNEL_RO);
36509
36510 /* Pin down new L4 */
36511 pin_pagetable_pfn(MMUEXT_PIN_L4_TABLE,
36512@@ -2117,6 +2126,7 @@ static void __init xen_post_allocator_init(void)
36513 pv_mmu_ops.set_pud = xen_set_pud;
36514 #if PAGETABLE_LEVELS == 4
36515 pv_mmu_ops.set_pgd = xen_set_pgd;
36516+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
36517 #endif
36518
36519 /* This will work as long as patching hasn't happened yet
36520@@ -2195,6 +2205,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
36521 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
36522 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
36523 .set_pgd = xen_set_pgd_hyper,
36524+ .set_pgd_batched = xen_set_pgd_hyper,
36525
36526 .alloc_pud = xen_alloc_pmd_init,
36527 .release_pud = xen_release_pmd_init,
36528diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
36529index 7005974..54fb05f 100644
36530--- a/arch/x86/xen/smp.c
36531+++ b/arch/x86/xen/smp.c
36532@@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
36533
36534 if (xen_pv_domain()) {
36535 if (!xen_feature(XENFEAT_writable_page_tables))
36536- /* We've switched to the "real" per-cpu gdt, so make
36537- * sure the old memory can be recycled. */
36538- make_lowmem_page_readwrite(xen_initial_gdt);
36539-
36540 #ifdef CONFIG_X86_32
36541 /*
36542 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
36543 * expects __USER_DS
36544 */
36545- loadsegment(ds, __USER_DS);
36546- loadsegment(es, __USER_DS);
36547+ loadsegment(ds, __KERNEL_DS);
36548+ loadsegment(es, __KERNEL_DS);
36549 #endif
36550
36551 xen_filter_cpu_maps();
36552@@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36553 #ifdef CONFIG_X86_32
36554 /* Note: PVH is not yet supported on x86_32. */
36555 ctxt->user_regs.fs = __KERNEL_PERCPU;
36556- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
36557+ savesegment(gs, ctxt->user_regs.gs);
36558 #endif
36559 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
36560
36561@@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
36562 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
36563 ctxt->flags = VGCF_IN_KERNEL;
36564 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
36565- ctxt->user_regs.ds = __USER_DS;
36566- ctxt->user_regs.es = __USER_DS;
36567+ ctxt->user_regs.ds = __KERNEL_DS;
36568+ ctxt->user_regs.es = __KERNEL_DS;
36569 ctxt->user_regs.ss = __KERNEL_DS;
36570
36571 xen_copy_trap_info(ctxt->trap_ctxt);
36572@@ -437,14 +433,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
36573 int rc;
36574
36575 per_cpu(current_task, cpu) = idle;
36576+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
36577 #ifdef CONFIG_X86_32
36578 irq_ctx_init(cpu);
36579 #else
36580 clear_tsk_thread_flag(idle, TIF_FORK);
36581 #endif
36582- per_cpu(kernel_stack, cpu) =
36583- (unsigned long)task_stack_page(idle) -
36584- KERNEL_STACK_OFFSET + THREAD_SIZE;
36585+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
36586
36587 xen_setup_runstate_info(cpu);
36588 xen_setup_timer(cpu);
36589@@ -720,7 +715,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
36590
36591 void __init xen_smp_init(void)
36592 {
36593- smp_ops = xen_smp_ops;
36594+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
36595 xen_fill_possible_map();
36596 }
36597
36598diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
36599index fd92a64..1f72641 100644
36600--- a/arch/x86/xen/xen-asm_32.S
36601+++ b/arch/x86/xen/xen-asm_32.S
36602@@ -99,7 +99,7 @@ ENTRY(xen_iret)
36603 pushw %fs
36604 movl $(__KERNEL_PERCPU), %eax
36605 movl %eax, %fs
36606- movl %fs:xen_vcpu, %eax
36607+ mov PER_CPU_VAR(xen_vcpu), %eax
36608 POP_FS
36609 #else
36610 movl %ss:xen_vcpu, %eax
36611diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
36612index 485b695..fda3e7c 100644
36613--- a/arch/x86/xen/xen-head.S
36614+++ b/arch/x86/xen/xen-head.S
36615@@ -39,6 +39,17 @@ ENTRY(startup_xen)
36616 #ifdef CONFIG_X86_32
36617 mov %esi,xen_start_info
36618 mov $init_thread_union+THREAD_SIZE,%esp
36619+#ifdef CONFIG_SMP
36620+ movl $cpu_gdt_table,%edi
36621+ movl $__per_cpu_load,%eax
36622+ movw %ax,__KERNEL_PERCPU + 2(%edi)
36623+ rorl $16,%eax
36624+ movb %al,__KERNEL_PERCPU + 4(%edi)
36625+ movb %ah,__KERNEL_PERCPU + 7(%edi)
36626+ movl $__per_cpu_end - 1,%eax
36627+ subl $__per_cpu_start,%eax
36628+ movw %ax,__KERNEL_PERCPU + 0(%edi)
36629+#endif
36630 #else
36631 mov %rsi,xen_start_info
36632 mov $init_thread_union+THREAD_SIZE,%rsp
36633diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
36634index 28c7e0b..2acfec7 100644
36635--- a/arch/x86/xen/xen-ops.h
36636+++ b/arch/x86/xen/xen-ops.h
36637@@ -10,8 +10,6 @@
36638 extern const char xen_hypervisor_callback[];
36639 extern const char xen_failsafe_callback[];
36640
36641-extern void *xen_initial_gdt;
36642-
36643 struct trap_info;
36644 void xen_copy_trap_info(struct trap_info *traps);
36645
36646diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
36647index 525bd3d..ef888b1 100644
36648--- a/arch/xtensa/variants/dc232b/include/variant/core.h
36649+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
36650@@ -119,9 +119,9 @@
36651 ----------------------------------------------------------------------*/
36652
36653 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
36654-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
36655 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
36656 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
36657+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36658
36659 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
36660 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
36661diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
36662index 2f33760..835e50a 100644
36663--- a/arch/xtensa/variants/fsf/include/variant/core.h
36664+++ b/arch/xtensa/variants/fsf/include/variant/core.h
36665@@ -11,6 +11,7 @@
36666 #ifndef _XTENSA_CORE_H
36667 #define _XTENSA_CORE_H
36668
36669+#include <linux/const.h>
36670
36671 /****************************************************************************
36672 Parameters Useful for Any Code, USER or PRIVILEGED
36673@@ -112,9 +113,9 @@
36674 ----------------------------------------------------------------------*/
36675
36676 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36677-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36678 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36679 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36680+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36681
36682 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
36683 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
36684diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
36685index af00795..2bb8105 100644
36686--- a/arch/xtensa/variants/s6000/include/variant/core.h
36687+++ b/arch/xtensa/variants/s6000/include/variant/core.h
36688@@ -11,6 +11,7 @@
36689 #ifndef _XTENSA_CORE_CONFIGURATION_H
36690 #define _XTENSA_CORE_CONFIGURATION_H
36691
36692+#include <linux/const.h>
36693
36694 /****************************************************************************
36695 Parameters Useful for Any Code, USER or PRIVILEGED
36696@@ -118,9 +119,9 @@
36697 ----------------------------------------------------------------------*/
36698
36699 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
36700-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
36701 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
36702 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
36703+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
36704
36705 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
36706 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
36707diff --git a/block/bio.c b/block/bio.c
36708index 3e6331d..f970433 100644
36709--- a/block/bio.c
36710+++ b/block/bio.c
36711@@ -1160,7 +1160,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
36712 /*
36713 * Overflow, abort
36714 */
36715- if (end < start)
36716+ if (end < start || end - start > INT_MAX - nr_pages)
36717 return ERR_PTR(-EINVAL);
36718
36719 nr_pages += end - start;
36720@@ -1294,7 +1294,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
36721 /*
36722 * Overflow, abort
36723 */
36724- if (end < start)
36725+ if (end < start || end - start > INT_MAX - nr_pages)
36726 return ERR_PTR(-EINVAL);
36727
36728 nr_pages += end - start;
36729@@ -1556,7 +1556,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
36730 const int read = bio_data_dir(bio) == READ;
36731 struct bio_map_data *bmd = bio->bi_private;
36732 int i;
36733- char *p = bmd->sgvecs[0].iov_base;
36734+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
36735
36736 bio_for_each_segment_all(bvec, bio, i) {
36737 char *addr = page_address(bvec->bv_page);
36738diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
36739index e17da94..e01cce1 100644
36740--- a/block/blk-cgroup.c
36741+++ b/block/blk-cgroup.c
36742@@ -822,7 +822,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
36743 static struct cgroup_subsys_state *
36744 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36745 {
36746- static atomic64_t id_seq = ATOMIC64_INIT(0);
36747+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
36748 struct blkcg *blkcg;
36749
36750 if (!parent_css) {
36751@@ -836,7 +836,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
36752
36753 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
36754 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
36755- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
36756+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
36757 done:
36758 spin_lock_init(&blkcg->lock);
36759 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
36760diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
36761index 0736729..2ec3b48 100644
36762--- a/block/blk-iopoll.c
36763+++ b/block/blk-iopoll.c
36764@@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iop)
36765 }
36766 EXPORT_SYMBOL(blk_iopoll_complete);
36767
36768-static void blk_iopoll_softirq(struct softirq_action *h)
36769+static __latent_entropy void blk_iopoll_softirq(void)
36770 {
36771 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
36772 int rearm = 0, budget = blk_iopoll_budget;
36773diff --git a/block/blk-map.c b/block/blk-map.c
36774index f890d43..97b0482 100644
36775--- a/block/blk-map.c
36776+++ b/block/blk-map.c
36777@@ -300,7 +300,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
36778 if (!len || !kbuf)
36779 return -EINVAL;
36780
36781- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
36782+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
36783 if (do_copy)
36784 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
36785 else
36786diff --git a/block/blk-softirq.c b/block/blk-softirq.c
36787index 53b1737..08177d2e 100644
36788--- a/block/blk-softirq.c
36789+++ b/block/blk-softirq.c
36790@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
36791 * Softirq action handler - move entries to local list and loop over them
36792 * while passing them to the queue registered handler.
36793 */
36794-static void blk_done_softirq(struct softirq_action *h)
36795+static __latent_entropy void blk_done_softirq(void)
36796 {
36797 struct list_head *cpu_list, local_list;
36798
36799diff --git a/block/bsg.c b/block/bsg.c
36800index ff46add..c4ba8ee 100644
36801--- a/block/bsg.c
36802+++ b/block/bsg.c
36803@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
36804 struct sg_io_v4 *hdr, struct bsg_device *bd,
36805 fmode_t has_write_perm)
36806 {
36807+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36808+ unsigned char *cmdptr;
36809+
36810 if (hdr->request_len > BLK_MAX_CDB) {
36811 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
36812 if (!rq->cmd)
36813 return -ENOMEM;
36814- }
36815+ cmdptr = rq->cmd;
36816+ } else
36817+ cmdptr = tmpcmd;
36818
36819- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
36820+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
36821 hdr->request_len))
36822 return -EFAULT;
36823
36824+ if (cmdptr != rq->cmd)
36825+ memcpy(rq->cmd, cmdptr, hdr->request_len);
36826+
36827 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
36828 if (blk_verify_command(rq->cmd, has_write_perm))
36829 return -EPERM;
36830diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
36831index 18b282c..050dbe5 100644
36832--- a/block/compat_ioctl.c
36833+++ b/block/compat_ioctl.c
36834@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
36835 cgc = compat_alloc_user_space(sizeof(*cgc));
36836 cgc32 = compat_ptr(arg);
36837
36838- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
36839+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
36840 get_user(data, &cgc32->buffer) ||
36841 put_user(compat_ptr(data), &cgc->buffer) ||
36842 copy_in_user(&cgc->buflen, &cgc32->buflen,
36843@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
36844 err |= __get_user(f->spec1, &uf->spec1);
36845 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
36846 err |= __get_user(name, &uf->name);
36847- f->name = compat_ptr(name);
36848+ f->name = (void __force_kernel *)compat_ptr(name);
36849 if (err) {
36850 err = -EFAULT;
36851 goto out;
36852diff --git a/block/genhd.c b/block/genhd.c
36853index e6723bd..703e4ac 100644
36854--- a/block/genhd.c
36855+++ b/block/genhd.c
36856@@ -469,21 +469,24 @@ static char *bdevt_str(dev_t devt, char *buf)
36857
36858 /*
36859 * Register device numbers dev..(dev+range-1)
36860- * range must be nonzero
36861+ * Noop if @range is zero.
36862 * The hash chain is sorted on range, so that subranges can override.
36863 */
36864 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
36865 struct kobject *(*probe)(dev_t, int *, void *),
36866 int (*lock)(dev_t, void *), void *data)
36867 {
36868- kobj_map(bdev_map, devt, range, module, probe, lock, data);
36869+ if (range)
36870+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
36871 }
36872
36873 EXPORT_SYMBOL(blk_register_region);
36874
36875+/* undo blk_register_region(), noop if @range is zero */
36876 void blk_unregister_region(dev_t devt, unsigned long range)
36877 {
36878- kobj_unmap(bdev_map, devt, range);
36879+ if (range)
36880+ kobj_unmap(bdev_map, devt, range);
36881 }
36882
36883 EXPORT_SYMBOL(blk_unregister_region);
36884diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36885index 56d08fd..2e07090 100644
36886--- a/block/partitions/efi.c
36887+++ b/block/partitions/efi.c
36888@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36889 if (!gpt)
36890 return NULL;
36891
36892+ if (!le32_to_cpu(gpt->num_partition_entries))
36893+ return NULL;
36894+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36895+ if (!pte)
36896+ return NULL;
36897+
36898 count = le32_to_cpu(gpt->num_partition_entries) *
36899 le32_to_cpu(gpt->sizeof_partition_entry);
36900- if (!count)
36901- return NULL;
36902- pte = kmalloc(count, GFP_KERNEL);
36903- if (!pte)
36904- return NULL;
36905-
36906 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36907 (u8 *) pte, count) < count) {
36908 kfree(pte);
36909diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36910index a6d6270..c4bb72f 100644
36911--- a/block/scsi_ioctl.c
36912+++ b/block/scsi_ioctl.c
36913@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36914 return put_user(0, p);
36915 }
36916
36917-static int sg_get_timeout(struct request_queue *q)
36918+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36919 {
36920 return jiffies_to_clock_t(q->sg_timeout);
36921 }
36922@@ -227,8 +227,20 @@ EXPORT_SYMBOL(blk_verify_command);
36923 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36924 struct sg_io_hdr *hdr, fmode_t mode)
36925 {
36926- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36927+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36928+ unsigned char *cmdptr;
36929+
36930+ if (rq->cmd != rq->__cmd)
36931+ cmdptr = rq->cmd;
36932+ else
36933+ cmdptr = tmpcmd;
36934+
36935+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36936 return -EFAULT;
36937+
36938+ if (cmdptr != rq->cmd)
36939+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36940+
36941 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36942 return -EPERM;
36943
36944@@ -432,6 +444,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36945 int err;
36946 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36947 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36948+ unsigned char tmpcmd[sizeof(rq->__cmd)];
36949+ unsigned char *cmdptr;
36950
36951 if (!sic)
36952 return -EINVAL;
36953@@ -470,9 +484,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36954 */
36955 err = -EFAULT;
36956 rq->cmd_len = cmdlen;
36957- if (copy_from_user(rq->cmd, sic->data, cmdlen))
36958+
36959+ if (rq->cmd != rq->__cmd)
36960+ cmdptr = rq->cmd;
36961+ else
36962+ cmdptr = tmpcmd;
36963+
36964+ if (copy_from_user(cmdptr, sic->data, cmdlen))
36965 goto error;
36966
36967+ if (rq->cmd != cmdptr)
36968+ memcpy(rq->cmd, cmdptr, cmdlen);
36969+
36970 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36971 goto error;
36972
36973diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36974index e592c90..c566114 100644
36975--- a/crypto/cryptd.c
36976+++ b/crypto/cryptd.c
36977@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36978
36979 struct cryptd_blkcipher_request_ctx {
36980 crypto_completion_t complete;
36981-};
36982+} __no_const;
36983
36984 struct cryptd_hash_ctx {
36985 struct crypto_shash *child;
36986@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36987
36988 struct cryptd_aead_request_ctx {
36989 crypto_completion_t complete;
36990-};
36991+} __no_const;
36992
36993 static void cryptd_queue_worker(struct work_struct *work);
36994
36995diff --git a/crypto/cts.c b/crypto/cts.c
36996index 042223f..133f087 100644
36997--- a/crypto/cts.c
36998+++ b/crypto/cts.c
36999@@ -202,7 +202,8 @@ static int cts_cbc_decrypt(struct crypto_cts_ctx *ctx,
37000 /* 5. Append the tail (BB - Ln) bytes of Xn (tmp) to Cn to create En */
37001 memcpy(s + bsize + lastn, tmp + lastn, bsize - lastn);
37002 /* 6. Decrypt En to create Pn-1 */
37003- memset(iv, 0, sizeof(iv));
37004+ memzero_explicit(iv, sizeof(iv));
37005+
37006 sg_set_buf(&sgsrc[0], s + bsize, bsize);
37007 sg_set_buf(&sgdst[0], d, bsize);
37008 err = crypto_blkcipher_decrypt_iv(&lcldesc, sgdst, sgsrc, bsize);
37009diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
37010index 309d345..1632720 100644
37011--- a/crypto/pcrypt.c
37012+++ b/crypto/pcrypt.c
37013@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
37014 int ret;
37015
37016 pinst->kobj.kset = pcrypt_kset;
37017- ret = kobject_add(&pinst->kobj, NULL, name);
37018+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
37019 if (!ret)
37020 kobject_uevent(&pinst->kobj, KOBJ_ADD);
37021
37022diff --git a/crypto/sha1_generic.c b/crypto/sha1_generic.c
37023index 4279480..7bb0474 100644
37024--- a/crypto/sha1_generic.c
37025+++ b/crypto/sha1_generic.c
37026@@ -64,7 +64,7 @@ int crypto_sha1_update(struct shash_desc *desc, const u8 *data,
37027 src = data + done;
37028 } while (done + SHA1_BLOCK_SIZE <= len);
37029
37030- memset(temp, 0, sizeof(temp));
37031+ memzero_explicit(temp, sizeof(temp));
37032 partial = 0;
37033 }
37034 memcpy(sctx->buffer + partial, src, len - done);
37035diff --git a/crypto/sha256_generic.c b/crypto/sha256_generic.c
37036index 5433667..32c5e5e 100644
37037--- a/crypto/sha256_generic.c
37038+++ b/crypto/sha256_generic.c
37039@@ -210,10 +210,9 @@ static void sha256_transform(u32 *state, const u8 *input)
37040
37041 /* clear any sensitive info... */
37042 a = b = c = d = e = f = g = h = t1 = t2 = 0;
37043- memset(W, 0, 64 * sizeof(u32));
37044+ memzero_explicit(W, 64 * sizeof(u32));
37045 }
37046
37047-
37048 static int sha224_init(struct shash_desc *desc)
37049 {
37050 struct sha256_state *sctx = shash_desc_ctx(desc);
37051@@ -316,7 +315,7 @@ static int sha224_final(struct shash_desc *desc, u8 *hash)
37052 sha256_final(desc, D);
37053
37054 memcpy(hash, D, SHA224_DIGEST_SIZE);
37055- memset(D, 0, SHA256_DIGEST_SIZE);
37056+ memzero_explicit(D, SHA256_DIGEST_SIZE);
37057
37058 return 0;
37059 }
37060diff --git a/crypto/sha512_generic.c b/crypto/sha512_generic.c
37061index 6ed124f..04d295a 100644
37062--- a/crypto/sha512_generic.c
37063+++ b/crypto/sha512_generic.c
37064@@ -238,7 +238,7 @@ static int sha384_final(struct shash_desc *desc, u8 *hash)
37065 sha512_final(desc, D);
37066
37067 memcpy(hash, D, 48);
37068- memset(D, 0, 64);
37069+ memzero_explicit(D, 64);
37070
37071 return 0;
37072 }
37073diff --git a/crypto/tgr192.c b/crypto/tgr192.c
37074index 8740355..3c7af0d 100644
37075--- a/crypto/tgr192.c
37076+++ b/crypto/tgr192.c
37077@@ -612,7 +612,7 @@ static int tgr160_final(struct shash_desc *desc, u8 * out)
37078
37079 tgr192_final(desc, D);
37080 memcpy(out, D, TGR160_DIGEST_SIZE);
37081- memset(D, 0, TGR192_DIGEST_SIZE);
37082+ memzero_explicit(D, TGR192_DIGEST_SIZE);
37083
37084 return 0;
37085 }
37086@@ -623,7 +623,7 @@ static int tgr128_final(struct shash_desc *desc, u8 * out)
37087
37088 tgr192_final(desc, D);
37089 memcpy(out, D, TGR128_DIGEST_SIZE);
37090- memset(D, 0, TGR192_DIGEST_SIZE);
37091+ memzero_explicit(D, TGR192_DIGEST_SIZE);
37092
37093 return 0;
37094 }
37095diff --git a/crypto/vmac.c b/crypto/vmac.c
37096index 2eb11a3..d84c24b 100644
37097--- a/crypto/vmac.c
37098+++ b/crypto/vmac.c
37099@@ -613,7 +613,7 @@ static int vmac_final(struct shash_desc *pdesc, u8 *out)
37100 }
37101 mac = vmac(ctx->partial, ctx->partial_size, nonce, NULL, ctx);
37102 memcpy(out, &mac, sizeof(vmac_t));
37103- memset(&mac, 0, sizeof(vmac_t));
37104+ memzero_explicit(&mac, sizeof(vmac_t));
37105 memset(&ctx->__vmac_ctx, 0, sizeof(struct vmac_ctx));
37106 ctx->partial_size = 0;
37107 return 0;
37108diff --git a/crypto/wp512.c b/crypto/wp512.c
37109index 180f1d6..ec64e77 100644
37110--- a/crypto/wp512.c
37111+++ b/crypto/wp512.c
37112@@ -1102,8 +1102,8 @@ static int wp384_final(struct shash_desc *desc, u8 *out)
37113 u8 D[64];
37114
37115 wp512_final(desc, D);
37116- memcpy (out, D, WP384_DIGEST_SIZE);
37117- memset (D, 0, WP512_DIGEST_SIZE);
37118+ memcpy(out, D, WP384_DIGEST_SIZE);
37119+ memzero_explicit(D, WP512_DIGEST_SIZE);
37120
37121 return 0;
37122 }
37123@@ -1113,8 +1113,8 @@ static int wp256_final(struct shash_desc *desc, u8 *out)
37124 u8 D[64];
37125
37126 wp512_final(desc, D);
37127- memcpy (out, D, WP256_DIGEST_SIZE);
37128- memset (D, 0, WP512_DIGEST_SIZE);
37129+ memcpy(out, D, WP256_DIGEST_SIZE);
37130+ memzero_explicit(D, WP512_DIGEST_SIZE);
37131
37132 return 0;
37133 }
37134diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
37135index 6921c7f..78e1af7 100644
37136--- a/drivers/acpi/acpica/hwxfsleep.c
37137+++ b/drivers/acpi/acpica/hwxfsleep.c
37138@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
37139 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
37140
37141 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
37142- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
37143- acpi_hw_extended_sleep},
37144- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
37145- acpi_hw_extended_wake_prep},
37146- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
37147+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
37148+ .extended_function = acpi_hw_extended_sleep},
37149+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
37150+ .extended_function = acpi_hw_extended_wake_prep},
37151+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
37152+ .extended_function = acpi_hw_extended_wake}
37153 };
37154
37155 /*
37156diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
37157index 16129c7..8b675cd 100644
37158--- a/drivers/acpi/apei/apei-internal.h
37159+++ b/drivers/acpi/apei/apei-internal.h
37160@@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
37161 struct apei_exec_ins_type {
37162 u32 flags;
37163 apei_exec_ins_func_t run;
37164-};
37165+} __do_const;
37166
37167 struct apei_exec_context {
37168 u32 ip;
37169diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
37170index fc5f780..e5ac91a 100644
37171--- a/drivers/acpi/apei/ghes.c
37172+++ b/drivers/acpi/apei/ghes.c
37173@@ -478,7 +478,7 @@ static void __ghes_print_estatus(const char *pfx,
37174 const struct acpi_hest_generic *generic,
37175 const struct acpi_hest_generic_status *estatus)
37176 {
37177- static atomic_t seqno;
37178+ static atomic_unchecked_t seqno;
37179 unsigned int curr_seqno;
37180 char pfx_seq[64];
37181
37182@@ -489,7 +489,7 @@ static void __ghes_print_estatus(const char *pfx,
37183 else
37184 pfx = KERN_ERR;
37185 }
37186- curr_seqno = atomic_inc_return(&seqno);
37187+ curr_seqno = atomic_inc_return_unchecked(&seqno);
37188 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
37189 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
37190 pfx_seq, generic->header.source_id);
37191diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
37192index a83e3c6..c3d617f 100644
37193--- a/drivers/acpi/bgrt.c
37194+++ b/drivers/acpi/bgrt.c
37195@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
37196 if (!bgrt_image)
37197 return -ENODEV;
37198
37199- bin_attr_image.private = bgrt_image;
37200- bin_attr_image.size = bgrt_image_size;
37201+ pax_open_kernel();
37202+ *(void **)&bin_attr_image.private = bgrt_image;
37203+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
37204+ pax_close_kernel();
37205
37206 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
37207 if (!bgrt_kobj)
37208diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
37209index 36eb42e..3b2f47e 100644
37210--- a/drivers/acpi/blacklist.c
37211+++ b/drivers/acpi/blacklist.c
37212@@ -51,7 +51,7 @@ struct acpi_blacklist_item {
37213 u32 is_critical_error;
37214 };
37215
37216-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
37217+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
37218
37219 /*
37220 * POLICY: If *anything* doesn't work, put it on the blacklist.
37221@@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
37222 return 0;
37223 }
37224
37225-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
37226+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
37227 {
37228 .callback = dmi_disable_osi_vista,
37229 .ident = "Fujitsu Siemens",
37230diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
37231index c68e724..e863008 100644
37232--- a/drivers/acpi/custom_method.c
37233+++ b/drivers/acpi/custom_method.c
37234@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
37235 struct acpi_table_header table;
37236 acpi_status status;
37237
37238+#ifdef CONFIG_GRKERNSEC_KMEM
37239+ return -EPERM;
37240+#endif
37241+
37242 if (!(*ppos)) {
37243 /* parse the table header to get the table length */
37244 if (count <= sizeof(struct acpi_table_header))
37245diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
37246index 17f9ec5..d9a455e 100644
37247--- a/drivers/acpi/processor_idle.c
37248+++ b/drivers/acpi/processor_idle.c
37249@@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
37250 {
37251 int i, count = CPUIDLE_DRIVER_STATE_START;
37252 struct acpi_processor_cx *cx;
37253- struct cpuidle_state *state;
37254+ cpuidle_state_no_const *state;
37255 struct cpuidle_driver *drv = &acpi_idle_driver;
37256
37257 if (!pr->flags.power_setup_done)
37258diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
37259index 38cb978..352c761 100644
37260--- a/drivers/acpi/sysfs.c
37261+++ b/drivers/acpi/sysfs.c
37262@@ -423,11 +423,11 @@ static u32 num_counters;
37263 static struct attribute **all_attrs;
37264 static u32 acpi_gpe_count;
37265
37266-static struct attribute_group interrupt_stats_attr_group = {
37267+static attribute_group_no_const interrupt_stats_attr_group = {
37268 .name = "interrupts",
37269 };
37270
37271-static struct kobj_attribute *counter_attrs;
37272+static kobj_attribute_no_const *counter_attrs;
37273
37274 static void delete_gpe_attr_array(void)
37275 {
37276diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
37277index b784e9d..a69a049 100644
37278--- a/drivers/ata/libahci.c
37279+++ b/drivers/ata/libahci.c
37280@@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
37281 }
37282 EXPORT_SYMBOL_GPL(ahci_kick_engine);
37283
37284-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
37285+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
37286 struct ata_taskfile *tf, int is_cmd, u16 flags,
37287 unsigned long timeout_msec)
37288 {
37289diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
37290index 6f67490..f951ead 100644
37291--- a/drivers/ata/libata-core.c
37292+++ b/drivers/ata/libata-core.c
37293@@ -99,7 +99,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
37294 static void ata_dev_xfermask(struct ata_device *dev);
37295 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
37296
37297-atomic_t ata_print_id = ATOMIC_INIT(0);
37298+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
37299
37300 struct ata_force_param {
37301 const char *name;
37302@@ -4797,7 +4797,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
37303 struct ata_port *ap;
37304 unsigned int tag;
37305
37306- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37307+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37308 ap = qc->ap;
37309
37310 qc->flags = 0;
37311@@ -4813,7 +4813,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
37312 struct ata_port *ap;
37313 struct ata_link *link;
37314
37315- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37316+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
37317 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
37318 ap = qc->ap;
37319 link = qc->dev->link;
37320@@ -5917,6 +5917,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
37321 return;
37322
37323 spin_lock(&lock);
37324+ pax_open_kernel();
37325
37326 for (cur = ops->inherits; cur; cur = cur->inherits) {
37327 void **inherit = (void **)cur;
37328@@ -5930,8 +5931,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
37329 if (IS_ERR(*pp))
37330 *pp = NULL;
37331
37332- ops->inherits = NULL;
37333+ *(struct ata_port_operations **)&ops->inherits = NULL;
37334
37335+ pax_close_kernel();
37336 spin_unlock(&lock);
37337 }
37338
37339@@ -6127,7 +6129,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
37340
37341 /* give ports names and add SCSI hosts */
37342 for (i = 0; i < host->n_ports; i++) {
37343- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
37344+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
37345 host->ports[i]->local_port_no = i + 1;
37346 }
37347
37348diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
37349index 0586f66..1a8f74a 100644
37350--- a/drivers/ata/libata-scsi.c
37351+++ b/drivers/ata/libata-scsi.c
37352@@ -4151,7 +4151,7 @@ int ata_sas_port_init(struct ata_port *ap)
37353
37354 if (rc)
37355 return rc;
37356- ap->print_id = atomic_inc_return(&ata_print_id);
37357+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
37358 return 0;
37359 }
37360 EXPORT_SYMBOL_GPL(ata_sas_port_init);
37361diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
37362index 5f4e0cc..ff2c347 100644
37363--- a/drivers/ata/libata.h
37364+++ b/drivers/ata/libata.h
37365@@ -53,7 +53,7 @@ enum {
37366 ATA_DNXFER_QUIET = (1 << 31),
37367 };
37368
37369-extern atomic_t ata_print_id;
37370+extern atomic_unchecked_t ata_print_id;
37371 extern int atapi_passthru16;
37372 extern int libata_fua;
37373 extern int libata_noacpi;
37374diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
37375index 4edb1a8..84e1658 100644
37376--- a/drivers/ata/pata_arasan_cf.c
37377+++ b/drivers/ata/pata_arasan_cf.c
37378@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
37379 /* Handle platform specific quirks */
37380 if (quirk) {
37381 if (quirk & CF_BROKEN_PIO) {
37382- ap->ops->set_piomode = NULL;
37383+ pax_open_kernel();
37384+ *(void **)&ap->ops->set_piomode = NULL;
37385+ pax_close_kernel();
37386 ap->pio_mask = 0;
37387 }
37388 if (quirk & CF_BROKEN_MWDMA)
37389diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
37390index f9b983a..887b9d8 100644
37391--- a/drivers/atm/adummy.c
37392+++ b/drivers/atm/adummy.c
37393@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
37394 vcc->pop(vcc, skb);
37395 else
37396 dev_kfree_skb_any(skb);
37397- atomic_inc(&vcc->stats->tx);
37398+ atomic_inc_unchecked(&vcc->stats->tx);
37399
37400 return 0;
37401 }
37402diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
37403index f1a9198..f466a4a 100644
37404--- a/drivers/atm/ambassador.c
37405+++ b/drivers/atm/ambassador.c
37406@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
37407 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
37408
37409 // VC layer stats
37410- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37411+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37412
37413 // free the descriptor
37414 kfree (tx_descr);
37415@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
37416 dump_skb ("<<<", vc, skb);
37417
37418 // VC layer stats
37419- atomic_inc(&atm_vcc->stats->rx);
37420+ atomic_inc_unchecked(&atm_vcc->stats->rx);
37421 __net_timestamp(skb);
37422 // end of our responsibility
37423 atm_vcc->push (atm_vcc, skb);
37424@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
37425 } else {
37426 PRINTK (KERN_INFO, "dropped over-size frame");
37427 // should we count this?
37428- atomic_inc(&atm_vcc->stats->rx_drop);
37429+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37430 }
37431
37432 } else {
37433@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
37434 }
37435
37436 if (check_area (skb->data, skb->len)) {
37437- atomic_inc(&atm_vcc->stats->tx_err);
37438+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
37439 return -ENOMEM; // ?
37440 }
37441
37442diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
37443index 480fa6f..947067c 100644
37444--- a/drivers/atm/atmtcp.c
37445+++ b/drivers/atm/atmtcp.c
37446@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37447 if (vcc->pop) vcc->pop(vcc,skb);
37448 else dev_kfree_skb(skb);
37449 if (dev_data) return 0;
37450- atomic_inc(&vcc->stats->tx_err);
37451+ atomic_inc_unchecked(&vcc->stats->tx_err);
37452 return -ENOLINK;
37453 }
37454 size = skb->len+sizeof(struct atmtcp_hdr);
37455@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37456 if (!new_skb) {
37457 if (vcc->pop) vcc->pop(vcc,skb);
37458 else dev_kfree_skb(skb);
37459- atomic_inc(&vcc->stats->tx_err);
37460+ atomic_inc_unchecked(&vcc->stats->tx_err);
37461 return -ENOBUFS;
37462 }
37463 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
37464@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
37465 if (vcc->pop) vcc->pop(vcc,skb);
37466 else dev_kfree_skb(skb);
37467 out_vcc->push(out_vcc,new_skb);
37468- atomic_inc(&vcc->stats->tx);
37469- atomic_inc(&out_vcc->stats->rx);
37470+ atomic_inc_unchecked(&vcc->stats->tx);
37471+ atomic_inc_unchecked(&out_vcc->stats->rx);
37472 return 0;
37473 }
37474
37475@@ -300,7 +300,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
37476 read_unlock(&vcc_sklist_lock);
37477 if (!out_vcc) {
37478 result = -EUNATCH;
37479- atomic_inc(&vcc->stats->tx_err);
37480+ atomic_inc_unchecked(&vcc->stats->tx_err);
37481 goto done;
37482 }
37483 skb_pull(skb,sizeof(struct atmtcp_hdr));
37484@@ -312,8 +312,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
37485 __net_timestamp(new_skb);
37486 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
37487 out_vcc->push(out_vcc,new_skb);
37488- atomic_inc(&vcc->stats->tx);
37489- atomic_inc(&out_vcc->stats->rx);
37490+ atomic_inc_unchecked(&vcc->stats->tx);
37491+ atomic_inc_unchecked(&out_vcc->stats->rx);
37492 done:
37493 if (vcc->pop) vcc->pop(vcc,skb);
37494 else dev_kfree_skb(skb);
37495diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
37496index d65975a..0b87e20 100644
37497--- a/drivers/atm/eni.c
37498+++ b/drivers/atm/eni.c
37499@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
37500 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
37501 vcc->dev->number);
37502 length = 0;
37503- atomic_inc(&vcc->stats->rx_err);
37504+ atomic_inc_unchecked(&vcc->stats->rx_err);
37505 }
37506 else {
37507 length = ATM_CELL_SIZE-1; /* no HEC */
37508@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
37509 size);
37510 }
37511 eff = length = 0;
37512- atomic_inc(&vcc->stats->rx_err);
37513+ atomic_inc_unchecked(&vcc->stats->rx_err);
37514 }
37515 else {
37516 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
37517@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
37518 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
37519 vcc->dev->number,vcc->vci,length,size << 2,descr);
37520 length = eff = 0;
37521- atomic_inc(&vcc->stats->rx_err);
37522+ atomic_inc_unchecked(&vcc->stats->rx_err);
37523 }
37524 }
37525 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
37526@@ -767,7 +767,7 @@ rx_dequeued++;
37527 vcc->push(vcc,skb);
37528 pushed++;
37529 }
37530- atomic_inc(&vcc->stats->rx);
37531+ atomic_inc_unchecked(&vcc->stats->rx);
37532 }
37533 wake_up(&eni_dev->rx_wait);
37534 }
37535@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
37536 PCI_DMA_TODEVICE);
37537 if (vcc->pop) vcc->pop(vcc,skb);
37538 else dev_kfree_skb_irq(skb);
37539- atomic_inc(&vcc->stats->tx);
37540+ atomic_inc_unchecked(&vcc->stats->tx);
37541 wake_up(&eni_dev->tx_wait);
37542 dma_complete++;
37543 }
37544diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
37545index 82f2ae0..f205c02 100644
37546--- a/drivers/atm/firestream.c
37547+++ b/drivers/atm/firestream.c
37548@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
37549 }
37550 }
37551
37552- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37553+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37554
37555 fs_dprintk (FS_DEBUG_TXMEM, "i");
37556 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
37557@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
37558 #endif
37559 skb_put (skb, qe->p1 & 0xffff);
37560 ATM_SKB(skb)->vcc = atm_vcc;
37561- atomic_inc(&atm_vcc->stats->rx);
37562+ atomic_inc_unchecked(&atm_vcc->stats->rx);
37563 __net_timestamp(skb);
37564 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
37565 atm_vcc->push (atm_vcc, skb);
37566@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
37567 kfree (pe);
37568 }
37569 if (atm_vcc)
37570- atomic_inc(&atm_vcc->stats->rx_drop);
37571+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37572 break;
37573 case 0x1f: /* Reassembly abort: no buffers. */
37574 /* Silently increment error counter. */
37575 if (atm_vcc)
37576- atomic_inc(&atm_vcc->stats->rx_drop);
37577+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
37578 break;
37579 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
37580 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
37581diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
37582index d4725fc..2d4ea65 100644
37583--- a/drivers/atm/fore200e.c
37584+++ b/drivers/atm/fore200e.c
37585@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
37586 #endif
37587 /* check error condition */
37588 if (*entry->status & STATUS_ERROR)
37589- atomic_inc(&vcc->stats->tx_err);
37590+ atomic_inc_unchecked(&vcc->stats->tx_err);
37591 else
37592- atomic_inc(&vcc->stats->tx);
37593+ atomic_inc_unchecked(&vcc->stats->tx);
37594 }
37595 }
37596
37597@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
37598 if (skb == NULL) {
37599 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
37600
37601- atomic_inc(&vcc->stats->rx_drop);
37602+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37603 return -ENOMEM;
37604 }
37605
37606@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
37607
37608 dev_kfree_skb_any(skb);
37609
37610- atomic_inc(&vcc->stats->rx_drop);
37611+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37612 return -ENOMEM;
37613 }
37614
37615 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
37616
37617 vcc->push(vcc, skb);
37618- atomic_inc(&vcc->stats->rx);
37619+ atomic_inc_unchecked(&vcc->stats->rx);
37620
37621 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
37622
37623@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
37624 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
37625 fore200e->atm_dev->number,
37626 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
37627- atomic_inc(&vcc->stats->rx_err);
37628+ atomic_inc_unchecked(&vcc->stats->rx_err);
37629 }
37630 }
37631
37632@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
37633 goto retry_here;
37634 }
37635
37636- atomic_inc(&vcc->stats->tx_err);
37637+ atomic_inc_unchecked(&vcc->stats->tx_err);
37638
37639 fore200e->tx_sat++;
37640 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
37641diff --git a/drivers/atm/he.c b/drivers/atm/he.c
37642index c39702b..785b73b 100644
37643--- a/drivers/atm/he.c
37644+++ b/drivers/atm/he.c
37645@@ -1689,7 +1689,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37646
37647 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
37648 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
37649- atomic_inc(&vcc->stats->rx_drop);
37650+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37651 goto return_host_buffers;
37652 }
37653
37654@@ -1716,7 +1716,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37655 RBRQ_LEN_ERR(he_dev->rbrq_head)
37656 ? "LEN_ERR" : "",
37657 vcc->vpi, vcc->vci);
37658- atomic_inc(&vcc->stats->rx_err);
37659+ atomic_inc_unchecked(&vcc->stats->rx_err);
37660 goto return_host_buffers;
37661 }
37662
37663@@ -1768,7 +1768,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
37664 vcc->push(vcc, skb);
37665 spin_lock(&he_dev->global_lock);
37666
37667- atomic_inc(&vcc->stats->rx);
37668+ atomic_inc_unchecked(&vcc->stats->rx);
37669
37670 return_host_buffers:
37671 ++pdus_assembled;
37672@@ -2094,7 +2094,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
37673 tpd->vcc->pop(tpd->vcc, tpd->skb);
37674 else
37675 dev_kfree_skb_any(tpd->skb);
37676- atomic_inc(&tpd->vcc->stats->tx_err);
37677+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
37678 }
37679 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
37680 return;
37681@@ -2506,7 +2506,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37682 vcc->pop(vcc, skb);
37683 else
37684 dev_kfree_skb_any(skb);
37685- atomic_inc(&vcc->stats->tx_err);
37686+ atomic_inc_unchecked(&vcc->stats->tx_err);
37687 return -EINVAL;
37688 }
37689
37690@@ -2517,7 +2517,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37691 vcc->pop(vcc, skb);
37692 else
37693 dev_kfree_skb_any(skb);
37694- atomic_inc(&vcc->stats->tx_err);
37695+ atomic_inc_unchecked(&vcc->stats->tx_err);
37696 return -EINVAL;
37697 }
37698 #endif
37699@@ -2529,7 +2529,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37700 vcc->pop(vcc, skb);
37701 else
37702 dev_kfree_skb_any(skb);
37703- atomic_inc(&vcc->stats->tx_err);
37704+ atomic_inc_unchecked(&vcc->stats->tx_err);
37705 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37706 return -ENOMEM;
37707 }
37708@@ -2571,7 +2571,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37709 vcc->pop(vcc, skb);
37710 else
37711 dev_kfree_skb_any(skb);
37712- atomic_inc(&vcc->stats->tx_err);
37713+ atomic_inc_unchecked(&vcc->stats->tx_err);
37714 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37715 return -ENOMEM;
37716 }
37717@@ -2602,7 +2602,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
37718 __enqueue_tpd(he_dev, tpd, cid);
37719 spin_unlock_irqrestore(&he_dev->global_lock, flags);
37720
37721- atomic_inc(&vcc->stats->tx);
37722+ atomic_inc_unchecked(&vcc->stats->tx);
37723
37724 return 0;
37725 }
37726diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
37727index 1dc0519..1aadaf7 100644
37728--- a/drivers/atm/horizon.c
37729+++ b/drivers/atm/horizon.c
37730@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
37731 {
37732 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
37733 // VC layer stats
37734- atomic_inc(&vcc->stats->rx);
37735+ atomic_inc_unchecked(&vcc->stats->rx);
37736 __net_timestamp(skb);
37737 // end of our responsibility
37738 vcc->push (vcc, skb);
37739@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
37740 dev->tx_iovec = NULL;
37741
37742 // VC layer stats
37743- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
37744+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
37745
37746 // free the skb
37747 hrz_kfree_skb (skb);
37748diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
37749index 2b24ed0..b3d6acc 100644
37750--- a/drivers/atm/idt77252.c
37751+++ b/drivers/atm/idt77252.c
37752@@ -810,7 +810,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
37753 else
37754 dev_kfree_skb(skb);
37755
37756- atomic_inc(&vcc->stats->tx);
37757+ atomic_inc_unchecked(&vcc->stats->tx);
37758 }
37759
37760 atomic_dec(&scq->used);
37761@@ -1072,13 +1072,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37762 if ((sb = dev_alloc_skb(64)) == NULL) {
37763 printk("%s: Can't allocate buffers for aal0.\n",
37764 card->name);
37765- atomic_add(i, &vcc->stats->rx_drop);
37766+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
37767 break;
37768 }
37769 if (!atm_charge(vcc, sb->truesize)) {
37770 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
37771 card->name);
37772- atomic_add(i - 1, &vcc->stats->rx_drop);
37773+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
37774 dev_kfree_skb(sb);
37775 break;
37776 }
37777@@ -1095,7 +1095,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37778 ATM_SKB(sb)->vcc = vcc;
37779 __net_timestamp(sb);
37780 vcc->push(vcc, sb);
37781- atomic_inc(&vcc->stats->rx);
37782+ atomic_inc_unchecked(&vcc->stats->rx);
37783
37784 cell += ATM_CELL_PAYLOAD;
37785 }
37786@@ -1132,13 +1132,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37787 "(CDC: %08x)\n",
37788 card->name, len, rpp->len, readl(SAR_REG_CDC));
37789 recycle_rx_pool_skb(card, rpp);
37790- atomic_inc(&vcc->stats->rx_err);
37791+ atomic_inc_unchecked(&vcc->stats->rx_err);
37792 return;
37793 }
37794 if (stat & SAR_RSQE_CRC) {
37795 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
37796 recycle_rx_pool_skb(card, rpp);
37797- atomic_inc(&vcc->stats->rx_err);
37798+ atomic_inc_unchecked(&vcc->stats->rx_err);
37799 return;
37800 }
37801 if (skb_queue_len(&rpp->queue) > 1) {
37802@@ -1149,7 +1149,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37803 RXPRINTK("%s: Can't alloc RX skb.\n",
37804 card->name);
37805 recycle_rx_pool_skb(card, rpp);
37806- atomic_inc(&vcc->stats->rx_err);
37807+ atomic_inc_unchecked(&vcc->stats->rx_err);
37808 return;
37809 }
37810 if (!atm_charge(vcc, skb->truesize)) {
37811@@ -1168,7 +1168,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37812 __net_timestamp(skb);
37813
37814 vcc->push(vcc, skb);
37815- atomic_inc(&vcc->stats->rx);
37816+ atomic_inc_unchecked(&vcc->stats->rx);
37817
37818 return;
37819 }
37820@@ -1190,7 +1190,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
37821 __net_timestamp(skb);
37822
37823 vcc->push(vcc, skb);
37824- atomic_inc(&vcc->stats->rx);
37825+ atomic_inc_unchecked(&vcc->stats->rx);
37826
37827 if (skb->truesize > SAR_FB_SIZE_3)
37828 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
37829@@ -1301,14 +1301,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
37830 if (vcc->qos.aal != ATM_AAL0) {
37831 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
37832 card->name, vpi, vci);
37833- atomic_inc(&vcc->stats->rx_drop);
37834+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37835 goto drop;
37836 }
37837
37838 if ((sb = dev_alloc_skb(64)) == NULL) {
37839 printk("%s: Can't allocate buffers for AAL0.\n",
37840 card->name);
37841- atomic_inc(&vcc->stats->rx_err);
37842+ atomic_inc_unchecked(&vcc->stats->rx_err);
37843 goto drop;
37844 }
37845
37846@@ -1327,7 +1327,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
37847 ATM_SKB(sb)->vcc = vcc;
37848 __net_timestamp(sb);
37849 vcc->push(vcc, sb);
37850- atomic_inc(&vcc->stats->rx);
37851+ atomic_inc_unchecked(&vcc->stats->rx);
37852
37853 drop:
37854 skb_pull(queue, 64);
37855@@ -1952,13 +1952,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37856
37857 if (vc == NULL) {
37858 printk("%s: NULL connection in send().\n", card->name);
37859- atomic_inc(&vcc->stats->tx_err);
37860+ atomic_inc_unchecked(&vcc->stats->tx_err);
37861 dev_kfree_skb(skb);
37862 return -EINVAL;
37863 }
37864 if (!test_bit(VCF_TX, &vc->flags)) {
37865 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
37866- atomic_inc(&vcc->stats->tx_err);
37867+ atomic_inc_unchecked(&vcc->stats->tx_err);
37868 dev_kfree_skb(skb);
37869 return -EINVAL;
37870 }
37871@@ -1970,14 +1970,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37872 break;
37873 default:
37874 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
37875- atomic_inc(&vcc->stats->tx_err);
37876+ atomic_inc_unchecked(&vcc->stats->tx_err);
37877 dev_kfree_skb(skb);
37878 return -EINVAL;
37879 }
37880
37881 if (skb_shinfo(skb)->nr_frags != 0) {
37882 printk("%s: No scatter-gather yet.\n", card->name);
37883- atomic_inc(&vcc->stats->tx_err);
37884+ atomic_inc_unchecked(&vcc->stats->tx_err);
37885 dev_kfree_skb(skb);
37886 return -EINVAL;
37887 }
37888@@ -1985,7 +1985,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
37889
37890 err = queue_skb(card, vc, skb, oam);
37891 if (err) {
37892- atomic_inc(&vcc->stats->tx_err);
37893+ atomic_inc_unchecked(&vcc->stats->tx_err);
37894 dev_kfree_skb(skb);
37895 return err;
37896 }
37897@@ -2008,7 +2008,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
37898 skb = dev_alloc_skb(64);
37899 if (!skb) {
37900 printk("%s: Out of memory in send_oam().\n", card->name);
37901- atomic_inc(&vcc->stats->tx_err);
37902+ atomic_inc_unchecked(&vcc->stats->tx_err);
37903 return -ENOMEM;
37904 }
37905 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
37906diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
37907index 4217f29..88f547a 100644
37908--- a/drivers/atm/iphase.c
37909+++ b/drivers/atm/iphase.c
37910@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
37911 status = (u_short) (buf_desc_ptr->desc_mode);
37912 if (status & (RX_CER | RX_PTE | RX_OFL))
37913 {
37914- atomic_inc(&vcc->stats->rx_err);
37915+ atomic_inc_unchecked(&vcc->stats->rx_err);
37916 IF_ERR(printk("IA: bad packet, dropping it");)
37917 if (status & RX_CER) {
37918 IF_ERR(printk(" cause: packet CRC error\n");)
37919@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
37920 len = dma_addr - buf_addr;
37921 if (len > iadev->rx_buf_sz) {
37922 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
37923- atomic_inc(&vcc->stats->rx_err);
37924+ atomic_inc_unchecked(&vcc->stats->rx_err);
37925 goto out_free_desc;
37926 }
37927
37928@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37929 ia_vcc = INPH_IA_VCC(vcc);
37930 if (ia_vcc == NULL)
37931 {
37932- atomic_inc(&vcc->stats->rx_err);
37933+ atomic_inc_unchecked(&vcc->stats->rx_err);
37934 atm_return(vcc, skb->truesize);
37935 dev_kfree_skb_any(skb);
37936 goto INCR_DLE;
37937@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37938 if ((length > iadev->rx_buf_sz) || (length >
37939 (skb->len - sizeof(struct cpcs_trailer))))
37940 {
37941- atomic_inc(&vcc->stats->rx_err);
37942+ atomic_inc_unchecked(&vcc->stats->rx_err);
37943 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
37944 length, skb->len);)
37945 atm_return(vcc, skb->truesize);
37946@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
37947
37948 IF_RX(printk("rx_dle_intr: skb push");)
37949 vcc->push(vcc,skb);
37950- atomic_inc(&vcc->stats->rx);
37951+ atomic_inc_unchecked(&vcc->stats->rx);
37952 iadev->rx_pkt_cnt++;
37953 }
37954 INCR_DLE:
37955@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
37956 {
37957 struct k_sonet_stats *stats;
37958 stats = &PRIV(_ia_dev[board])->sonet_stats;
37959- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
37960- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
37961- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
37962- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
37963- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
37964- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
37965- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
37966- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
37967- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
37968+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
37969+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
37970+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
37971+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
37972+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
37973+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
37974+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
37975+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
37976+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
37977 }
37978 ia_cmds.status = 0;
37979 break;
37980@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37981 if ((desc == 0) || (desc > iadev->num_tx_desc))
37982 {
37983 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
37984- atomic_inc(&vcc->stats->tx);
37985+ atomic_inc_unchecked(&vcc->stats->tx);
37986 if (vcc->pop)
37987 vcc->pop(vcc, skb);
37988 else
37989@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
37990 ATM_DESC(skb) = vcc->vci;
37991 skb_queue_tail(&iadev->tx_dma_q, skb);
37992
37993- atomic_inc(&vcc->stats->tx);
37994+ atomic_inc_unchecked(&vcc->stats->tx);
37995 iadev->tx_pkt_cnt++;
37996 /* Increment transaction counter */
37997 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
37998
37999 #if 0
38000 /* add flow control logic */
38001- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
38002+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
38003 if (iavcc->vc_desc_cnt > 10) {
38004 vcc->tx_quota = vcc->tx_quota * 3 / 4;
38005 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
38006diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
38007index fa7d7019..1e404c7 100644
38008--- a/drivers/atm/lanai.c
38009+++ b/drivers/atm/lanai.c
38010@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
38011 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
38012 lanai_endtx(lanai, lvcc);
38013 lanai_free_skb(lvcc->tx.atmvcc, skb);
38014- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
38015+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
38016 }
38017
38018 /* Try to fill the buffer - don't call unless there is backlog */
38019@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
38020 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
38021 __net_timestamp(skb);
38022 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
38023- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
38024+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
38025 out:
38026 lvcc->rx.buf.ptr = end;
38027 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
38028@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38029 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
38030 "vcc %d\n", lanai->number, (unsigned int) s, vci);
38031 lanai->stats.service_rxnotaal5++;
38032- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38033+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38034 return 0;
38035 }
38036 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
38037@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38038 int bytes;
38039 read_unlock(&vcc_sklist_lock);
38040 DPRINTK("got trashed rx pdu on vci %d\n", vci);
38041- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38042+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38043 lvcc->stats.x.aal5.service_trash++;
38044 bytes = (SERVICE_GET_END(s) * 16) -
38045 (((unsigned long) lvcc->rx.buf.ptr) -
38046@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38047 }
38048 if (s & SERVICE_STREAM) {
38049 read_unlock(&vcc_sklist_lock);
38050- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38051+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38052 lvcc->stats.x.aal5.service_stream++;
38053 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
38054 "PDU on VCI %d!\n", lanai->number, vci);
38055@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
38056 return 0;
38057 }
38058 DPRINTK("got rx crc error on vci %d\n", vci);
38059- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
38060+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
38061 lvcc->stats.x.aal5.service_rxcrc++;
38062 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
38063 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
38064diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
38065index 9988ac9..7c52585 100644
38066--- a/drivers/atm/nicstar.c
38067+++ b/drivers/atm/nicstar.c
38068@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38069 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
38070 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
38071 card->index);
38072- atomic_inc(&vcc->stats->tx_err);
38073+ atomic_inc_unchecked(&vcc->stats->tx_err);
38074 dev_kfree_skb_any(skb);
38075 return -EINVAL;
38076 }
38077@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38078 if (!vc->tx) {
38079 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
38080 card->index);
38081- atomic_inc(&vcc->stats->tx_err);
38082+ atomic_inc_unchecked(&vcc->stats->tx_err);
38083 dev_kfree_skb_any(skb);
38084 return -EINVAL;
38085 }
38086@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38087 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
38088 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
38089 card->index);
38090- atomic_inc(&vcc->stats->tx_err);
38091+ atomic_inc_unchecked(&vcc->stats->tx_err);
38092 dev_kfree_skb_any(skb);
38093 return -EINVAL;
38094 }
38095
38096 if (skb_shinfo(skb)->nr_frags != 0) {
38097 printk("nicstar%d: No scatter-gather yet.\n", card->index);
38098- atomic_inc(&vcc->stats->tx_err);
38099+ atomic_inc_unchecked(&vcc->stats->tx_err);
38100 dev_kfree_skb_any(skb);
38101 return -EINVAL;
38102 }
38103@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
38104 }
38105
38106 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
38107- atomic_inc(&vcc->stats->tx_err);
38108+ atomic_inc_unchecked(&vcc->stats->tx_err);
38109 dev_kfree_skb_any(skb);
38110 return -EIO;
38111 }
38112- atomic_inc(&vcc->stats->tx);
38113+ atomic_inc_unchecked(&vcc->stats->tx);
38114
38115 return 0;
38116 }
38117@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38118 printk
38119 ("nicstar%d: Can't allocate buffers for aal0.\n",
38120 card->index);
38121- atomic_add(i, &vcc->stats->rx_drop);
38122+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
38123 break;
38124 }
38125 if (!atm_charge(vcc, sb->truesize)) {
38126 RXPRINTK
38127 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
38128 card->index);
38129- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
38130+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
38131 dev_kfree_skb_any(sb);
38132 break;
38133 }
38134@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38135 ATM_SKB(sb)->vcc = vcc;
38136 __net_timestamp(sb);
38137 vcc->push(vcc, sb);
38138- atomic_inc(&vcc->stats->rx);
38139+ atomic_inc_unchecked(&vcc->stats->rx);
38140 cell += ATM_CELL_PAYLOAD;
38141 }
38142
38143@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38144 if (iovb == NULL) {
38145 printk("nicstar%d: Out of iovec buffers.\n",
38146 card->index);
38147- atomic_inc(&vcc->stats->rx_drop);
38148+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38149 recycle_rx_buf(card, skb);
38150 return;
38151 }
38152@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38153 small or large buffer itself. */
38154 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
38155 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
38156- atomic_inc(&vcc->stats->rx_err);
38157+ atomic_inc_unchecked(&vcc->stats->rx_err);
38158 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38159 NS_MAX_IOVECS);
38160 NS_PRV_IOVCNT(iovb) = 0;
38161@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38162 ("nicstar%d: Expected a small buffer, and this is not one.\n",
38163 card->index);
38164 which_list(card, skb);
38165- atomic_inc(&vcc->stats->rx_err);
38166+ atomic_inc_unchecked(&vcc->stats->rx_err);
38167 recycle_rx_buf(card, skb);
38168 vc->rx_iov = NULL;
38169 recycle_iov_buf(card, iovb);
38170@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38171 ("nicstar%d: Expected a large buffer, and this is not one.\n",
38172 card->index);
38173 which_list(card, skb);
38174- atomic_inc(&vcc->stats->rx_err);
38175+ atomic_inc_unchecked(&vcc->stats->rx_err);
38176 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38177 NS_PRV_IOVCNT(iovb));
38178 vc->rx_iov = NULL;
38179@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38180 printk(" - PDU size mismatch.\n");
38181 else
38182 printk(".\n");
38183- atomic_inc(&vcc->stats->rx_err);
38184+ atomic_inc_unchecked(&vcc->stats->rx_err);
38185 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
38186 NS_PRV_IOVCNT(iovb));
38187 vc->rx_iov = NULL;
38188@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38189 /* skb points to a small buffer */
38190 if (!atm_charge(vcc, skb->truesize)) {
38191 push_rxbufs(card, skb);
38192- atomic_inc(&vcc->stats->rx_drop);
38193+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38194 } else {
38195 skb_put(skb, len);
38196 dequeue_sm_buf(card, skb);
38197@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38198 ATM_SKB(skb)->vcc = vcc;
38199 __net_timestamp(skb);
38200 vcc->push(vcc, skb);
38201- atomic_inc(&vcc->stats->rx);
38202+ atomic_inc_unchecked(&vcc->stats->rx);
38203 }
38204 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
38205 struct sk_buff *sb;
38206@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38207 if (len <= NS_SMBUFSIZE) {
38208 if (!atm_charge(vcc, sb->truesize)) {
38209 push_rxbufs(card, sb);
38210- atomic_inc(&vcc->stats->rx_drop);
38211+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38212 } else {
38213 skb_put(sb, len);
38214 dequeue_sm_buf(card, sb);
38215@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38216 ATM_SKB(sb)->vcc = vcc;
38217 __net_timestamp(sb);
38218 vcc->push(vcc, sb);
38219- atomic_inc(&vcc->stats->rx);
38220+ atomic_inc_unchecked(&vcc->stats->rx);
38221 }
38222
38223 push_rxbufs(card, skb);
38224@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38225
38226 if (!atm_charge(vcc, skb->truesize)) {
38227 push_rxbufs(card, skb);
38228- atomic_inc(&vcc->stats->rx_drop);
38229+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38230 } else {
38231 dequeue_lg_buf(card, skb);
38232 #ifdef NS_USE_DESTRUCTORS
38233@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38234 ATM_SKB(skb)->vcc = vcc;
38235 __net_timestamp(skb);
38236 vcc->push(vcc, skb);
38237- atomic_inc(&vcc->stats->rx);
38238+ atomic_inc_unchecked(&vcc->stats->rx);
38239 }
38240
38241 push_rxbufs(card, sb);
38242@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38243 printk
38244 ("nicstar%d: Out of huge buffers.\n",
38245 card->index);
38246- atomic_inc(&vcc->stats->rx_drop);
38247+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38248 recycle_iovec_rx_bufs(card,
38249 (struct iovec *)
38250 iovb->data,
38251@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38252 card->hbpool.count++;
38253 } else
38254 dev_kfree_skb_any(hb);
38255- atomic_inc(&vcc->stats->rx_drop);
38256+ atomic_inc_unchecked(&vcc->stats->rx_drop);
38257 } else {
38258 /* Copy the small buffer to the huge buffer */
38259 sb = (struct sk_buff *)iov->iov_base;
38260@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
38261 #endif /* NS_USE_DESTRUCTORS */
38262 __net_timestamp(hb);
38263 vcc->push(vcc, hb);
38264- atomic_inc(&vcc->stats->rx);
38265+ atomic_inc_unchecked(&vcc->stats->rx);
38266 }
38267 }
38268
38269diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
38270index 7652e8d..db45069 100644
38271--- a/drivers/atm/solos-pci.c
38272+++ b/drivers/atm/solos-pci.c
38273@@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
38274 }
38275 atm_charge(vcc, skb->truesize);
38276 vcc->push(vcc, skb);
38277- atomic_inc(&vcc->stats->rx);
38278+ atomic_inc_unchecked(&vcc->stats->rx);
38279 break;
38280
38281 case PKT_STATUS:
38282@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
38283 vcc = SKB_CB(oldskb)->vcc;
38284
38285 if (vcc) {
38286- atomic_inc(&vcc->stats->tx);
38287+ atomic_inc_unchecked(&vcc->stats->tx);
38288 solos_pop(vcc, oldskb);
38289 } else {
38290 dev_kfree_skb_irq(oldskb);
38291diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
38292index 0215934..ce9f5b1 100644
38293--- a/drivers/atm/suni.c
38294+++ b/drivers/atm/suni.c
38295@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
38296
38297
38298 #define ADD_LIMITED(s,v) \
38299- atomic_add((v),&stats->s); \
38300- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
38301+ atomic_add_unchecked((v),&stats->s); \
38302+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
38303
38304
38305 static void suni_hz(unsigned long from_timer)
38306diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
38307index 5120a96..e2572bd 100644
38308--- a/drivers/atm/uPD98402.c
38309+++ b/drivers/atm/uPD98402.c
38310@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
38311 struct sonet_stats tmp;
38312 int error = 0;
38313
38314- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
38315+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
38316 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
38317 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
38318 if (zero && !error) {
38319@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
38320
38321
38322 #define ADD_LIMITED(s,v) \
38323- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
38324- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
38325- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
38326+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
38327+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
38328+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
38329
38330
38331 static void stat_event(struct atm_dev *dev)
38332@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
38333 if (reason & uPD98402_INT_PFM) stat_event(dev);
38334 if (reason & uPD98402_INT_PCO) {
38335 (void) GET(PCOCR); /* clear interrupt cause */
38336- atomic_add(GET(HECCT),
38337+ atomic_add_unchecked(GET(HECCT),
38338 &PRIV(dev)->sonet_stats.uncorr_hcs);
38339 }
38340 if ((reason & uPD98402_INT_RFO) &&
38341@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
38342 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
38343 uPD98402_INT_LOS),PIMR); /* enable them */
38344 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
38345- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
38346- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
38347- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
38348+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
38349+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
38350+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
38351 return 0;
38352 }
38353
38354diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
38355index 969c3c2..9b72956 100644
38356--- a/drivers/atm/zatm.c
38357+++ b/drivers/atm/zatm.c
38358@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
38359 }
38360 if (!size) {
38361 dev_kfree_skb_irq(skb);
38362- if (vcc) atomic_inc(&vcc->stats->rx_err);
38363+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
38364 continue;
38365 }
38366 if (!atm_charge(vcc,skb->truesize)) {
38367@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
38368 skb->len = size;
38369 ATM_SKB(skb)->vcc = vcc;
38370 vcc->push(vcc,skb);
38371- atomic_inc(&vcc->stats->rx);
38372+ atomic_inc_unchecked(&vcc->stats->rx);
38373 }
38374 zout(pos & 0xffff,MTA(mbx));
38375 #if 0 /* probably a stupid idea */
38376@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
38377 skb_queue_head(&zatm_vcc->backlog,skb);
38378 break;
38379 }
38380- atomic_inc(&vcc->stats->tx);
38381+ atomic_inc_unchecked(&vcc->stats->tx);
38382 wake_up(&zatm_vcc->tx_wait);
38383 }
38384
38385diff --git a/drivers/base/bus.c b/drivers/base/bus.c
38386index 83e910a..b224a73 100644
38387--- a/drivers/base/bus.c
38388+++ b/drivers/base/bus.c
38389@@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
38390 return -EINVAL;
38391
38392 mutex_lock(&subsys->p->mutex);
38393- list_add_tail(&sif->node, &subsys->p->interfaces);
38394+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
38395 if (sif->add_dev) {
38396 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
38397 while ((dev = subsys_dev_iter_next(&iter)))
38398@@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
38399 subsys = sif->subsys;
38400
38401 mutex_lock(&subsys->p->mutex);
38402- list_del_init(&sif->node);
38403+ pax_list_del_init((struct list_head *)&sif->node);
38404 if (sif->remove_dev) {
38405 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
38406 while ((dev = subsys_dev_iter_next(&iter)))
38407diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
38408index 25798db..15f130e 100644
38409--- a/drivers/base/devtmpfs.c
38410+++ b/drivers/base/devtmpfs.c
38411@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
38412 if (!thread)
38413 return 0;
38414
38415- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
38416+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
38417 if (err)
38418 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
38419 else
38420@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
38421 *err = sys_unshare(CLONE_NEWNS);
38422 if (*err)
38423 goto out;
38424- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
38425+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
38426 if (*err)
38427 goto out;
38428- sys_chdir("/.."); /* will traverse into overmounted root */
38429- sys_chroot(".");
38430+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
38431+ sys_chroot((char __force_user *)".");
38432 complete(&setup_done);
38433 while (1) {
38434 spin_lock(&req_lock);
38435diff --git a/drivers/base/node.c b/drivers/base/node.c
38436index d51c49c..28908df 100644
38437--- a/drivers/base/node.c
38438+++ b/drivers/base/node.c
38439@@ -623,7 +623,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
38440 struct node_attr {
38441 struct device_attribute attr;
38442 enum node_states state;
38443-};
38444+} __do_const;
38445
38446 static ssize_t show_node_state(struct device *dev,
38447 struct device_attribute *attr, char *buf)
38448diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
38449index eee55c1..b8c9393 100644
38450--- a/drivers/base/power/domain.c
38451+++ b/drivers/base/power/domain.c
38452@@ -1821,9 +1821,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
38453
38454 if (dev->power.subsys_data->domain_data) {
38455 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
38456- gpd_data->ops = (struct gpd_dev_ops){ NULL };
38457+ memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
38458 if (clear_td)
38459- gpd_data->td = (struct gpd_timing_data){ 0 };
38460+ memset(&gpd_data->td, 0, sizeof(gpd_data->td));
38461
38462 if (--gpd_data->refcount == 0) {
38463 dev->power.subsys_data->domain_data = NULL;
38464@@ -1862,7 +1862,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
38465 {
38466 struct cpuidle_driver *cpuidle_drv;
38467 struct gpd_cpu_data *cpu_data;
38468- struct cpuidle_state *idle_state;
38469+ cpuidle_state_no_const *idle_state;
38470 int ret = 0;
38471
38472 if (IS_ERR_OR_NULL(genpd) || state < 0)
38473@@ -1930,7 +1930,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
38474 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
38475 {
38476 struct gpd_cpu_data *cpu_data;
38477- struct cpuidle_state *idle_state;
38478+ cpuidle_state_no_const *idle_state;
38479 int ret = 0;
38480
38481 if (IS_ERR_OR_NULL(genpd))
38482diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
38483index 95b181d1..c4f0e19 100644
38484--- a/drivers/base/power/sysfs.c
38485+++ b/drivers/base/power/sysfs.c
38486@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
38487 return -EIO;
38488 }
38489 }
38490- return sprintf(buf, p);
38491+ return sprintf(buf, "%s", p);
38492 }
38493
38494 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
38495diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
38496index eb1bd2e..2667d3a 100644
38497--- a/drivers/base/power/wakeup.c
38498+++ b/drivers/base/power/wakeup.c
38499@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
38500 * They need to be modified together atomically, so it's better to use one
38501 * atomic variable to hold them both.
38502 */
38503-static atomic_t combined_event_count = ATOMIC_INIT(0);
38504+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
38505
38506 #define IN_PROGRESS_BITS (sizeof(int) * 4)
38507 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
38508
38509 static void split_counters(unsigned int *cnt, unsigned int *inpr)
38510 {
38511- unsigned int comb = atomic_read(&combined_event_count);
38512+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
38513
38514 *cnt = (comb >> IN_PROGRESS_BITS);
38515 *inpr = comb & MAX_IN_PROGRESS;
38516@@ -401,7 +401,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
38517 ws->start_prevent_time = ws->last_time;
38518
38519 /* Increment the counter of events in progress. */
38520- cec = atomic_inc_return(&combined_event_count);
38521+ cec = atomic_inc_return_unchecked(&combined_event_count);
38522
38523 trace_wakeup_source_activate(ws->name, cec);
38524 }
38525@@ -527,7 +527,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
38526 * Increment the counter of registered wakeup events and decrement the
38527 * couter of wakeup events in progress simultaneously.
38528 */
38529- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
38530+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
38531 trace_wakeup_source_deactivate(ws->name, cec);
38532
38533 split_counters(&cnt, &inpr);
38534diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
38535index dbb8350..4762f4c 100644
38536--- a/drivers/base/syscore.c
38537+++ b/drivers/base/syscore.c
38538@@ -22,7 +22,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
38539 void register_syscore_ops(struct syscore_ops *ops)
38540 {
38541 mutex_lock(&syscore_ops_lock);
38542- list_add_tail(&ops->node, &syscore_ops_list);
38543+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
38544 mutex_unlock(&syscore_ops_lock);
38545 }
38546 EXPORT_SYMBOL_GPL(register_syscore_ops);
38547@@ -34,7 +34,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
38548 void unregister_syscore_ops(struct syscore_ops *ops)
38549 {
38550 mutex_lock(&syscore_ops_lock);
38551- list_del(&ops->node);
38552+ pax_list_del((struct list_head *)&ops->node);
38553 mutex_unlock(&syscore_ops_lock);
38554 }
38555 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
38556diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
38557index ff20f19..018f1da 100644
38558--- a/drivers/block/cciss.c
38559+++ b/drivers/block/cciss.c
38560@@ -3008,7 +3008,7 @@ static void start_io(ctlr_info_t *h)
38561 while (!list_empty(&h->reqQ)) {
38562 c = list_entry(h->reqQ.next, CommandList_struct, list);
38563 /* can't do anything if fifo is full */
38564- if ((h->access.fifo_full(h))) {
38565+ if ((h->access->fifo_full(h))) {
38566 dev_warn(&h->pdev->dev, "fifo full\n");
38567 break;
38568 }
38569@@ -3018,7 +3018,7 @@ static void start_io(ctlr_info_t *h)
38570 h->Qdepth--;
38571
38572 /* Tell the controller execute command */
38573- h->access.submit_command(h, c);
38574+ h->access->submit_command(h, c);
38575
38576 /* Put job onto the completed Q */
38577 addQ(&h->cmpQ, c);
38578@@ -3444,17 +3444,17 @@ startio:
38579
38580 static inline unsigned long get_next_completion(ctlr_info_t *h)
38581 {
38582- return h->access.command_completed(h);
38583+ return h->access->command_completed(h);
38584 }
38585
38586 static inline int interrupt_pending(ctlr_info_t *h)
38587 {
38588- return h->access.intr_pending(h);
38589+ return h->access->intr_pending(h);
38590 }
38591
38592 static inline long interrupt_not_for_us(ctlr_info_t *h)
38593 {
38594- return ((h->access.intr_pending(h) == 0) ||
38595+ return ((h->access->intr_pending(h) == 0) ||
38596 (h->interrupts_enabled == 0));
38597 }
38598
38599@@ -3487,7 +3487,7 @@ static inline u32 next_command(ctlr_info_t *h)
38600 u32 a;
38601
38602 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
38603- return h->access.command_completed(h);
38604+ return h->access->command_completed(h);
38605
38606 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
38607 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
38608@@ -4044,7 +4044,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
38609 trans_support & CFGTBL_Trans_use_short_tags);
38610
38611 /* Change the access methods to the performant access methods */
38612- h->access = SA5_performant_access;
38613+ h->access = &SA5_performant_access;
38614 h->transMethod = CFGTBL_Trans_Performant;
38615
38616 return;
38617@@ -4318,7 +4318,7 @@ static int cciss_pci_init(ctlr_info_t *h)
38618 if (prod_index < 0)
38619 return -ENODEV;
38620 h->product_name = products[prod_index].product_name;
38621- h->access = *(products[prod_index].access);
38622+ h->access = products[prod_index].access;
38623
38624 if (cciss_board_disabled(h)) {
38625 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
38626@@ -5050,7 +5050,7 @@ reinit_after_soft_reset:
38627 }
38628
38629 /* make sure the board interrupts are off */
38630- h->access.set_intr_mask(h, CCISS_INTR_OFF);
38631+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
38632 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
38633 if (rc)
38634 goto clean2;
38635@@ -5100,7 +5100,7 @@ reinit_after_soft_reset:
38636 * fake ones to scoop up any residual completions.
38637 */
38638 spin_lock_irqsave(&h->lock, flags);
38639- h->access.set_intr_mask(h, CCISS_INTR_OFF);
38640+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
38641 spin_unlock_irqrestore(&h->lock, flags);
38642 free_irq(h->intr[h->intr_mode], h);
38643 rc = cciss_request_irq(h, cciss_msix_discard_completions,
38644@@ -5120,9 +5120,9 @@ reinit_after_soft_reset:
38645 dev_info(&h->pdev->dev, "Board READY.\n");
38646 dev_info(&h->pdev->dev,
38647 "Waiting for stale completions to drain.\n");
38648- h->access.set_intr_mask(h, CCISS_INTR_ON);
38649+ h->access->set_intr_mask(h, CCISS_INTR_ON);
38650 msleep(10000);
38651- h->access.set_intr_mask(h, CCISS_INTR_OFF);
38652+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
38653
38654 rc = controller_reset_failed(h->cfgtable);
38655 if (rc)
38656@@ -5145,7 +5145,7 @@ reinit_after_soft_reset:
38657 cciss_scsi_setup(h);
38658
38659 /* Turn the interrupts on so we can service requests */
38660- h->access.set_intr_mask(h, CCISS_INTR_ON);
38661+ h->access->set_intr_mask(h, CCISS_INTR_ON);
38662
38663 /* Get the firmware version */
38664 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
38665@@ -5217,7 +5217,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
38666 kfree(flush_buf);
38667 if (return_code != IO_OK)
38668 dev_warn(&h->pdev->dev, "Error flushing cache\n");
38669- h->access.set_intr_mask(h, CCISS_INTR_OFF);
38670+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
38671 free_irq(h->intr[h->intr_mode], h);
38672 }
38673
38674diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
38675index 7fda30e..2f27946 100644
38676--- a/drivers/block/cciss.h
38677+++ b/drivers/block/cciss.h
38678@@ -101,7 +101,7 @@ struct ctlr_info
38679 /* information about each logical volume */
38680 drive_info_struct *drv[CISS_MAX_LUN];
38681
38682- struct access_method access;
38683+ struct access_method *access;
38684
38685 /* queue and queue Info */
38686 struct list_head reqQ;
38687@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
38688 }
38689
38690 static struct access_method SA5_access = {
38691- SA5_submit_command,
38692- SA5_intr_mask,
38693- SA5_fifo_full,
38694- SA5_intr_pending,
38695- SA5_completed,
38696+ .submit_command = SA5_submit_command,
38697+ .set_intr_mask = SA5_intr_mask,
38698+ .fifo_full = SA5_fifo_full,
38699+ .intr_pending = SA5_intr_pending,
38700+ .command_completed = SA5_completed,
38701 };
38702
38703 static struct access_method SA5B_access = {
38704- SA5_submit_command,
38705- SA5B_intr_mask,
38706- SA5_fifo_full,
38707- SA5B_intr_pending,
38708- SA5_completed,
38709+ .submit_command = SA5_submit_command,
38710+ .set_intr_mask = SA5B_intr_mask,
38711+ .fifo_full = SA5_fifo_full,
38712+ .intr_pending = SA5B_intr_pending,
38713+ .command_completed = SA5_completed,
38714 };
38715
38716 static struct access_method SA5_performant_access = {
38717- SA5_submit_command,
38718- SA5_performant_intr_mask,
38719- SA5_fifo_full,
38720- SA5_performant_intr_pending,
38721- SA5_performant_completed,
38722+ .submit_command = SA5_submit_command,
38723+ .set_intr_mask = SA5_performant_intr_mask,
38724+ .fifo_full = SA5_fifo_full,
38725+ .intr_pending = SA5_performant_intr_pending,
38726+ .command_completed = SA5_performant_completed,
38727 };
38728
38729 struct board_type {
38730diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
38731index 2b94403..fd6ad1f 100644
38732--- a/drivers/block/cpqarray.c
38733+++ b/drivers/block/cpqarray.c
38734@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38735 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
38736 goto Enomem4;
38737 }
38738- hba[i]->access.set_intr_mask(hba[i], 0);
38739+ hba[i]->access->set_intr_mask(hba[i], 0);
38740 if (request_irq(hba[i]->intr, do_ida_intr,
38741 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
38742 {
38743@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
38744 add_timer(&hba[i]->timer);
38745
38746 /* Enable IRQ now that spinlock and rate limit timer are set up */
38747- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38748+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
38749
38750 for(j=0; j<NWD; j++) {
38751 struct gendisk *disk = ida_gendisk[i][j];
38752@@ -694,7 +694,7 @@ DBGINFO(
38753 for(i=0; i<NR_PRODUCTS; i++) {
38754 if (board_id == products[i].board_id) {
38755 c->product_name = products[i].product_name;
38756- c->access = *(products[i].access);
38757+ c->access = products[i].access;
38758 break;
38759 }
38760 }
38761@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
38762 hba[ctlr]->intr = intr;
38763 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
38764 hba[ctlr]->product_name = products[j].product_name;
38765- hba[ctlr]->access = *(products[j].access);
38766+ hba[ctlr]->access = products[j].access;
38767 hba[ctlr]->ctlr = ctlr;
38768 hba[ctlr]->board_id = board_id;
38769 hba[ctlr]->pci_dev = NULL; /* not PCI */
38770@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
38771
38772 while((c = h->reqQ) != NULL) {
38773 /* Can't do anything if we're busy */
38774- if (h->access.fifo_full(h) == 0)
38775+ if (h->access->fifo_full(h) == 0)
38776 return;
38777
38778 /* Get the first entry from the request Q */
38779@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
38780 h->Qdepth--;
38781
38782 /* Tell the controller to do our bidding */
38783- h->access.submit_command(h, c);
38784+ h->access->submit_command(h, c);
38785
38786 /* Get onto the completion Q */
38787 addQ(&h->cmpQ, c);
38788@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38789 unsigned long flags;
38790 __u32 a,a1;
38791
38792- istat = h->access.intr_pending(h);
38793+ istat = h->access->intr_pending(h);
38794 /* Is this interrupt for us? */
38795 if (istat == 0)
38796 return IRQ_NONE;
38797@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
38798 */
38799 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
38800 if (istat & FIFO_NOT_EMPTY) {
38801- while((a = h->access.command_completed(h))) {
38802+ while((a = h->access->command_completed(h))) {
38803 a1 = a; a &= ~3;
38804 if ((c = h->cmpQ) == NULL)
38805 {
38806@@ -1448,11 +1448,11 @@ static int sendcmd(
38807 /*
38808 * Disable interrupt
38809 */
38810- info_p->access.set_intr_mask(info_p, 0);
38811+ info_p->access->set_intr_mask(info_p, 0);
38812 /* Make sure there is room in the command FIFO */
38813 /* Actually it should be completely empty at this time. */
38814 for (i = 200000; i > 0; i--) {
38815- temp = info_p->access.fifo_full(info_p);
38816+ temp = info_p->access->fifo_full(info_p);
38817 if (temp != 0) {
38818 break;
38819 }
38820@@ -1465,7 +1465,7 @@ DBG(
38821 /*
38822 * Send the cmd
38823 */
38824- info_p->access.submit_command(info_p, c);
38825+ info_p->access->submit_command(info_p, c);
38826 complete = pollcomplete(ctlr);
38827
38828 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
38829@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
38830 * we check the new geometry. Then turn interrupts back on when
38831 * we're done.
38832 */
38833- host->access.set_intr_mask(host, 0);
38834+ host->access->set_intr_mask(host, 0);
38835 getgeometry(ctlr);
38836- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
38837+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
38838
38839 for(i=0; i<NWD; i++) {
38840 struct gendisk *disk = ida_gendisk[ctlr][i];
38841@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
38842 /* Wait (up to 2 seconds) for a command to complete */
38843
38844 for (i = 200000; i > 0; i--) {
38845- done = hba[ctlr]->access.command_completed(hba[ctlr]);
38846+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
38847 if (done == 0) {
38848 udelay(10); /* a short fixed delay */
38849 } else
38850diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
38851index be73e9d..7fbf140 100644
38852--- a/drivers/block/cpqarray.h
38853+++ b/drivers/block/cpqarray.h
38854@@ -99,7 +99,7 @@ struct ctlr_info {
38855 drv_info_t drv[NWD];
38856 struct proc_dir_entry *proc;
38857
38858- struct access_method access;
38859+ struct access_method *access;
38860
38861 cmdlist_t *reqQ;
38862 cmdlist_t *cmpQ;
38863diff --git a/drivers/block/drbd/drbd_bitmap.c b/drivers/block/drbd/drbd_bitmap.c
38864index 426c97a..8c58607 100644
38865--- a/drivers/block/drbd/drbd_bitmap.c
38866+++ b/drivers/block/drbd/drbd_bitmap.c
38867@@ -1036,7 +1036,7 @@ static void bm_page_io_async(struct drbd_bm_aio_ctx *ctx, int page_nr) __must_ho
38868 submit_bio(rw, bio);
38869 /* this should not count as user activity and cause the
38870 * resync to throttle -- see drbd_rs_should_slow_down(). */
38871- atomic_add(len >> 9, &device->rs_sect_ev);
38872+ atomic_add_unchecked(len >> 9, &device->rs_sect_ev);
38873 }
38874 }
38875
38876diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
38877index 1a00001..c0d4253 100644
38878--- a/drivers/block/drbd/drbd_int.h
38879+++ b/drivers/block/drbd/drbd_int.h
38880@@ -387,7 +387,7 @@ struct drbd_epoch {
38881 struct drbd_connection *connection;
38882 struct list_head list;
38883 unsigned int barrier_nr;
38884- atomic_t epoch_size; /* increased on every request added. */
38885+ atomic_unchecked_t epoch_size; /* increased on every request added. */
38886 atomic_t active; /* increased on every req. added, and dec on every finished. */
38887 unsigned long flags;
38888 };
38889@@ -948,7 +948,7 @@ struct drbd_device {
38890 unsigned int al_tr_number;
38891 int al_tr_cycle;
38892 wait_queue_head_t seq_wait;
38893- atomic_t packet_seq;
38894+ atomic_unchecked_t packet_seq;
38895 unsigned int peer_seq;
38896 spinlock_t peer_seq_lock;
38897 unsigned long comm_bm_set; /* communicated number of set bits. */
38898@@ -957,8 +957,8 @@ struct drbd_device {
38899 struct mutex own_state_mutex;
38900 struct mutex *state_mutex; /* either own_state_mutex or first_peer_device(device)->connection->cstate_mutex */
38901 char congestion_reason; /* Why we where congested... */
38902- atomic_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38903- atomic_t rs_sect_ev; /* for submitted resync data rate, both */
38904+ atomic_unchecked_t rs_sect_in; /* for incoming resync data rate, SyncTarget */
38905+ atomic_unchecked_t rs_sect_ev; /* for submitted resync data rate, both */
38906 int rs_last_sect_ev; /* counter to compare with */
38907 int rs_last_events; /* counter of read or write "events" (unit sectors)
38908 * on the lower level device when we last looked. */
38909@@ -1569,7 +1569,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
38910 char __user *uoptval;
38911 int err;
38912
38913- uoptval = (char __user __force *)optval;
38914+ uoptval = (char __force_user *)optval;
38915
38916 set_fs(KERNEL_DS);
38917 if (level == SOL_SOCKET)
38918diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
38919index 04a14e0..5b8f0aa 100644
38920--- a/drivers/block/drbd/drbd_interval.c
38921+++ b/drivers/block/drbd/drbd_interval.c
38922@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
38923 }
38924
38925 static const struct rb_augment_callbacks augment_callbacks = {
38926- augment_propagate,
38927- augment_copy,
38928- augment_rotate,
38929+ .propagate = augment_propagate,
38930+ .copy = augment_copy,
38931+ .rotate = augment_rotate,
38932 };
38933
38934 /**
38935diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
38936index 9b465bb..00034ecf 100644
38937--- a/drivers/block/drbd/drbd_main.c
38938+++ b/drivers/block/drbd/drbd_main.c
38939@@ -1328,7 +1328,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
38940 p->sector = sector;
38941 p->block_id = block_id;
38942 p->blksize = blksize;
38943- p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
38944+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
38945 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
38946 }
38947
38948@@ -1634,7 +1634,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
38949 return -EIO;
38950 p->sector = cpu_to_be64(req->i.sector);
38951 p->block_id = (unsigned long)req;
38952- p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
38953+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
38954 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
38955 if (device->state.conn >= C_SYNC_SOURCE &&
38956 device->state.conn <= C_PAUSED_SYNC_T)
38957@@ -1915,8 +1915,8 @@ void drbd_init_set_defaults(struct drbd_device *device)
38958 atomic_set(&device->unacked_cnt, 0);
38959 atomic_set(&device->local_cnt, 0);
38960 atomic_set(&device->pp_in_use_by_net, 0);
38961- atomic_set(&device->rs_sect_in, 0);
38962- atomic_set(&device->rs_sect_ev, 0);
38963+ atomic_set_unchecked(&device->rs_sect_in, 0);
38964+ atomic_set_unchecked(&device->rs_sect_ev, 0);
38965 atomic_set(&device->ap_in_flight, 0);
38966 atomic_set(&device->md_io.in_use, 0);
38967
38968@@ -2688,8 +2688,8 @@ void drbd_destroy_connection(struct kref *kref)
38969 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
38970 struct drbd_resource *resource = connection->resource;
38971
38972- if (atomic_read(&connection->current_epoch->epoch_size) != 0)
38973- drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
38974+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
38975+ drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
38976 kfree(connection->current_epoch);
38977
38978 idr_destroy(&connection->peer_devices);
38979diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
38980index 1cd47df..57c53c0 100644
38981--- a/drivers/block/drbd/drbd_nl.c
38982+++ b/drivers/block/drbd/drbd_nl.c
38983@@ -3645,13 +3645,13 @@ finish:
38984
38985 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
38986 {
38987- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38988+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
38989 struct sk_buff *msg;
38990 struct drbd_genlmsghdr *d_out;
38991 unsigned seq;
38992 int err = -ENOMEM;
38993
38994- seq = atomic_inc_return(&drbd_genl_seq);
38995+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
38996 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
38997 if (!msg)
38998 goto failed;
38999diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
39000index 9342b8d..b6a6825 100644
39001--- a/drivers/block/drbd/drbd_receiver.c
39002+++ b/drivers/block/drbd/drbd_receiver.c
39003@@ -870,7 +870,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
39004 struct drbd_device *device = peer_device->device;
39005 int err;
39006
39007- atomic_set(&device->packet_seq, 0);
39008+ atomic_set_unchecked(&device->packet_seq, 0);
39009 device->peer_seq = 0;
39010
39011 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
39012@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39013 do {
39014 next_epoch = NULL;
39015
39016- epoch_size = atomic_read(&epoch->epoch_size);
39017+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
39018
39019 switch (ev & ~EV_CLEANUP) {
39020 case EV_PUT:
39021@@ -1273,7 +1273,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
39022 rv = FE_DESTROYED;
39023 } else {
39024 epoch->flags = 0;
39025- atomic_set(&epoch->epoch_size, 0);
39026+ atomic_set_unchecked(&epoch->epoch_size, 0);
39027 /* atomic_set(&epoch->active, 0); is already zero */
39028 if (rv == FE_STILL_LIVE)
39029 rv = FE_RECYCLED;
39030@@ -1550,7 +1550,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39031 conn_wait_active_ee_empty(connection);
39032 drbd_flush(connection);
39033
39034- if (atomic_read(&connection->current_epoch->epoch_size)) {
39035+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39036 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
39037 if (epoch)
39038 break;
39039@@ -1564,11 +1564,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
39040 }
39041
39042 epoch->flags = 0;
39043- atomic_set(&epoch->epoch_size, 0);
39044+ atomic_set_unchecked(&epoch->epoch_size, 0);
39045 atomic_set(&epoch->active, 0);
39046
39047 spin_lock(&connection->epoch_lock);
39048- if (atomic_read(&connection->current_epoch->epoch_size)) {
39049+ if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
39050 list_add(&epoch->list, &connection->current_epoch->list);
39051 connection->current_epoch = epoch;
39052 connection->epochs++;
39053@@ -1802,7 +1802,7 @@ static int recv_resync_read(struct drbd_peer_device *peer_device, sector_t secto
39054 list_add_tail(&peer_req->w.list, &device->sync_ee);
39055 spin_unlock_irq(&device->resource->req_lock);
39056
39057- atomic_add(pi->size >> 9, &device->rs_sect_ev);
39058+ atomic_add_unchecked(pi->size >> 9, &device->rs_sect_ev);
39059 if (drbd_submit_peer_request(device, peer_req, WRITE, DRBD_FAULT_RS_WR) == 0)
39060 return 0;
39061
39062@@ -1900,7 +1900,7 @@ static int receive_RSDataReply(struct drbd_connection *connection, struct packet
39063 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
39064 }
39065
39066- atomic_add(pi->size >> 9, &device->rs_sect_in);
39067+ atomic_add_unchecked(pi->size >> 9, &device->rs_sect_in);
39068
39069 return err;
39070 }
39071@@ -2290,7 +2290,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39072
39073 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
39074 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
39075- atomic_inc(&connection->current_epoch->epoch_size);
39076+ atomic_inc_unchecked(&connection->current_epoch->epoch_size);
39077 err2 = drbd_drain_block(peer_device, pi->size);
39078 if (!err)
39079 err = err2;
39080@@ -2334,7 +2334,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
39081
39082 spin_lock(&connection->epoch_lock);
39083 peer_req->epoch = connection->current_epoch;
39084- atomic_inc(&peer_req->epoch->epoch_size);
39085+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
39086 atomic_inc(&peer_req->epoch->active);
39087 spin_unlock(&connection->epoch_lock);
39088
39089@@ -2479,7 +2479,7 @@ bool drbd_rs_c_min_rate_throttle(struct drbd_device *device)
39090
39091 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
39092 (int)part_stat_read(&disk->part0, sectors[1]) -
39093- atomic_read(&device->rs_sect_ev);
39094+ atomic_read_unchecked(&device->rs_sect_ev);
39095
39096 if (atomic_read(&device->ap_actlog_cnt)
39097 || !device->rs_last_events || curr_events - device->rs_last_events > 64) {
39098@@ -2618,7 +2618,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
39099 device->use_csums = true;
39100 } else if (pi->cmd == P_OV_REPLY) {
39101 /* track progress, we may need to throttle */
39102- atomic_add(size >> 9, &device->rs_sect_in);
39103+ atomic_add_unchecked(size >> 9, &device->rs_sect_in);
39104 peer_req->w.cb = w_e_end_ov_reply;
39105 dec_rs_pending(device);
39106 /* drbd_rs_begin_io done when we sent this request,
39107@@ -2691,7 +2691,7 @@ static int receive_DataRequest(struct drbd_connection *connection, struct packet
39108 goto out_free_e;
39109
39110 submit_for_resync:
39111- atomic_add(size >> 9, &device->rs_sect_ev);
39112+ atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
39113
39114 submit:
39115 update_receiver_timing_details(connection, drbd_submit_peer_request);
39116@@ -4564,7 +4564,7 @@ struct data_cmd {
39117 int expect_payload;
39118 size_t pkt_size;
39119 int (*fn)(struct drbd_connection *, struct packet_info *);
39120-};
39121+} __do_const;
39122
39123 static struct data_cmd drbd_cmd_handler[] = {
39124 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
39125@@ -4678,7 +4678,7 @@ static void conn_disconnect(struct drbd_connection *connection)
39126 if (!list_empty(&connection->current_epoch->list))
39127 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
39128 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
39129- atomic_set(&connection->current_epoch->epoch_size, 0);
39130+ atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
39131 connection->send.seen_any_write_yet = false;
39132
39133 drbd_info(connection, "Connection closed\n");
39134@@ -5182,7 +5182,7 @@ static int got_IsInSync(struct drbd_connection *connection, struct packet_info *
39135 put_ldev(device);
39136 }
39137 dec_rs_pending(device);
39138- atomic_add(blksize >> 9, &device->rs_sect_in);
39139+ atomic_add_unchecked(blksize >> 9, &device->rs_sect_in);
39140
39141 return 0;
39142 }
39143@@ -5470,7 +5470,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
39144 struct asender_cmd {
39145 size_t pkt_size;
39146 int (*fn)(struct drbd_connection *connection, struct packet_info *);
39147-};
39148+} __do_const;
39149
39150 static struct asender_cmd asender_tbl[] = {
39151 [P_PING] = { 0, got_Ping },
39152diff --git a/drivers/block/drbd/drbd_worker.c b/drivers/block/drbd/drbd_worker.c
39153index 50776b3..1477c3f 100644
39154--- a/drivers/block/drbd/drbd_worker.c
39155+++ b/drivers/block/drbd/drbd_worker.c
39156@@ -408,7 +408,7 @@ static int read_for_csum(struct drbd_peer_device *peer_device, sector_t sector,
39157 list_add_tail(&peer_req->w.list, &device->read_ee);
39158 spin_unlock_irq(&device->resource->req_lock);
39159
39160- atomic_add(size >> 9, &device->rs_sect_ev);
39161+ atomic_add_unchecked(size >> 9, &device->rs_sect_ev);
39162 if (drbd_submit_peer_request(device, peer_req, READ, DRBD_FAULT_RS_RD) == 0)
39163 return 0;
39164
39165@@ -553,7 +553,7 @@ static int drbd_rs_number_requests(struct drbd_device *device)
39166 unsigned int sect_in; /* Number of sectors that came in since the last turn */
39167 int number, mxb;
39168
39169- sect_in = atomic_xchg(&device->rs_sect_in, 0);
39170+ sect_in = atomic_xchg_unchecked(&device->rs_sect_in, 0);
39171 device->rs_in_flight -= sect_in;
39172
39173 rcu_read_lock();
39174@@ -1594,8 +1594,8 @@ void drbd_rs_controller_reset(struct drbd_device *device)
39175 {
39176 struct fifo_buffer *plan;
39177
39178- atomic_set(&device->rs_sect_in, 0);
39179- atomic_set(&device->rs_sect_ev, 0);
39180+ atomic_set_unchecked(&device->rs_sect_in, 0);
39181+ atomic_set_unchecked(&device->rs_sect_ev, 0);
39182 device->rs_in_flight = 0;
39183
39184 /* Updating the RCU protected object in place is necessary since
39185diff --git a/drivers/block/loop.c b/drivers/block/loop.c
39186index 6cb1beb..bf490f7 100644
39187--- a/drivers/block/loop.c
39188+++ b/drivers/block/loop.c
39189@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
39190
39191 file_start_write(file);
39192 set_fs(get_ds());
39193- bw = file->f_op->write(file, buf, len, &pos);
39194+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
39195 set_fs(old_fs);
39196 file_end_write(file);
39197 if (likely(bw == len))
39198diff --git a/drivers/block/nvme-core.c b/drivers/block/nvme-core.c
39199index 02351e2..a9ea617 100644
39200--- a/drivers/block/nvme-core.c
39201+++ b/drivers/block/nvme-core.c
39202@@ -73,7 +73,6 @@ static LIST_HEAD(dev_list);
39203 static struct task_struct *nvme_thread;
39204 static struct workqueue_struct *nvme_workq;
39205 static wait_queue_head_t nvme_kthread_wait;
39206-static struct notifier_block nvme_nb;
39207
39208 static void nvme_reset_failed_dev(struct work_struct *ws);
39209
39210@@ -2925,6 +2924,10 @@ static struct pci_driver nvme_driver = {
39211 .err_handler = &nvme_err_handler,
39212 };
39213
39214+static struct notifier_block nvme_nb = {
39215+ .notifier_call = &nvme_cpu_notify,
39216+};
39217+
39218 static int __init nvme_init(void)
39219 {
39220 int result;
39221@@ -2941,7 +2944,6 @@ static int __init nvme_init(void)
39222 else if (result > 0)
39223 nvme_major = result;
39224
39225- nvme_nb.notifier_call = &nvme_cpu_notify;
39226 result = register_hotcpu_notifier(&nvme_nb);
39227 if (result)
39228 goto unregister_blkdev;
39229diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
39230index 758ac44..58087fd 100644
39231--- a/drivers/block/pktcdvd.c
39232+++ b/drivers/block/pktcdvd.c
39233@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
39234
39235 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
39236 {
39237- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
39238+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
39239 }
39240
39241 /*
39242@@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
39243 return -EROFS;
39244 }
39245 pd->settings.fp = ti.fp;
39246- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
39247+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
39248
39249 if (ti.nwa_v) {
39250 pd->nwa = be32_to_cpu(ti.next_writable);
39251diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
39252index e5565fb..71be10b4 100644
39253--- a/drivers/block/smart1,2.h
39254+++ b/drivers/block/smart1,2.h
39255@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
39256 }
39257
39258 static struct access_method smart4_access = {
39259- smart4_submit_command,
39260- smart4_intr_mask,
39261- smart4_fifo_full,
39262- smart4_intr_pending,
39263- smart4_completed,
39264+ .submit_command = smart4_submit_command,
39265+ .set_intr_mask = smart4_intr_mask,
39266+ .fifo_full = smart4_fifo_full,
39267+ .intr_pending = smart4_intr_pending,
39268+ .command_completed = smart4_completed,
39269 };
39270
39271 /*
39272@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
39273 }
39274
39275 static struct access_method smart2_access = {
39276- smart2_submit_command,
39277- smart2_intr_mask,
39278- smart2_fifo_full,
39279- smart2_intr_pending,
39280- smart2_completed,
39281+ .submit_command = smart2_submit_command,
39282+ .set_intr_mask = smart2_intr_mask,
39283+ .fifo_full = smart2_fifo_full,
39284+ .intr_pending = smart2_intr_pending,
39285+ .command_completed = smart2_completed,
39286 };
39287
39288 /*
39289@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
39290 }
39291
39292 static struct access_method smart2e_access = {
39293- smart2e_submit_command,
39294- smart2e_intr_mask,
39295- smart2e_fifo_full,
39296- smart2e_intr_pending,
39297- smart2e_completed,
39298+ .submit_command = smart2e_submit_command,
39299+ .set_intr_mask = smart2e_intr_mask,
39300+ .fifo_full = smart2e_fifo_full,
39301+ .intr_pending = smart2e_intr_pending,
39302+ .command_completed = smart2e_completed,
39303 };
39304
39305 /*
39306@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
39307 }
39308
39309 static struct access_method smart1_access = {
39310- smart1_submit_command,
39311- smart1_intr_mask,
39312- smart1_fifo_full,
39313- smart1_intr_pending,
39314- smart1_completed,
39315+ .submit_command = smart1_submit_command,
39316+ .set_intr_mask = smart1_intr_mask,
39317+ .fifo_full = smart1_fifo_full,
39318+ .intr_pending = smart1_intr_pending,
39319+ .command_completed = smart1_completed,
39320 };
39321diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
39322index f038dba..bb74c08 100644
39323--- a/drivers/bluetooth/btwilink.c
39324+++ b/drivers/bluetooth/btwilink.c
39325@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
39326
39327 static int bt_ti_probe(struct platform_device *pdev)
39328 {
39329- static struct ti_st *hst;
39330+ struct ti_st *hst;
39331 struct hci_dev *hdev;
39332 int err;
39333
39334diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
39335index 898b84b..86f74b9 100644
39336--- a/drivers/cdrom/cdrom.c
39337+++ b/drivers/cdrom/cdrom.c
39338@@ -610,7 +610,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
39339 ENSURE(reset, CDC_RESET);
39340 ENSURE(generic_packet, CDC_GENERIC_PACKET);
39341 cdi->mc_flags = 0;
39342- cdo->n_minors = 0;
39343 cdi->options = CDO_USE_FFLAGS;
39344
39345 if (autoclose == 1 && CDROM_CAN(CDC_CLOSE_TRAY))
39346@@ -630,8 +629,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
39347 else
39348 cdi->cdda_method = CDDA_OLD;
39349
39350- if (!cdo->generic_packet)
39351- cdo->generic_packet = cdrom_dummy_generic_packet;
39352+ if (!cdo->generic_packet) {
39353+ pax_open_kernel();
39354+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
39355+ pax_close_kernel();
39356+ }
39357
39358 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
39359 mutex_lock(&cdrom_mutex);
39360@@ -652,7 +654,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
39361 if (cdi->exit)
39362 cdi->exit(cdi);
39363
39364- cdi->ops->n_minors--;
39365 cd_dbg(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
39366 }
39367
39368@@ -2126,7 +2127,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
39369 */
39370 nr = nframes;
39371 do {
39372- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
39373+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
39374 if (cgc.buffer)
39375 break;
39376
39377@@ -3434,7 +3435,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
39378 struct cdrom_device_info *cdi;
39379 int ret;
39380
39381- ret = scnprintf(info + *pos, max_size - *pos, header);
39382+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
39383 if (!ret)
39384 return 1;
39385
39386diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
39387index 584bc31..e64a12c 100644
39388--- a/drivers/cdrom/gdrom.c
39389+++ b/drivers/cdrom/gdrom.c
39390@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
39391 .audio_ioctl = gdrom_audio_ioctl,
39392 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
39393 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
39394- .n_minors = 1,
39395 };
39396
39397 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
39398diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
39399index 6e9f74a..50c7cea 100644
39400--- a/drivers/char/Kconfig
39401+++ b/drivers/char/Kconfig
39402@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
39403
39404 config DEVKMEM
39405 bool "/dev/kmem virtual device support"
39406- default y
39407+ default n
39408+ depends on !GRKERNSEC_KMEM
39409 help
39410 Say Y here if you want to support the /dev/kmem device. The
39411 /dev/kmem device is rarely used, but can be used for certain
39412@@ -577,6 +578,7 @@ config DEVPORT
39413 bool
39414 depends on !M68K
39415 depends on ISA || PCI
39416+ depends on !GRKERNSEC_KMEM
39417 default y
39418
39419 source "drivers/s390/char/Kconfig"
39420diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
39421index a48e05b..6bac831 100644
39422--- a/drivers/char/agp/compat_ioctl.c
39423+++ b/drivers/char/agp/compat_ioctl.c
39424@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
39425 return -ENOMEM;
39426 }
39427
39428- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
39429+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
39430 sizeof(*usegment) * ureserve.seg_count)) {
39431 kfree(usegment);
39432 kfree(ksegment);
39433diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
39434index 09f17eb..8531d2f 100644
39435--- a/drivers/char/agp/frontend.c
39436+++ b/drivers/char/agp/frontend.c
39437@@ -806,7 +806,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
39438 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
39439 return -EFAULT;
39440
39441- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
39442+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
39443 return -EFAULT;
39444
39445 client = agp_find_client_by_pid(reserve.pid);
39446@@ -836,7 +836,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
39447 if (segment == NULL)
39448 return -ENOMEM;
39449
39450- if (copy_from_user(segment, (void __user *) reserve.seg_list,
39451+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
39452 sizeof(struct agp_segment) * reserve.seg_count)) {
39453 kfree(segment);
39454 return -EFAULT;
39455diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
39456index 4f94375..413694e 100644
39457--- a/drivers/char/genrtc.c
39458+++ b/drivers/char/genrtc.c
39459@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
39460 switch (cmd) {
39461
39462 case RTC_PLL_GET:
39463+ memset(&pll, 0, sizeof(pll));
39464 if (get_rtc_pll(&pll))
39465 return -EINVAL;
39466 else
39467diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
39468index d5d4cd8..22d561d 100644
39469--- a/drivers/char/hpet.c
39470+++ b/drivers/char/hpet.c
39471@@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
39472 }
39473
39474 static int
39475-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
39476+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
39477 struct hpet_info *info)
39478 {
39479 struct hpet_timer __iomem *timer;
39480diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
39481index 86fe45c..c0ea948 100644
39482--- a/drivers/char/hw_random/intel-rng.c
39483+++ b/drivers/char/hw_random/intel-rng.c
39484@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
39485
39486 if (no_fwh_detect)
39487 return -ENODEV;
39488- printk(warning);
39489+ printk("%s", warning);
39490 return -EBUSY;
39491 }
39492
39493diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
39494index e6db938..835e3a2 100644
39495--- a/drivers/char/ipmi/ipmi_msghandler.c
39496+++ b/drivers/char/ipmi/ipmi_msghandler.c
39497@@ -438,7 +438,7 @@ struct ipmi_smi {
39498 struct proc_dir_entry *proc_dir;
39499 char proc_dir_name[10];
39500
39501- atomic_t stats[IPMI_NUM_STATS];
39502+ atomic_unchecked_t stats[IPMI_NUM_STATS];
39503
39504 /*
39505 * run_to_completion duplicate of smb_info, smi_info
39506@@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
39507 static DEFINE_MUTEX(smi_watchers_mutex);
39508
39509 #define ipmi_inc_stat(intf, stat) \
39510- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
39511+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
39512 #define ipmi_get_stat(intf, stat) \
39513- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
39514+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
39515
39516 static int is_lan_addr(struct ipmi_addr *addr)
39517 {
39518@@ -2926,7 +2926,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
39519 INIT_LIST_HEAD(&intf->cmd_rcvrs);
39520 init_waitqueue_head(&intf->waitq);
39521 for (i = 0; i < IPMI_NUM_STATS; i++)
39522- atomic_set(&intf->stats[i], 0);
39523+ atomic_set_unchecked(&intf->stats[i], 0);
39524
39525 intf->proc_dir = NULL;
39526
39527diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
39528index 5d66568..c9d93c3 100644
39529--- a/drivers/char/ipmi/ipmi_si_intf.c
39530+++ b/drivers/char/ipmi/ipmi_si_intf.c
39531@@ -285,7 +285,7 @@ struct smi_info {
39532 unsigned char slave_addr;
39533
39534 /* Counters and things for the proc filesystem. */
39535- atomic_t stats[SI_NUM_STATS];
39536+ atomic_unchecked_t stats[SI_NUM_STATS];
39537
39538 struct task_struct *thread;
39539
39540@@ -294,9 +294,9 @@ struct smi_info {
39541 };
39542
39543 #define smi_inc_stat(smi, stat) \
39544- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
39545+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
39546 #define smi_get_stat(smi, stat) \
39547- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
39548+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
39549
39550 #define SI_MAX_PARMS 4
39551
39552@@ -3374,7 +3374,7 @@ static int try_smi_init(struct smi_info *new_smi)
39553 atomic_set(&new_smi->req_events, 0);
39554 new_smi->run_to_completion = false;
39555 for (i = 0; i < SI_NUM_STATS; i++)
39556- atomic_set(&new_smi->stats[i], 0);
39557+ atomic_set_unchecked(&new_smi->stats[i], 0);
39558
39559 new_smi->interrupt_disabled = true;
39560 atomic_set(&new_smi->stop_operation, 0);
39561diff --git a/drivers/char/mem.c b/drivers/char/mem.c
39562index 917403f..dddd899 100644
39563--- a/drivers/char/mem.c
39564+++ b/drivers/char/mem.c
39565@@ -18,6 +18,7 @@
39566 #include <linux/raw.h>
39567 #include <linux/tty.h>
39568 #include <linux/capability.h>
39569+#include <linux/security.h>
39570 #include <linux/ptrace.h>
39571 #include <linux/device.h>
39572 #include <linux/highmem.h>
39573@@ -36,6 +37,10 @@
39574
39575 #define DEVPORT_MINOR 4
39576
39577+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
39578+extern const struct file_operations grsec_fops;
39579+#endif
39580+
39581 static inline unsigned long size_inside_page(unsigned long start,
39582 unsigned long size)
39583 {
39584@@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39585
39586 while (cursor < to) {
39587 if (!devmem_is_allowed(pfn)) {
39588+#ifdef CONFIG_GRKERNSEC_KMEM
39589+ gr_handle_mem_readwrite(from, to);
39590+#else
39591 printk(KERN_INFO
39592 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
39593 current->comm, from, to);
39594+#endif
39595 return 0;
39596 }
39597 cursor += PAGE_SIZE;
39598@@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39599 }
39600 return 1;
39601 }
39602+#elif defined(CONFIG_GRKERNSEC_KMEM)
39603+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39604+{
39605+ return 0;
39606+}
39607 #else
39608 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
39609 {
39610@@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
39611
39612 while (count > 0) {
39613 unsigned long remaining;
39614+ char *temp;
39615
39616 sz = size_inside_page(p, count);
39617
39618@@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
39619 if (!ptr)
39620 return -EFAULT;
39621
39622- remaining = copy_to_user(buf, ptr, sz);
39623+#ifdef CONFIG_PAX_USERCOPY
39624+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
39625+ if (!temp) {
39626+ unxlate_dev_mem_ptr(p, ptr);
39627+ return -ENOMEM;
39628+ }
39629+ memcpy(temp, ptr, sz);
39630+#else
39631+ temp = ptr;
39632+#endif
39633+
39634+ remaining = copy_to_user(buf, temp, sz);
39635+
39636+#ifdef CONFIG_PAX_USERCOPY
39637+ kfree(temp);
39638+#endif
39639+
39640 unxlate_dev_mem_ptr(p, ptr);
39641 if (remaining)
39642 return -EFAULT;
39643@@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39644 size_t count, loff_t *ppos)
39645 {
39646 unsigned long p = *ppos;
39647- ssize_t low_count, read, sz;
39648+ ssize_t low_count, read, sz, err = 0;
39649 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
39650- int err = 0;
39651
39652 read = 0;
39653 if (p < (unsigned long) high_memory) {
39654@@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39655 }
39656 #endif
39657 while (low_count > 0) {
39658+ char *temp;
39659+
39660 sz = size_inside_page(p, low_count);
39661
39662 /*
39663@@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
39664 */
39665 kbuf = xlate_dev_kmem_ptr((char *)p);
39666
39667- if (copy_to_user(buf, kbuf, sz))
39668+#ifdef CONFIG_PAX_USERCOPY
39669+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
39670+ if (!temp)
39671+ return -ENOMEM;
39672+ memcpy(temp, kbuf, sz);
39673+#else
39674+ temp = kbuf;
39675+#endif
39676+
39677+ err = copy_to_user(buf, temp, sz);
39678+
39679+#ifdef CONFIG_PAX_USERCOPY
39680+ kfree(temp);
39681+#endif
39682+
39683+ if (err)
39684 return -EFAULT;
39685 buf += sz;
39686 p += sz;
39687@@ -827,6 +874,9 @@ static const struct memdev {
39688 #ifdef CONFIG_PRINTK
39689 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
39690 #endif
39691+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
39692+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
39693+#endif
39694 };
39695
39696 static int memory_open(struct inode *inode, struct file *filp)
39697@@ -898,7 +948,7 @@ static int __init chr_dev_init(void)
39698 continue;
39699
39700 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
39701- NULL, devlist[minor].name);
39702+ NULL, "%s", devlist[minor].name);
39703 }
39704
39705 return tty_init();
39706diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
39707index 9df78e2..01ba9ae 100644
39708--- a/drivers/char/nvram.c
39709+++ b/drivers/char/nvram.c
39710@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
39711
39712 spin_unlock_irq(&rtc_lock);
39713
39714- if (copy_to_user(buf, contents, tmp - contents))
39715+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
39716 return -EFAULT;
39717
39718 *ppos = i;
39719diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
39720index 0ea9986..e7b07e4 100644
39721--- a/drivers/char/pcmcia/synclink_cs.c
39722+++ b/drivers/char/pcmcia/synclink_cs.c
39723@@ -2345,7 +2345,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
39724
39725 if (debug_level >= DEBUG_LEVEL_INFO)
39726 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
39727- __FILE__, __LINE__, info->device_name, port->count);
39728+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
39729
39730 if (tty_port_close_start(port, tty, filp) == 0)
39731 goto cleanup;
39732@@ -2363,7 +2363,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
39733 cleanup:
39734 if (debug_level >= DEBUG_LEVEL_INFO)
39735 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
39736- tty->driver->name, port->count);
39737+ tty->driver->name, atomic_read(&port->count));
39738 }
39739
39740 /* Wait until the transmitter is empty.
39741@@ -2505,7 +2505,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
39742
39743 if (debug_level >= DEBUG_LEVEL_INFO)
39744 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
39745- __FILE__, __LINE__, tty->driver->name, port->count);
39746+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
39747
39748 /* If port is closing, signal caller to try again */
39749 if (port->flags & ASYNC_CLOSING){
39750@@ -2525,11 +2525,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
39751 goto cleanup;
39752 }
39753 spin_lock(&port->lock);
39754- port->count++;
39755+ atomic_inc(&port->count);
39756 spin_unlock(&port->lock);
39757 spin_unlock_irqrestore(&info->netlock, flags);
39758
39759- if (port->count == 1) {
39760+ if (atomic_read(&port->count) == 1) {
39761 /* 1st open on this device, init hardware */
39762 retval = startup(info, tty);
39763 if (retval < 0)
39764@@ -3918,7 +3918,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
39765 unsigned short new_crctype;
39766
39767 /* return error if TTY interface open */
39768- if (info->port.count)
39769+ if (atomic_read(&info->port.count))
39770 return -EBUSY;
39771
39772 switch (encoding)
39773@@ -4022,7 +4022,7 @@ static int hdlcdev_open(struct net_device *dev)
39774
39775 /* arbitrate between network and tty opens */
39776 spin_lock_irqsave(&info->netlock, flags);
39777- if (info->port.count != 0 || info->netcount != 0) {
39778+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
39779 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
39780 spin_unlock_irqrestore(&info->netlock, flags);
39781 return -EBUSY;
39782@@ -4112,7 +4112,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
39783 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
39784
39785 /* return error if TTY interface open */
39786- if (info->port.count)
39787+ if (atomic_read(&info->port.count))
39788 return -EBUSY;
39789
39790 if (cmd != SIOCWANDEV)
39791diff --git a/drivers/char/random.c b/drivers/char/random.c
39792index 8c86a95..7c499f3 100644
39793--- a/drivers/char/random.c
39794+++ b/drivers/char/random.c
39795@@ -289,9 +289,6 @@
39796 /*
39797 * To allow fractional bits to be tracked, the entropy_count field is
39798 * denominated in units of 1/8th bits.
39799- *
39800- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
39801- * credit_entropy_bits() needs to be 64 bits wide.
39802 */
39803 #define ENTROPY_SHIFT 3
39804 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
39805@@ -439,9 +436,9 @@ struct entropy_store {
39806 };
39807
39808 static void push_to_pool(struct work_struct *work);
39809-static __u32 input_pool_data[INPUT_POOL_WORDS];
39810-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
39811-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
39812+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
39813+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39814+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
39815
39816 static struct entropy_store input_pool = {
39817 .poolinfo = &poolinfo_table[0],
39818@@ -635,7 +632,7 @@ retry:
39819 /* The +2 corresponds to the /4 in the denominator */
39820
39821 do {
39822- unsigned int anfrac = min(pnfrac, pool_size/2);
39823+ u64 anfrac = min(pnfrac, pool_size/2);
39824 unsigned int add =
39825 ((pool_size - entropy_count)*anfrac*3) >> s;
39826
39827@@ -1207,7 +1204,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
39828
39829 extract_buf(r, tmp);
39830 i = min_t(int, nbytes, EXTRACT_SIZE);
39831- if (copy_to_user(buf, tmp, i)) {
39832+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
39833 ret = -EFAULT;
39834 break;
39835 }
39836@@ -1590,7 +1587,7 @@ static char sysctl_bootid[16];
39837 static int proc_do_uuid(struct ctl_table *table, int write,
39838 void __user *buffer, size_t *lenp, loff_t *ppos)
39839 {
39840- struct ctl_table fake_table;
39841+ ctl_table_no_const fake_table;
39842 unsigned char buf[64], tmp_uuid[16], *uuid;
39843
39844 uuid = table->data;
39845@@ -1620,7 +1617,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
39846 static int proc_do_entropy(struct ctl_table *table, int write,
39847 void __user *buffer, size_t *lenp, loff_t *ppos)
39848 {
39849- struct ctl_table fake_table;
39850+ ctl_table_no_const fake_table;
39851 int entropy_count;
39852
39853 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
39854diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
39855index 7cc1fe22..b602d6b 100644
39856--- a/drivers/char/sonypi.c
39857+++ b/drivers/char/sonypi.c
39858@@ -54,6 +54,7 @@
39859
39860 #include <asm/uaccess.h>
39861 #include <asm/io.h>
39862+#include <asm/local.h>
39863
39864 #include <linux/sonypi.h>
39865
39866@@ -490,7 +491,7 @@ static struct sonypi_device {
39867 spinlock_t fifo_lock;
39868 wait_queue_head_t fifo_proc_list;
39869 struct fasync_struct *fifo_async;
39870- int open_count;
39871+ local_t open_count;
39872 int model;
39873 struct input_dev *input_jog_dev;
39874 struct input_dev *input_key_dev;
39875@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
39876 static int sonypi_misc_release(struct inode *inode, struct file *file)
39877 {
39878 mutex_lock(&sonypi_device.lock);
39879- sonypi_device.open_count--;
39880+ local_dec(&sonypi_device.open_count);
39881 mutex_unlock(&sonypi_device.lock);
39882 return 0;
39883 }
39884@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
39885 {
39886 mutex_lock(&sonypi_device.lock);
39887 /* Flush input queue on first open */
39888- if (!sonypi_device.open_count)
39889+ if (!local_read(&sonypi_device.open_count))
39890 kfifo_reset(&sonypi_device.fifo);
39891- sonypi_device.open_count++;
39892+ local_inc(&sonypi_device.open_count);
39893 mutex_unlock(&sonypi_device.lock);
39894
39895 return 0;
39896diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
39897index 565a947..dcdc06e 100644
39898--- a/drivers/char/tpm/tpm_acpi.c
39899+++ b/drivers/char/tpm/tpm_acpi.c
39900@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
39901 virt = acpi_os_map_iomem(start, len);
39902 if (!virt) {
39903 kfree(log->bios_event_log);
39904+ log->bios_event_log = NULL;
39905 printk("%s: ERROR - Unable to map memory\n", __func__);
39906 return -EIO;
39907 }
39908
39909- memcpy_fromio(log->bios_event_log, virt, len);
39910+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
39911
39912 acpi_os_unmap_iomem(virt, len);
39913 return 0;
39914diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
39915index 3a56a13..f8cbd25 100644
39916--- a/drivers/char/tpm/tpm_eventlog.c
39917+++ b/drivers/char/tpm/tpm_eventlog.c
39918@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
39919 event = addr;
39920
39921 if ((event->event_type == 0 && event->event_size == 0) ||
39922- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
39923+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
39924 return NULL;
39925
39926 return addr;
39927@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
39928 return NULL;
39929
39930 if ((event->event_type == 0 && event->event_size == 0) ||
39931- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
39932+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
39933 return NULL;
39934
39935 (*pos)++;
39936@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
39937 int i;
39938
39939 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
39940- seq_putc(m, data[i]);
39941+ if (!seq_putc(m, data[i]))
39942+ return -EFAULT;
39943
39944 return 0;
39945 }
39946diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
39947index b585b47..488f43e 100644
39948--- a/drivers/char/virtio_console.c
39949+++ b/drivers/char/virtio_console.c
39950@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
39951 if (to_user) {
39952 ssize_t ret;
39953
39954- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
39955+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
39956 if (ret)
39957 return -EFAULT;
39958 } else {
39959@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
39960 if (!port_has_data(port) && !port->host_connected)
39961 return 0;
39962
39963- return fill_readbuf(port, ubuf, count, true);
39964+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
39965 }
39966
39967 static int wait_port_writable(struct port *port, bool nonblock)
39968diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
39969index b9355da..9611f4e 100644
39970--- a/drivers/clk/clk-composite.c
39971+++ b/drivers/clk/clk-composite.c
39972@@ -191,7 +191,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
39973 struct clk *clk;
39974 struct clk_init_data init;
39975 struct clk_composite *composite;
39976- struct clk_ops *clk_composite_ops;
39977+ clk_ops_no_const *clk_composite_ops;
39978
39979 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
39980 if (!composite) {
39981diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
39982index dd3a78c..386d49c 100644
39983--- a/drivers/clk/socfpga/clk-gate.c
39984+++ b/drivers/clk/socfpga/clk-gate.c
39985@@ -22,6 +22,7 @@
39986 #include <linux/mfd/syscon.h>
39987 #include <linux/of.h>
39988 #include <linux/regmap.h>
39989+#include <asm/pgtable.h>
39990
39991 #include "clk.h"
39992
39993@@ -174,7 +175,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
39994 return 0;
39995 }
39996
39997-static struct clk_ops gateclk_ops = {
39998+static clk_ops_no_const gateclk_ops __read_only = {
39999 .prepare = socfpga_clk_prepare,
40000 .recalc_rate = socfpga_clk_recalc_rate,
40001 .get_parent = socfpga_clk_get_parent,
40002@@ -208,8 +209,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
40003 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
40004 socfpga_clk->hw.bit_idx = clk_gate[1];
40005
40006- gateclk_ops.enable = clk_gate_ops.enable;
40007- gateclk_ops.disable = clk_gate_ops.disable;
40008+ pax_open_kernel();
40009+ *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
40010+ *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
40011+ pax_close_kernel();
40012 }
40013
40014 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
40015diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
40016index de6da95..c98278b 100644
40017--- a/drivers/clk/socfpga/clk-pll.c
40018+++ b/drivers/clk/socfpga/clk-pll.c
40019@@ -21,6 +21,7 @@
40020 #include <linux/io.h>
40021 #include <linux/of.h>
40022 #include <linux/of_address.h>
40023+#include <asm/pgtable.h>
40024
40025 #include "clk.h"
40026
40027@@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
40028 CLK_MGR_PLL_CLK_SRC_MASK;
40029 }
40030
40031-static struct clk_ops clk_pll_ops = {
40032+static clk_ops_no_const clk_pll_ops __read_only = {
40033 .recalc_rate = clk_pll_recalc_rate,
40034 .get_parent = clk_pll_get_parent,
40035 };
40036@@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
40037 pll_clk->hw.hw.init = &init;
40038
40039 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
40040- clk_pll_ops.enable = clk_gate_ops.enable;
40041- clk_pll_ops.disable = clk_gate_ops.disable;
40042+ pax_open_kernel();
40043+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
40044+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
40045+ pax_close_kernel();
40046
40047 clk = clk_register(NULL, &pll_clk->hw.hw);
40048 if (WARN_ON(IS_ERR(clk))) {
40049diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
40050index b0c18ed..1713a80 100644
40051--- a/drivers/cpufreq/acpi-cpufreq.c
40052+++ b/drivers/cpufreq/acpi-cpufreq.c
40053@@ -675,8 +675,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40054 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
40055 per_cpu(acfreq_data, cpu) = data;
40056
40057- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
40058- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40059+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
40060+ pax_open_kernel();
40061+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
40062+ pax_close_kernel();
40063+ }
40064
40065 result = acpi_processor_register_performance(data->acpi_data, cpu);
40066 if (result)
40067@@ -809,7 +812,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
40068 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
40069 break;
40070 case ACPI_ADR_SPACE_FIXED_HARDWARE:
40071- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40072+ pax_open_kernel();
40073+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
40074+ pax_close_kernel();
40075 break;
40076 default:
40077 break;
40078@@ -903,8 +908,10 @@ static void __init acpi_cpufreq_boost_init(void)
40079 if (!msrs)
40080 return;
40081
40082- acpi_cpufreq_driver.boost_supported = true;
40083- acpi_cpufreq_driver.boost_enabled = boost_state(0);
40084+ pax_open_kernel();
40085+ *(bool *)&acpi_cpufreq_driver.boost_supported = true;
40086+ *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
40087+ pax_close_kernel();
40088
40089 cpu_notifier_register_begin();
40090
40091diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
40092index c05821e..373651a 100644
40093--- a/drivers/cpufreq/cpufreq.c
40094+++ b/drivers/cpufreq/cpufreq.c
40095@@ -2106,7 +2106,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
40096 }
40097
40098 mutex_lock(&cpufreq_governor_mutex);
40099- list_del(&governor->governor_list);
40100+ pax_list_del(&governor->governor_list);
40101 mutex_unlock(&cpufreq_governor_mutex);
40102 return;
40103 }
40104@@ -2322,7 +2322,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
40105 return NOTIFY_OK;
40106 }
40107
40108-static struct notifier_block __refdata cpufreq_cpu_notifier = {
40109+static struct notifier_block cpufreq_cpu_notifier = {
40110 .notifier_call = cpufreq_cpu_callback,
40111 };
40112
40113@@ -2362,13 +2362,17 @@ int cpufreq_boost_trigger_state(int state)
40114 return 0;
40115
40116 write_lock_irqsave(&cpufreq_driver_lock, flags);
40117- cpufreq_driver->boost_enabled = state;
40118+ pax_open_kernel();
40119+ *(bool *)&cpufreq_driver->boost_enabled = state;
40120+ pax_close_kernel();
40121 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40122
40123 ret = cpufreq_driver->set_boost(state);
40124 if (ret) {
40125 write_lock_irqsave(&cpufreq_driver_lock, flags);
40126- cpufreq_driver->boost_enabled = !state;
40127+ pax_open_kernel();
40128+ *(bool *)&cpufreq_driver->boost_enabled = !state;
40129+ pax_close_kernel();
40130 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
40131
40132 pr_err("%s: Cannot %s BOOST\n",
40133@@ -2425,8 +2429,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40134
40135 pr_debug("trying to register driver %s\n", driver_data->name);
40136
40137- if (driver_data->setpolicy)
40138- driver_data->flags |= CPUFREQ_CONST_LOOPS;
40139+ if (driver_data->setpolicy) {
40140+ pax_open_kernel();
40141+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
40142+ pax_close_kernel();
40143+ }
40144
40145 write_lock_irqsave(&cpufreq_driver_lock, flags);
40146 if (cpufreq_driver) {
40147@@ -2441,8 +2448,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
40148 * Check if driver provides function to enable boost -
40149 * if not, use cpufreq_boost_set_sw as default
40150 */
40151- if (!cpufreq_driver->set_boost)
40152- cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40153+ if (!cpufreq_driver->set_boost) {
40154+ pax_open_kernel();
40155+ *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
40156+ pax_close_kernel();
40157+ }
40158
40159 ret = cpufreq_sysfs_create_file(&boost.attr);
40160 if (ret) {
40161diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
40162index 1b44496..b80ff5e 100644
40163--- a/drivers/cpufreq/cpufreq_governor.c
40164+++ b/drivers/cpufreq/cpufreq_governor.c
40165@@ -245,7 +245,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40166 struct dbs_data *dbs_data;
40167 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
40168 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
40169- struct od_ops *od_ops = NULL;
40170+ const struct od_ops *od_ops = NULL;
40171 struct od_dbs_tuners *od_tuners = NULL;
40172 struct cs_dbs_tuners *cs_tuners = NULL;
40173 struct cpu_dbs_common_info *cpu_cdbs;
40174@@ -311,7 +311,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40175
40176 if ((cdata->governor == GOV_CONSERVATIVE) &&
40177 (!policy->governor->initialized)) {
40178- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40179+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40180
40181 cpufreq_register_notifier(cs_ops->notifier_block,
40182 CPUFREQ_TRANSITION_NOTIFIER);
40183@@ -331,7 +331,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
40184
40185 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
40186 (policy->governor->initialized == 1)) {
40187- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40188+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
40189
40190 cpufreq_unregister_notifier(cs_ops->notifier_block,
40191 CPUFREQ_TRANSITION_NOTIFIER);
40192diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
40193index cc401d1..8197340 100644
40194--- a/drivers/cpufreq/cpufreq_governor.h
40195+++ b/drivers/cpufreq/cpufreq_governor.h
40196@@ -212,7 +212,7 @@ struct common_dbs_data {
40197 void (*exit)(struct dbs_data *dbs_data);
40198
40199 /* Governor specific ops, see below */
40200- void *gov_ops;
40201+ const void *gov_ops;
40202 };
40203
40204 /* Governor Per policy data */
40205@@ -232,7 +232,7 @@ struct od_ops {
40206 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
40207 unsigned int freq_next, unsigned int relation);
40208 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
40209-};
40210+} __no_const;
40211
40212 struct cs_ops {
40213 struct notifier_block *notifier_block;
40214diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
40215index ad3f38f..8f086cd 100644
40216--- a/drivers/cpufreq/cpufreq_ondemand.c
40217+++ b/drivers/cpufreq/cpufreq_ondemand.c
40218@@ -524,7 +524,7 @@ static void od_exit(struct dbs_data *dbs_data)
40219
40220 define_get_cpu_dbs_routines(od_cpu_dbs_info);
40221
40222-static struct od_ops od_ops = {
40223+static struct od_ops od_ops __read_only = {
40224 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
40225 .powersave_bias_target = generic_powersave_bias_target,
40226 .freq_increase = dbs_freq_increase,
40227@@ -579,14 +579,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
40228 (struct cpufreq_policy *, unsigned int, unsigned int),
40229 unsigned int powersave_bias)
40230 {
40231- od_ops.powersave_bias_target = f;
40232+ pax_open_kernel();
40233+ *(void **)&od_ops.powersave_bias_target = f;
40234+ pax_close_kernel();
40235 od_set_powersave_bias(powersave_bias);
40236 }
40237 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
40238
40239 void od_unregister_powersave_bias_handler(void)
40240 {
40241- od_ops.powersave_bias_target = generic_powersave_bias_target;
40242+ pax_open_kernel();
40243+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
40244+ pax_close_kernel();
40245 od_set_powersave_bias(0);
40246 }
40247 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
40248diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
40249index 27bb6d3..4cf595c 100644
40250--- a/drivers/cpufreq/intel_pstate.c
40251+++ b/drivers/cpufreq/intel_pstate.c
40252@@ -133,10 +133,10 @@ struct pstate_funcs {
40253 struct cpu_defaults {
40254 struct pstate_adjust_policy pid_policy;
40255 struct pstate_funcs funcs;
40256-};
40257+} __do_const;
40258
40259 static struct pstate_adjust_policy pid_params;
40260-static struct pstate_funcs pstate_funcs;
40261+static struct pstate_funcs *pstate_funcs;
40262
40263 struct perf_limits {
40264 int no_turbo;
40265@@ -594,18 +594,18 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
40266
40267 cpu->pstate.current_pstate = pstate;
40268
40269- pstate_funcs.set(cpu, pstate);
40270+ pstate_funcs->set(cpu, pstate);
40271 }
40272
40273 static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
40274 {
40275- cpu->pstate.min_pstate = pstate_funcs.get_min();
40276- cpu->pstate.max_pstate = pstate_funcs.get_max();
40277- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
40278- cpu->pstate.scaling = pstate_funcs.get_scaling();
40279+ cpu->pstate.min_pstate = pstate_funcs->get_min();
40280+ cpu->pstate.max_pstate = pstate_funcs->get_max();
40281+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
40282+ cpu->pstate.scaling = pstate_funcs->get_scaling();
40283
40284- if (pstate_funcs.get_vid)
40285- pstate_funcs.get_vid(cpu);
40286+ if (pstate_funcs->get_vid)
40287+ pstate_funcs->get_vid(cpu);
40288 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
40289 }
40290
40291@@ -875,9 +875,9 @@ static int intel_pstate_msrs_not_valid(void)
40292 rdmsrl(MSR_IA32_APERF, aperf);
40293 rdmsrl(MSR_IA32_MPERF, mperf);
40294
40295- if (!pstate_funcs.get_max() ||
40296- !pstate_funcs.get_min() ||
40297- !pstate_funcs.get_turbo())
40298+ if (!pstate_funcs->get_max() ||
40299+ !pstate_funcs->get_min() ||
40300+ !pstate_funcs->get_turbo())
40301 return -ENODEV;
40302
40303 rdmsrl(MSR_IA32_APERF, tmp);
40304@@ -891,7 +891,7 @@ static int intel_pstate_msrs_not_valid(void)
40305 return 0;
40306 }
40307
40308-static void copy_pid_params(struct pstate_adjust_policy *policy)
40309+static void copy_pid_params(const struct pstate_adjust_policy *policy)
40310 {
40311 pid_params.sample_rate_ms = policy->sample_rate_ms;
40312 pid_params.p_gain_pct = policy->p_gain_pct;
40313@@ -903,12 +903,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
40314
40315 static void copy_cpu_funcs(struct pstate_funcs *funcs)
40316 {
40317- pstate_funcs.get_max = funcs->get_max;
40318- pstate_funcs.get_min = funcs->get_min;
40319- pstate_funcs.get_turbo = funcs->get_turbo;
40320- pstate_funcs.get_scaling = funcs->get_scaling;
40321- pstate_funcs.set = funcs->set;
40322- pstate_funcs.get_vid = funcs->get_vid;
40323+ pstate_funcs = funcs;
40324 }
40325
40326 #if IS_ENABLED(CONFIG_ACPI)
40327diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
40328index 529cfd9..0e28fff 100644
40329--- a/drivers/cpufreq/p4-clockmod.c
40330+++ b/drivers/cpufreq/p4-clockmod.c
40331@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
40332 case 0x0F: /* Core Duo */
40333 case 0x16: /* Celeron Core */
40334 case 0x1C: /* Atom */
40335- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40336+ pax_open_kernel();
40337+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40338+ pax_close_kernel();
40339 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
40340 case 0x0D: /* Pentium M (Dothan) */
40341- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40342+ pax_open_kernel();
40343+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40344+ pax_close_kernel();
40345 /* fall through */
40346 case 0x09: /* Pentium M (Banias) */
40347 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
40348@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
40349
40350 /* on P-4s, the TSC runs with constant frequency independent whether
40351 * throttling is active or not. */
40352- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40353+ pax_open_kernel();
40354+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
40355+ pax_close_kernel();
40356
40357 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
40358 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
40359diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
40360index 9bb42ba..b01b4a2 100644
40361--- a/drivers/cpufreq/sparc-us3-cpufreq.c
40362+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
40363@@ -18,14 +18,12 @@
40364 #include <asm/head.h>
40365 #include <asm/timer.h>
40366
40367-static struct cpufreq_driver *cpufreq_us3_driver;
40368-
40369 struct us3_freq_percpu_info {
40370 struct cpufreq_frequency_table table[4];
40371 };
40372
40373 /* Indexed by cpu number. */
40374-static struct us3_freq_percpu_info *us3_freq_table;
40375+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
40376
40377 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
40378 * in the Safari config register.
40379@@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
40380
40381 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
40382 {
40383- if (cpufreq_us3_driver)
40384- us3_freq_target(policy, 0);
40385+ us3_freq_target(policy, 0);
40386
40387 return 0;
40388 }
40389
40390+static int __init us3_freq_init(void);
40391+static void __exit us3_freq_exit(void);
40392+
40393+static struct cpufreq_driver cpufreq_us3_driver = {
40394+ .init = us3_freq_cpu_init,
40395+ .verify = cpufreq_generic_frequency_table_verify,
40396+ .target_index = us3_freq_target,
40397+ .get = us3_freq_get,
40398+ .exit = us3_freq_cpu_exit,
40399+ .name = "UltraSPARC-III",
40400+
40401+};
40402+
40403 static int __init us3_freq_init(void)
40404 {
40405 unsigned long manuf, impl, ver;
40406- int ret;
40407
40408 if (tlb_type != cheetah && tlb_type != cheetah_plus)
40409 return -ENODEV;
40410@@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
40411 (impl == CHEETAH_IMPL ||
40412 impl == CHEETAH_PLUS_IMPL ||
40413 impl == JAGUAR_IMPL ||
40414- impl == PANTHER_IMPL)) {
40415- struct cpufreq_driver *driver;
40416-
40417- ret = -ENOMEM;
40418- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
40419- if (!driver)
40420- goto err_out;
40421-
40422- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
40423- GFP_KERNEL);
40424- if (!us3_freq_table)
40425- goto err_out;
40426-
40427- driver->init = us3_freq_cpu_init;
40428- driver->verify = cpufreq_generic_frequency_table_verify;
40429- driver->target_index = us3_freq_target;
40430- driver->get = us3_freq_get;
40431- driver->exit = us3_freq_cpu_exit;
40432- strcpy(driver->name, "UltraSPARC-III");
40433-
40434- cpufreq_us3_driver = driver;
40435- ret = cpufreq_register_driver(driver);
40436- if (ret)
40437- goto err_out;
40438-
40439- return 0;
40440-
40441-err_out:
40442- if (driver) {
40443- kfree(driver);
40444- cpufreq_us3_driver = NULL;
40445- }
40446- kfree(us3_freq_table);
40447- us3_freq_table = NULL;
40448- return ret;
40449- }
40450+ impl == PANTHER_IMPL))
40451+ return cpufreq_register_driver(&cpufreq_us3_driver);
40452
40453 return -ENODEV;
40454 }
40455
40456 static void __exit us3_freq_exit(void)
40457 {
40458- if (cpufreq_us3_driver) {
40459- cpufreq_unregister_driver(cpufreq_us3_driver);
40460- kfree(cpufreq_us3_driver);
40461- cpufreq_us3_driver = NULL;
40462- kfree(us3_freq_table);
40463- us3_freq_table = NULL;
40464- }
40465+ cpufreq_unregister_driver(&cpufreq_us3_driver);
40466 }
40467
40468 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
40469diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
40470index 7d4a315..21bb886 100644
40471--- a/drivers/cpufreq/speedstep-centrino.c
40472+++ b/drivers/cpufreq/speedstep-centrino.c
40473@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
40474 !cpu_has(cpu, X86_FEATURE_EST))
40475 return -ENODEV;
40476
40477- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
40478- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
40479+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
40480+ pax_open_kernel();
40481+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
40482+ pax_close_kernel();
40483+ }
40484
40485 if (policy->cpu != 0)
40486 return -ENODEV;
40487diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
40488index e431d11..d0b997e 100644
40489--- a/drivers/cpuidle/driver.c
40490+++ b/drivers/cpuidle/driver.c
40491@@ -194,7 +194,7 @@ static int poll_idle(struct cpuidle_device *dev,
40492
40493 static void poll_idle_init(struct cpuidle_driver *drv)
40494 {
40495- struct cpuidle_state *state = &drv->states[0];
40496+ cpuidle_state_no_const *state = &drv->states[0];
40497
40498 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
40499 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
40500diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
40501index ca89412..a7b9c49 100644
40502--- a/drivers/cpuidle/governor.c
40503+++ b/drivers/cpuidle/governor.c
40504@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
40505 mutex_lock(&cpuidle_lock);
40506 if (__cpuidle_find_governor(gov->name) == NULL) {
40507 ret = 0;
40508- list_add_tail(&gov->governor_list, &cpuidle_governors);
40509+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
40510 if (!cpuidle_curr_governor ||
40511 cpuidle_curr_governor->rating < gov->rating)
40512 cpuidle_switch_governor(gov);
40513diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
40514index 97c5903..023ad23 100644
40515--- a/drivers/cpuidle/sysfs.c
40516+++ b/drivers/cpuidle/sysfs.c
40517@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
40518 NULL
40519 };
40520
40521-static struct attribute_group cpuidle_attr_group = {
40522+static attribute_group_no_const cpuidle_attr_group = {
40523 .attrs = cpuidle_default_attrs,
40524 .name = "cpuidle",
40525 };
40526diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
40527index 8d2a772..33826c9 100644
40528--- a/drivers/crypto/hifn_795x.c
40529+++ b/drivers/crypto/hifn_795x.c
40530@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
40531 MODULE_PARM_DESC(hifn_pll_ref,
40532 "PLL reference clock (pci[freq] or ext[freq], default ext)");
40533
40534-static atomic_t hifn_dev_number;
40535+static atomic_unchecked_t hifn_dev_number;
40536
40537 #define ACRYPTO_OP_DECRYPT 0
40538 #define ACRYPTO_OP_ENCRYPT 1
40539@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
40540 goto err_out_disable_pci_device;
40541
40542 snprintf(name, sizeof(name), "hifn%d",
40543- atomic_inc_return(&hifn_dev_number)-1);
40544+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
40545
40546 err = pci_request_regions(pdev, name);
40547 if (err)
40548diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
40549index 9f90369..bfcacdb 100644
40550--- a/drivers/devfreq/devfreq.c
40551+++ b/drivers/devfreq/devfreq.c
40552@@ -673,7 +673,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
40553 goto err_out;
40554 }
40555
40556- list_add(&governor->node, &devfreq_governor_list);
40557+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
40558
40559 list_for_each_entry(devfreq, &devfreq_list, node) {
40560 int ret = 0;
40561@@ -761,7 +761,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
40562 }
40563 }
40564
40565- list_del(&governor->node);
40566+ pax_list_del((struct list_head *)&governor->node);
40567 err_out:
40568 mutex_unlock(&devfreq_list_lock);
40569
40570diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
40571index 42d4974..2714f36 100644
40572--- a/drivers/dma/sh/shdma-base.c
40573+++ b/drivers/dma/sh/shdma-base.c
40574@@ -228,8 +228,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
40575 schan->slave_id = -EINVAL;
40576 }
40577
40578- schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
40579- sdev->desc_size, GFP_KERNEL);
40580+ schan->desc = kcalloc(sdev->desc_size,
40581+ NR_DESCS_PER_CHANNEL, GFP_KERNEL);
40582 if (!schan->desc) {
40583 ret = -ENOMEM;
40584 goto edescalloc;
40585diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
40586index 58eb857..d7e42c8 100644
40587--- a/drivers/dma/sh/shdmac.c
40588+++ b/drivers/dma/sh/shdmac.c
40589@@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
40590 return ret;
40591 }
40592
40593-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
40594+static struct notifier_block sh_dmae_nmi_notifier = {
40595 .notifier_call = sh_dmae_nmi_handler,
40596
40597 /* Run before NMI debug handler and KGDB */
40598diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
40599index 592af5f..bb1d583 100644
40600--- a/drivers/edac/edac_device.c
40601+++ b/drivers/edac/edac_device.c
40602@@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
40603 */
40604 int edac_device_alloc_index(void)
40605 {
40606- static atomic_t device_indexes = ATOMIC_INIT(0);
40607+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
40608
40609- return atomic_inc_return(&device_indexes) - 1;
40610+ return atomic_inc_return_unchecked(&device_indexes) - 1;
40611 }
40612 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
40613
40614diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
40615index a6cd361..7bdbf53 100644
40616--- a/drivers/edac/edac_mc_sysfs.c
40617+++ b/drivers/edac/edac_mc_sysfs.c
40618@@ -154,7 +154,7 @@ static const char * const edac_caps[] = {
40619 struct dev_ch_attribute {
40620 struct device_attribute attr;
40621 int channel;
40622-};
40623+} __do_const;
40624
40625 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
40626 struct dev_ch_attribute dev_attr_legacy_##_name = \
40627@@ -1011,14 +1011,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
40628 }
40629
40630 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
40631+ pax_open_kernel();
40632 if (mci->get_sdram_scrub_rate) {
40633- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
40634- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
40635+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
40636+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
40637 }
40638 if (mci->set_sdram_scrub_rate) {
40639- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
40640- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
40641+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
40642+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
40643 }
40644+ pax_close_kernel();
40645 err = device_create_file(&mci->dev,
40646 &dev_attr_sdram_scrub_rate);
40647 if (err) {
40648diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
40649index 2cf44b4d..6dd2dc7 100644
40650--- a/drivers/edac/edac_pci.c
40651+++ b/drivers/edac/edac_pci.c
40652@@ -29,7 +29,7 @@
40653
40654 static DEFINE_MUTEX(edac_pci_ctls_mutex);
40655 static LIST_HEAD(edac_pci_list);
40656-static atomic_t pci_indexes = ATOMIC_INIT(0);
40657+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
40658
40659 /*
40660 * edac_pci_alloc_ctl_info
40661@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
40662 */
40663 int edac_pci_alloc_index(void)
40664 {
40665- return atomic_inc_return(&pci_indexes) - 1;
40666+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
40667 }
40668 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
40669
40670diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
40671index e8658e4..22746d6 100644
40672--- a/drivers/edac/edac_pci_sysfs.c
40673+++ b/drivers/edac/edac_pci_sysfs.c
40674@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
40675 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
40676 static int edac_pci_poll_msec = 1000; /* one second workq period */
40677
40678-static atomic_t pci_parity_count = ATOMIC_INIT(0);
40679-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
40680+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
40681+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
40682
40683 static struct kobject *edac_pci_top_main_kobj;
40684 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
40685@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
40686 void *value;
40687 ssize_t(*show) (void *, char *);
40688 ssize_t(*store) (void *, const char *, size_t);
40689-};
40690+} __do_const;
40691
40692 /* Set of show/store abstract level functions for PCI Parity object */
40693 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
40694@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40695 edac_printk(KERN_CRIT, EDAC_PCI,
40696 "Signaled System Error on %s\n",
40697 pci_name(dev));
40698- atomic_inc(&pci_nonparity_count);
40699+ atomic_inc_unchecked(&pci_nonparity_count);
40700 }
40701
40702 if (status & (PCI_STATUS_PARITY)) {
40703@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40704 "Master Data Parity Error on %s\n",
40705 pci_name(dev));
40706
40707- atomic_inc(&pci_parity_count);
40708+ atomic_inc_unchecked(&pci_parity_count);
40709 }
40710
40711 if (status & (PCI_STATUS_DETECTED_PARITY)) {
40712@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40713 "Detected Parity Error on %s\n",
40714 pci_name(dev));
40715
40716- atomic_inc(&pci_parity_count);
40717+ atomic_inc_unchecked(&pci_parity_count);
40718 }
40719 }
40720
40721@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40722 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
40723 "Signaled System Error on %s\n",
40724 pci_name(dev));
40725- atomic_inc(&pci_nonparity_count);
40726+ atomic_inc_unchecked(&pci_nonparity_count);
40727 }
40728
40729 if (status & (PCI_STATUS_PARITY)) {
40730@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40731 "Master Data Parity Error on "
40732 "%s\n", pci_name(dev));
40733
40734- atomic_inc(&pci_parity_count);
40735+ atomic_inc_unchecked(&pci_parity_count);
40736 }
40737
40738 if (status & (PCI_STATUS_DETECTED_PARITY)) {
40739@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
40740 "Detected Parity Error on %s\n",
40741 pci_name(dev));
40742
40743- atomic_inc(&pci_parity_count);
40744+ atomic_inc_unchecked(&pci_parity_count);
40745 }
40746 }
40747 }
40748@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
40749 if (!check_pci_errors)
40750 return;
40751
40752- before_count = atomic_read(&pci_parity_count);
40753+ before_count = atomic_read_unchecked(&pci_parity_count);
40754
40755 /* scan all PCI devices looking for a Parity Error on devices and
40756 * bridges.
40757@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
40758 /* Only if operator has selected panic on PCI Error */
40759 if (edac_pci_get_panic_on_pe()) {
40760 /* If the count is different 'after' from 'before' */
40761- if (before_count != atomic_read(&pci_parity_count))
40762+ if (before_count != atomic_read_unchecked(&pci_parity_count))
40763 panic("EDAC: PCI Parity Error");
40764 }
40765 }
40766diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
40767index 51b7e3a..aa8a3e8 100644
40768--- a/drivers/edac/mce_amd.h
40769+++ b/drivers/edac/mce_amd.h
40770@@ -77,7 +77,7 @@ struct amd_decoder_ops {
40771 bool (*mc0_mce)(u16, u8);
40772 bool (*mc1_mce)(u16, u8);
40773 bool (*mc2_mce)(u16, u8);
40774-};
40775+} __no_const;
40776
40777 void amd_report_gart_errors(bool);
40778 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
40779diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
40780index 57ea7f4..af06b76 100644
40781--- a/drivers/firewire/core-card.c
40782+++ b/drivers/firewire/core-card.c
40783@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
40784 const struct fw_card_driver *driver,
40785 struct device *device)
40786 {
40787- static atomic_t index = ATOMIC_INIT(-1);
40788+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
40789
40790- card->index = atomic_inc_return(&index);
40791+ card->index = atomic_inc_return_unchecked(&index);
40792 card->driver = driver;
40793 card->device = device;
40794 card->current_tlabel = 0;
40795@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
40796
40797 void fw_core_remove_card(struct fw_card *card)
40798 {
40799- struct fw_card_driver dummy_driver = dummy_driver_template;
40800+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
40801
40802 card->driver->update_phy_reg(card, 4,
40803 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
40804diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
40805index 5d997a3..2a3973a 100644
40806--- a/drivers/firewire/core-cdev.c
40807+++ b/drivers/firewire/core-cdev.c
40808@@ -1637,8 +1637,7 @@ static int dispatch_ioctl(struct client *client,
40809 _IOC_SIZE(cmd) > sizeof(buffer))
40810 return -ENOTTY;
40811
40812- if (_IOC_DIR(cmd) == _IOC_READ)
40813- memset(&buffer, 0, _IOC_SIZE(cmd));
40814+ memset(&buffer, 0, sizeof(buffer));
40815
40816 if (_IOC_DIR(cmd) & _IOC_WRITE)
40817 if (copy_from_user(&buffer, arg, _IOC_SIZE(cmd)))
40818diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
40819index 2c6d5e1..a2cca6b 100644
40820--- a/drivers/firewire/core-device.c
40821+++ b/drivers/firewire/core-device.c
40822@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
40823 struct config_rom_attribute {
40824 struct device_attribute attr;
40825 u32 key;
40826-};
40827+} __do_const;
40828
40829 static ssize_t show_immediate(struct device *dev,
40830 struct device_attribute *dattr, char *buf)
40831diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
40832index eb6935c..3cc2bfa 100644
40833--- a/drivers/firewire/core-transaction.c
40834+++ b/drivers/firewire/core-transaction.c
40835@@ -38,6 +38,7 @@
40836 #include <linux/timer.h>
40837 #include <linux/types.h>
40838 #include <linux/workqueue.h>
40839+#include <linux/sched.h>
40840
40841 #include <asm/byteorder.h>
40842
40843diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
40844index e1480ff6..1a429bd 100644
40845--- a/drivers/firewire/core.h
40846+++ b/drivers/firewire/core.h
40847@@ -111,6 +111,7 @@ struct fw_card_driver {
40848
40849 int (*stop_iso)(struct fw_iso_context *ctx);
40850 };
40851+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
40852
40853 void fw_card_initialize(struct fw_card *card,
40854 const struct fw_card_driver *driver, struct device *device);
40855diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
40856index a66a321..f6caf20 100644
40857--- a/drivers/firewire/ohci.c
40858+++ b/drivers/firewire/ohci.c
40859@@ -2056,10 +2056,12 @@ static void bus_reset_work(struct work_struct *work)
40860 be32_to_cpu(ohci->next_header));
40861 }
40862
40863+#ifndef CONFIG_GRKERNSEC
40864 if (param_remote_dma) {
40865 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
40866 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
40867 }
40868+#endif
40869
40870 spin_unlock_irq(&ohci->lock);
40871
40872@@ -2591,8 +2593,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
40873 unsigned long flags;
40874 int n, ret = 0;
40875
40876+#ifndef CONFIG_GRKERNSEC
40877 if (param_remote_dma)
40878 return 0;
40879+#endif
40880
40881 /*
40882 * FIXME: Make sure this bitmask is cleared when we clear the busReset
40883diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
40884index 94a58a0..f5eba42 100644
40885--- a/drivers/firmware/dmi-id.c
40886+++ b/drivers/firmware/dmi-id.c
40887@@ -16,7 +16,7 @@
40888 struct dmi_device_attribute{
40889 struct device_attribute dev_attr;
40890 int field;
40891-};
40892+} __do_const;
40893 #define to_dmi_dev_attr(_dev_attr) \
40894 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
40895
40896diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
40897index 17afc51..0ef90cd 100644
40898--- a/drivers/firmware/dmi_scan.c
40899+++ b/drivers/firmware/dmi_scan.c
40900@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
40901 if (buf == NULL)
40902 return -1;
40903
40904- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
40905+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
40906
40907 dmi_unmap(buf);
40908 return 0;
40909diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
40910index 5b53d61..72cee96 100644
40911--- a/drivers/firmware/efi/cper.c
40912+++ b/drivers/firmware/efi/cper.c
40913@@ -44,12 +44,12 @@ static char rcd_decode_str[CPER_REC_LEN];
40914 */
40915 u64 cper_next_record_id(void)
40916 {
40917- static atomic64_t seq;
40918+ static atomic64_unchecked_t seq;
40919
40920- if (!atomic64_read(&seq))
40921- atomic64_set(&seq, ((u64)get_seconds()) << 32);
40922+ if (!atomic64_read_unchecked(&seq))
40923+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
40924
40925- return atomic64_inc_return(&seq);
40926+ return atomic64_inc_return_unchecked(&seq);
40927 }
40928 EXPORT_SYMBOL_GPL(cper_next_record_id);
40929
40930diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
40931index 64ecbb5..d921eb3 100644
40932--- a/drivers/firmware/efi/efi.c
40933+++ b/drivers/firmware/efi/efi.c
40934@@ -126,14 +126,16 @@ static struct attribute_group efi_subsys_attr_group = {
40935 };
40936
40937 static struct efivars generic_efivars;
40938-static struct efivar_operations generic_ops;
40939+static efivar_operations_no_const generic_ops __read_only;
40940
40941 static int generic_ops_register(void)
40942 {
40943- generic_ops.get_variable = efi.get_variable;
40944- generic_ops.set_variable = efi.set_variable;
40945- generic_ops.get_next_variable = efi.get_next_variable;
40946- generic_ops.query_variable_store = efi_query_variable_store;
40947+ pax_open_kernel();
40948+ *(void **)&generic_ops.get_variable = efi.get_variable;
40949+ *(void **)&generic_ops.set_variable = efi.set_variable;
40950+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
40951+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
40952+ pax_close_kernel();
40953
40954 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
40955 }
40956diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
40957index f256ecd..387dcb1 100644
40958--- a/drivers/firmware/efi/efivars.c
40959+++ b/drivers/firmware/efi/efivars.c
40960@@ -589,7 +589,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
40961 static int
40962 create_efivars_bin_attributes(void)
40963 {
40964- struct bin_attribute *attr;
40965+ bin_attribute_no_const *attr;
40966 int error;
40967
40968 /* new_var */
40969diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
40970index 2f569aa..c95f4fb 100644
40971--- a/drivers/firmware/google/memconsole.c
40972+++ b/drivers/firmware/google/memconsole.c
40973@@ -155,7 +155,10 @@ static int __init memconsole_init(void)
40974 if (!found_memconsole())
40975 return -ENODEV;
40976
40977- memconsole_bin_attr.size = memconsole_length;
40978+ pax_open_kernel();
40979+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
40980+ pax_close_kernel();
40981+
40982 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
40983 }
40984
40985diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
40986index fe49ec3..1ade794 100644
40987--- a/drivers/gpio/gpio-em.c
40988+++ b/drivers/gpio/gpio-em.c
40989@@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
40990 struct em_gio_priv *p;
40991 struct resource *io[2], *irq[2];
40992 struct gpio_chip *gpio_chip;
40993- struct irq_chip *irq_chip;
40994+ irq_chip_no_const *irq_chip;
40995 const char *name = dev_name(&pdev->dev);
40996 int ret;
40997
40998diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
40999index 3784e81..73637b5 100644
41000--- a/drivers/gpio/gpio-ich.c
41001+++ b/drivers/gpio/gpio-ich.c
41002@@ -94,7 +94,7 @@ struct ichx_desc {
41003 * this option allows driver caching written output values
41004 */
41005 bool use_outlvl_cache;
41006-};
41007+} __do_const;
41008
41009 static struct {
41010 spinlock_t lock;
41011diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
41012index bf6c094..6573caf 100644
41013--- a/drivers/gpio/gpio-rcar.c
41014+++ b/drivers/gpio/gpio-rcar.c
41015@@ -357,7 +357,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
41016 struct gpio_rcar_priv *p;
41017 struct resource *io, *irq;
41018 struct gpio_chip *gpio_chip;
41019- struct irq_chip *irq_chip;
41020+ irq_chip_no_const *irq_chip;
41021 struct device *dev = &pdev->dev;
41022 const char *name = dev_name(dev);
41023 int ret;
41024diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
41025index dbf28fa..04dad4e 100644
41026--- a/drivers/gpio/gpio-vr41xx.c
41027+++ b/drivers/gpio/gpio-vr41xx.c
41028@@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
41029 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
41030 maskl, pendl, maskh, pendh);
41031
41032- atomic_inc(&irq_err_count);
41033+ atomic_inc_unchecked(&irq_err_count);
41034
41035 return -EINVAL;
41036 }
41037diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
41038index c68d037..2f4f9a9 100644
41039--- a/drivers/gpio/gpiolib.c
41040+++ b/drivers/gpio/gpiolib.c
41041@@ -529,8 +529,10 @@ static void gpiochip_irqchip_remove(struct gpio_chip *gpiochip)
41042 }
41043
41044 if (gpiochip->irqchip) {
41045- gpiochip->irqchip->irq_request_resources = NULL;
41046- gpiochip->irqchip->irq_release_resources = NULL;
41047+ pax_open_kernel();
41048+ *(void **)&gpiochip->irqchip->irq_request_resources = NULL;
41049+ *(void **)&gpiochip->irqchip->irq_release_resources = NULL;
41050+ pax_close_kernel();
41051 gpiochip->irqchip = NULL;
41052 }
41053 }
41054@@ -596,8 +598,11 @@ int gpiochip_irqchip_add(struct gpio_chip *gpiochip,
41055 gpiochip->irqchip = NULL;
41056 return -EINVAL;
41057 }
41058- irqchip->irq_request_resources = gpiochip_irq_reqres;
41059- irqchip->irq_release_resources = gpiochip_irq_relres;
41060+
41061+ pax_open_kernel();
41062+ *(void **)&irqchip->irq_request_resources = gpiochip_irq_reqres;
41063+ *(void **)&irqchip->irq_release_resources = gpiochip_irq_relres;
41064+ pax_close_kernel();
41065
41066 /*
41067 * Prepare the mapping since the irqchip shall be orthogonal to
41068diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
41069index 90e7730..3b41807 100644
41070--- a/drivers/gpu/drm/drm_crtc.c
41071+++ b/drivers/gpu/drm/drm_crtc.c
41072@@ -3861,7 +3861,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
41073 goto done;
41074 }
41075
41076- if (copy_to_user(&enum_ptr[copied].name,
41077+ if (copy_to_user(enum_ptr[copied].name,
41078 &prop_enum->name, DRM_PROP_NAME_LEN)) {
41079 ret = -EFAULT;
41080 goto done;
41081diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
41082index 3242e20..7e4f621 100644
41083--- a/drivers/gpu/drm/drm_drv.c
41084+++ b/drivers/gpu/drm/drm_drv.c
41085@@ -463,7 +463,7 @@ void drm_unplug_dev(struct drm_device *dev)
41086
41087 drm_device_set_unplugged(dev);
41088
41089- if (dev->open_count == 0) {
41090+ if (local_read(&dev->open_count) == 0) {
41091 drm_put_dev(dev);
41092 }
41093 mutex_unlock(&drm_global_mutex);
41094diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
41095index 79d5221..7ff73496 100644
41096--- a/drivers/gpu/drm/drm_fops.c
41097+++ b/drivers/gpu/drm/drm_fops.c
41098@@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
41099 return PTR_ERR(minor);
41100
41101 dev = minor->dev;
41102- if (!dev->open_count++)
41103+ if (local_inc_return(&dev->open_count) == 1)
41104 need_setup = 1;
41105
41106 /* share address_space across all char-devs of a single device */
41107@@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
41108 return 0;
41109
41110 err_undo:
41111- dev->open_count--;
41112+ local_dec(&dev->open_count);
41113 drm_minor_release(minor);
41114 return retcode;
41115 }
41116@@ -384,7 +384,7 @@ int drm_release(struct inode *inode, struct file *filp)
41117
41118 mutex_lock(&drm_global_mutex);
41119
41120- DRM_DEBUG("open_count = %d\n", dev->open_count);
41121+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
41122
41123 mutex_lock(&dev->struct_mutex);
41124 list_del(&file_priv->lhead);
41125@@ -397,10 +397,10 @@ int drm_release(struct inode *inode, struct file *filp)
41126 * Begin inline drm_release
41127 */
41128
41129- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
41130+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
41131 task_pid_nr(current),
41132 (long)old_encode_dev(file_priv->minor->kdev->devt),
41133- dev->open_count);
41134+ local_read(&dev->open_count));
41135
41136 /* Release any auth tokens that might point to this file_priv,
41137 (do that under the drm_global_mutex) */
41138@@ -471,7 +471,7 @@ int drm_release(struct inode *inode, struct file *filp)
41139 * End inline drm_release
41140 */
41141
41142- if (!--dev->open_count) {
41143+ if (local_dec_and_test(&dev->open_count)) {
41144 retcode = drm_lastclose(dev);
41145 if (drm_device_is_unplugged(dev))
41146 drm_put_dev(dev);
41147diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
41148index 3d2e91c..d31c4c9 100644
41149--- a/drivers/gpu/drm/drm_global.c
41150+++ b/drivers/gpu/drm/drm_global.c
41151@@ -36,7 +36,7 @@
41152 struct drm_global_item {
41153 struct mutex mutex;
41154 void *object;
41155- int refcount;
41156+ atomic_t refcount;
41157 };
41158
41159 static struct drm_global_item glob[DRM_GLOBAL_NUM];
41160@@ -49,7 +49,7 @@ void drm_global_init(void)
41161 struct drm_global_item *item = &glob[i];
41162 mutex_init(&item->mutex);
41163 item->object = NULL;
41164- item->refcount = 0;
41165+ atomic_set(&item->refcount, 0);
41166 }
41167 }
41168
41169@@ -59,7 +59,7 @@ void drm_global_release(void)
41170 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
41171 struct drm_global_item *item = &glob[i];
41172 BUG_ON(item->object != NULL);
41173- BUG_ON(item->refcount != 0);
41174+ BUG_ON(atomic_read(&item->refcount) != 0);
41175 }
41176 }
41177
41178@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41179 struct drm_global_item *item = &glob[ref->global_type];
41180
41181 mutex_lock(&item->mutex);
41182- if (item->refcount == 0) {
41183+ if (atomic_read(&item->refcount) == 0) {
41184 item->object = kzalloc(ref->size, GFP_KERNEL);
41185 if (unlikely(item->object == NULL)) {
41186 ret = -ENOMEM;
41187@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
41188 goto out_err;
41189
41190 }
41191- ++item->refcount;
41192+ atomic_inc(&item->refcount);
41193 ref->object = item->object;
41194 mutex_unlock(&item->mutex);
41195 return 0;
41196@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
41197 struct drm_global_item *item = &glob[ref->global_type];
41198
41199 mutex_lock(&item->mutex);
41200- BUG_ON(item->refcount == 0);
41201+ BUG_ON(atomic_read(&item->refcount) == 0);
41202 BUG_ON(ref->object != item->object);
41203- if (--item->refcount == 0) {
41204+ if (atomic_dec_and_test(&item->refcount)) {
41205 ref->release(ref);
41206 item->object = NULL;
41207 }
41208diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
41209index ecaf0fa..a49cee9 100644
41210--- a/drivers/gpu/drm/drm_info.c
41211+++ b/drivers/gpu/drm/drm_info.c
41212@@ -73,10 +73,13 @@ int drm_vm_info(struct seq_file *m, void *data)
41213 struct drm_local_map *map;
41214 struct drm_map_list *r_list;
41215
41216- /* Hardcoded from _DRM_FRAME_BUFFER,
41217- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
41218- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
41219- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
41220+ static const char * const types[] = {
41221+ [_DRM_FRAME_BUFFER] = "FB",
41222+ [_DRM_REGISTERS] = "REG",
41223+ [_DRM_SHM] = "SHM",
41224+ [_DRM_AGP] = "AGP",
41225+ [_DRM_SCATTER_GATHER] = "SG",
41226+ [_DRM_CONSISTENT] = "PCI"};
41227 const char *type;
41228 int i;
41229
41230@@ -87,7 +90,7 @@ int drm_vm_info(struct seq_file *m, void *data)
41231 map = r_list->map;
41232 if (!map)
41233 continue;
41234- if (map->type < 0 || map->type > 5)
41235+ if (map->type >= ARRAY_SIZE(types))
41236 type = "??";
41237 else
41238 type = types[map->type];
41239@@ -259,7 +262,11 @@ int drm_vma_info(struct seq_file *m, void *data)
41240 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
41241 vma->vm_flags & VM_LOCKED ? 'l' : '-',
41242 vma->vm_flags & VM_IO ? 'i' : '-',
41243+#ifdef CONFIG_GRKERNSEC_HIDESYM
41244+ 0);
41245+#else
41246 vma->vm_pgoff);
41247+#endif
41248
41249 #if defined(__i386__)
41250 pgprot = pgprot_val(vma->vm_page_prot);
41251diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
41252index 2f4c4343..dd12cd2 100644
41253--- a/drivers/gpu/drm/drm_ioc32.c
41254+++ b/drivers/gpu/drm/drm_ioc32.c
41255@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
41256 request = compat_alloc_user_space(nbytes);
41257 if (!access_ok(VERIFY_WRITE, request, nbytes))
41258 return -EFAULT;
41259- list = (struct drm_buf_desc *) (request + 1);
41260+ list = (struct drm_buf_desc __user *) (request + 1);
41261
41262 if (__put_user(count, &request->count)
41263 || __put_user(list, &request->list))
41264@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
41265 request = compat_alloc_user_space(nbytes);
41266 if (!access_ok(VERIFY_WRITE, request, nbytes))
41267 return -EFAULT;
41268- list = (struct drm_buf_pub *) (request + 1);
41269+ list = (struct drm_buf_pub __user *) (request + 1);
41270
41271 if (__put_user(count, &request->count)
41272 || __put_user(list, &request->list))
41273@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
41274 return 0;
41275 }
41276
41277-drm_ioctl_compat_t *drm_compat_ioctls[] = {
41278+drm_ioctl_compat_t drm_compat_ioctls[] = {
41279 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
41280 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
41281 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
41282@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
41283 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41284 {
41285 unsigned int nr = DRM_IOCTL_NR(cmd);
41286- drm_ioctl_compat_t *fn;
41287 int ret;
41288
41289 /* Assume that ioctls without an explicit compat routine will just
41290@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41291 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
41292 return drm_ioctl(filp, cmd, arg);
41293
41294- fn = drm_compat_ioctls[nr];
41295-
41296- if (fn != NULL)
41297- ret = (*fn) (filp, cmd, arg);
41298+ if (drm_compat_ioctls[nr] != NULL)
41299+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
41300 else
41301 ret = drm_ioctl(filp, cmd, arg);
41302
41303diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
41304index 40be746..fd78faf 100644
41305--- a/drivers/gpu/drm/drm_ioctl.c
41306+++ b/drivers/gpu/drm/drm_ioctl.c
41307@@ -642,7 +642,7 @@ long drm_ioctl(struct file *filp,
41308 struct drm_file *file_priv = filp->private_data;
41309 struct drm_device *dev;
41310 const struct drm_ioctl_desc *ioctl = NULL;
41311- drm_ioctl_t *func;
41312+ drm_ioctl_no_const_t func;
41313 unsigned int nr = DRM_IOCTL_NR(cmd);
41314 int retcode = -EINVAL;
41315 char stack_kdata[128];
41316diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
41317index d4d16ed..8fb0b51 100644
41318--- a/drivers/gpu/drm/i810/i810_drv.h
41319+++ b/drivers/gpu/drm/i810/i810_drv.h
41320@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
41321 int page_flipping;
41322
41323 wait_queue_head_t irq_queue;
41324- atomic_t irq_received;
41325- atomic_t irq_emitted;
41326+ atomic_unchecked_t irq_received;
41327+ atomic_unchecked_t irq_emitted;
41328
41329 int front_offset;
41330 } drm_i810_private_t;
41331diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
41332index 9933c26..32cc097 100644
41333--- a/drivers/gpu/drm/i915/i915_dma.c
41334+++ b/drivers/gpu/drm/i915/i915_dma.c
41335@@ -1292,7 +1292,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
41336 * locking inversion with the driver load path. And the access here is
41337 * completely racy anyway. So don't bother with locking for now.
41338 */
41339- return dev->open_count == 0;
41340+ return local_read(&dev->open_count) == 0;
41341 }
41342
41343 static const struct vga_switcheroo_client_ops i915_switcheroo_ops = {
41344diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41345index 60998fc..3b244bc 100644
41346--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41347+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
41348@@ -891,9 +891,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
41349
41350 static int
41351 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
41352- int count)
41353+ unsigned int count)
41354 {
41355- int i;
41356+ unsigned int i;
41357 unsigned relocs_total = 0;
41358 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
41359
41360diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
41361index 2e0613e..a8b94d9 100644
41362--- a/drivers/gpu/drm/i915/i915_ioc32.c
41363+++ b/drivers/gpu/drm/i915/i915_ioc32.c
41364@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
41365 (unsigned long)request);
41366 }
41367
41368-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
41369+static drm_ioctl_compat_t i915_compat_ioctls[] = {
41370 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
41371 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
41372 [DRM_I915_GETPARAM] = compat_i915_getparam,
41373@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
41374 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41375 {
41376 unsigned int nr = DRM_IOCTL_NR(cmd);
41377- drm_ioctl_compat_t *fn = NULL;
41378 int ret;
41379
41380 if (nr < DRM_COMMAND_BASE)
41381 return drm_compat_ioctl(filp, cmd, arg);
41382
41383- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls))
41384- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
41385-
41386- if (fn != NULL)
41387+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(i915_compat_ioctls)) {
41388+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
41389 ret = (*fn) (filp, cmd, arg);
41390- else
41391+ } else
41392 ret = drm_ioctl(filp, cmd, arg);
41393
41394 return ret;
41395diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
41396index b71a026..8b6cc10 100644
41397--- a/drivers/gpu/drm/i915/intel_display.c
41398+++ b/drivers/gpu/drm/i915/intel_display.c
41399@@ -12437,13 +12437,13 @@ struct intel_quirk {
41400 int subsystem_vendor;
41401 int subsystem_device;
41402 void (*hook)(struct drm_device *dev);
41403-};
41404+} __do_const;
41405
41406 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
41407 struct intel_dmi_quirk {
41408 void (*hook)(struct drm_device *dev);
41409 const struct dmi_system_id (*dmi_id_list)[];
41410-};
41411+} __do_const;
41412
41413 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
41414 {
41415@@ -12451,18 +12451,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
41416 return 1;
41417 }
41418
41419-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
41420+static const struct dmi_system_id intel_dmi_quirks_table[] = {
41421 {
41422- .dmi_id_list = &(const struct dmi_system_id[]) {
41423- {
41424- .callback = intel_dmi_reverse_brightness,
41425- .ident = "NCR Corporation",
41426- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
41427- DMI_MATCH(DMI_PRODUCT_NAME, ""),
41428- },
41429- },
41430- { } /* terminating entry */
41431+ .callback = intel_dmi_reverse_brightness,
41432+ .ident = "NCR Corporation",
41433+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
41434+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
41435 },
41436+ },
41437+ { } /* terminating entry */
41438+};
41439+
41440+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
41441+ {
41442+ .dmi_id_list = &intel_dmi_quirks_table,
41443 .hook = quirk_invert_brightness,
41444 },
41445 };
41446diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
41447index fe45321..836fdca 100644
41448--- a/drivers/gpu/drm/mga/mga_drv.h
41449+++ b/drivers/gpu/drm/mga/mga_drv.h
41450@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
41451 u32 clear_cmd;
41452 u32 maccess;
41453
41454- atomic_t vbl_received; /**< Number of vblanks received. */
41455+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
41456 wait_queue_head_t fence_queue;
41457- atomic_t last_fence_retired;
41458+ atomic_unchecked_t last_fence_retired;
41459 u32 next_fence_to_post;
41460
41461 unsigned int fb_cpp;
41462diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
41463index 729bfd5..ead8823 100644
41464--- a/drivers/gpu/drm/mga/mga_ioc32.c
41465+++ b/drivers/gpu/drm/mga/mga_ioc32.c
41466@@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
41467 return 0;
41468 }
41469
41470-drm_ioctl_compat_t *mga_compat_ioctls[] = {
41471+drm_ioctl_compat_t mga_compat_ioctls[] = {
41472 [DRM_MGA_INIT] = compat_mga_init,
41473 [DRM_MGA_GETPARAM] = compat_mga_getparam,
41474 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
41475@@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
41476 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41477 {
41478 unsigned int nr = DRM_IOCTL_NR(cmd);
41479- drm_ioctl_compat_t *fn = NULL;
41480 int ret;
41481
41482 if (nr < DRM_COMMAND_BASE)
41483 return drm_compat_ioctl(filp, cmd, arg);
41484
41485- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls))
41486- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
41487-
41488- if (fn != NULL)
41489+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(mga_compat_ioctls)) {
41490+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
41491 ret = (*fn) (filp, cmd, arg);
41492- else
41493+ } else
41494 ret = drm_ioctl(filp, cmd, arg);
41495
41496 return ret;
41497diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
41498index 1b071b8..de8601a 100644
41499--- a/drivers/gpu/drm/mga/mga_irq.c
41500+++ b/drivers/gpu/drm/mga/mga_irq.c
41501@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
41502 if (crtc != 0)
41503 return 0;
41504
41505- return atomic_read(&dev_priv->vbl_received);
41506+ return atomic_read_unchecked(&dev_priv->vbl_received);
41507 }
41508
41509
41510@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
41511 /* VBLANK interrupt */
41512 if (status & MGA_VLINEPEN) {
41513 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
41514- atomic_inc(&dev_priv->vbl_received);
41515+ atomic_inc_unchecked(&dev_priv->vbl_received);
41516 drm_handle_vblank(dev, 0);
41517 handled = 1;
41518 }
41519@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
41520 if ((prim_start & ~0x03) != (prim_end & ~0x03))
41521 MGA_WRITE(MGA_PRIMEND, prim_end);
41522
41523- atomic_inc(&dev_priv->last_fence_retired);
41524+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
41525 wake_up(&dev_priv->fence_queue);
41526 handled = 1;
41527 }
41528@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
41529 * using fences.
41530 */
41531 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
41532- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
41533+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
41534 - *sequence) <= (1 << 23)));
41535
41536 *sequence = cur_fence;
41537diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
41538index dae2c96..324dbe4 100644
41539--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
41540+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
41541@@ -963,7 +963,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
41542 struct bit_table {
41543 const char id;
41544 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
41545-};
41546+} __no_const;
41547
41548 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
41549
41550diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
41551index b02b024..aed7bad 100644
41552--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
41553+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
41554@@ -119,7 +119,6 @@ struct nouveau_drm {
41555 struct drm_global_reference mem_global_ref;
41556 struct ttm_bo_global_ref bo_global_ref;
41557 struct ttm_bo_device bdev;
41558- atomic_t validate_sequence;
41559 int (*move)(struct nouveau_channel *,
41560 struct ttm_buffer_object *,
41561 struct ttm_mem_reg *, struct ttm_mem_reg *);
41562diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41563index 462679a..88e32a7 100644
41564--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41565+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
41566@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
41567 unsigned long arg)
41568 {
41569 unsigned int nr = DRM_IOCTL_NR(cmd);
41570- drm_ioctl_compat_t *fn = NULL;
41571+ drm_ioctl_compat_t fn = NULL;
41572 int ret;
41573
41574 if (nr < DRM_COMMAND_BASE)
41575diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
41576index 53874b7..1db0a68 100644
41577--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
41578+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
41579@@ -127,11 +127,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41580 }
41581
41582 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
41583- nouveau_vram_manager_init,
41584- nouveau_vram_manager_fini,
41585- nouveau_vram_manager_new,
41586- nouveau_vram_manager_del,
41587- nouveau_vram_manager_debug
41588+ .init = nouveau_vram_manager_init,
41589+ .takedown = nouveau_vram_manager_fini,
41590+ .get_node = nouveau_vram_manager_new,
41591+ .put_node = nouveau_vram_manager_del,
41592+ .debug = nouveau_vram_manager_debug
41593 };
41594
41595 static int
41596@@ -196,11 +196,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41597 }
41598
41599 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
41600- nouveau_gart_manager_init,
41601- nouveau_gart_manager_fini,
41602- nouveau_gart_manager_new,
41603- nouveau_gart_manager_del,
41604- nouveau_gart_manager_debug
41605+ .init = nouveau_gart_manager_init,
41606+ .takedown = nouveau_gart_manager_fini,
41607+ .get_node = nouveau_gart_manager_new,
41608+ .put_node = nouveau_gart_manager_del,
41609+ .debug = nouveau_gart_manager_debug
41610 };
41611
41612 /*XXX*/
41613@@ -270,11 +270,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
41614 }
41615
41616 const struct ttm_mem_type_manager_func nv04_gart_manager = {
41617- nv04_gart_manager_init,
41618- nv04_gart_manager_fini,
41619- nv04_gart_manager_new,
41620- nv04_gart_manager_del,
41621- nv04_gart_manager_debug
41622+ .init = nv04_gart_manager_init,
41623+ .takedown = nv04_gart_manager_fini,
41624+ .get_node = nv04_gart_manager_new,
41625+ .put_node = nv04_gart_manager_del,
41626+ .debug = nv04_gart_manager_debug
41627 };
41628
41629 int
41630diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
41631index c7592ec..dd45ebc 100644
41632--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
41633+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
41634@@ -72,7 +72,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
41635 * locking inversion with the driver load path. And the access here is
41636 * completely racy anyway. So don't bother with locking for now.
41637 */
41638- return dev->open_count == 0;
41639+ return local_read(&dev->open_count) == 0;
41640 }
41641
41642 static const struct vga_switcheroo_client_ops
41643diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
41644index eb89653..613cf71 100644
41645--- a/drivers/gpu/drm/qxl/qxl_cmd.c
41646+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
41647@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
41648 int ret;
41649
41650 mutex_lock(&qdev->async_io_mutex);
41651- irq_num = atomic_read(&qdev->irq_received_io_cmd);
41652+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41653 if (qdev->last_sent_io_cmd > irq_num) {
41654 if (intr)
41655 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41656- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41657+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41658 else
41659 ret = wait_event_timeout(qdev->io_cmd_event,
41660- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41661+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41662 /* 0 is timeout, just bail the "hw" has gone away */
41663 if (ret <= 0)
41664 goto out;
41665- irq_num = atomic_read(&qdev->irq_received_io_cmd);
41666+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
41667 }
41668 outb(val, addr);
41669 qdev->last_sent_io_cmd = irq_num + 1;
41670 if (intr)
41671 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
41672- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41673+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41674 else
41675 ret = wait_event_timeout(qdev->io_cmd_event,
41676- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41677+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
41678 out:
41679 if (ret > 0)
41680 ret = 0;
41681diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
41682index c3c2bbd..bc3c0fb 100644
41683--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
41684+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
41685@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
41686 struct drm_info_node *node = (struct drm_info_node *) m->private;
41687 struct qxl_device *qdev = node->minor->dev->dev_private;
41688
41689- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
41690- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
41691- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
41692- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
41693+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
41694+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
41695+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
41696+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
41697 seq_printf(m, "%d\n", qdev->irq_received_error);
41698 return 0;
41699 }
41700diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
41701index 36ed40b..0397633 100644
41702--- a/drivers/gpu/drm/qxl/qxl_drv.h
41703+++ b/drivers/gpu/drm/qxl/qxl_drv.h
41704@@ -290,10 +290,10 @@ struct qxl_device {
41705 unsigned int last_sent_io_cmd;
41706
41707 /* interrupt handling */
41708- atomic_t irq_received;
41709- atomic_t irq_received_display;
41710- atomic_t irq_received_cursor;
41711- atomic_t irq_received_io_cmd;
41712+ atomic_unchecked_t irq_received;
41713+ atomic_unchecked_t irq_received_display;
41714+ atomic_unchecked_t irq_received_cursor;
41715+ atomic_unchecked_t irq_received_io_cmd;
41716 unsigned irq_received_error;
41717 wait_queue_head_t display_event;
41718 wait_queue_head_t cursor_event;
41719diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
41720index b110883..dd06418 100644
41721--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
41722+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
41723@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41724
41725 /* TODO copy slow path code from i915 */
41726 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
41727- 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);
41728+ 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);
41729
41730 {
41731 struct qxl_drawable *draw = fb_cmd;
41732@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
41733 struct drm_qxl_reloc reloc;
41734
41735 if (copy_from_user(&reloc,
41736- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
41737+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
41738 sizeof(reloc))) {
41739 ret = -EFAULT;
41740 goto out_free_bos;
41741@@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
41742
41743 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
41744
41745- struct drm_qxl_command *commands =
41746- (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
41747+ struct drm_qxl_command __user *commands =
41748+ (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
41749
41750- if (copy_from_user(&user_cmd, &commands[cmd_num],
41751+ if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
41752 sizeof(user_cmd)))
41753 return -EFAULT;
41754
41755diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
41756index 0bf1e20..42a7310 100644
41757--- a/drivers/gpu/drm/qxl/qxl_irq.c
41758+++ b/drivers/gpu/drm/qxl/qxl_irq.c
41759@@ -36,19 +36,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
41760 if (!pending)
41761 return IRQ_NONE;
41762
41763- atomic_inc(&qdev->irq_received);
41764+ atomic_inc_unchecked(&qdev->irq_received);
41765
41766 if (pending & QXL_INTERRUPT_DISPLAY) {
41767- atomic_inc(&qdev->irq_received_display);
41768+ atomic_inc_unchecked(&qdev->irq_received_display);
41769 wake_up_all(&qdev->display_event);
41770 qxl_queue_garbage_collect(qdev, false);
41771 }
41772 if (pending & QXL_INTERRUPT_CURSOR) {
41773- atomic_inc(&qdev->irq_received_cursor);
41774+ atomic_inc_unchecked(&qdev->irq_received_cursor);
41775 wake_up_all(&qdev->cursor_event);
41776 }
41777 if (pending & QXL_INTERRUPT_IO_CMD) {
41778- atomic_inc(&qdev->irq_received_io_cmd);
41779+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
41780 wake_up_all(&qdev->io_cmd_event);
41781 }
41782 if (pending & QXL_INTERRUPT_ERROR) {
41783@@ -85,10 +85,10 @@ int qxl_irq_init(struct qxl_device *qdev)
41784 init_waitqueue_head(&qdev->io_cmd_event);
41785 INIT_WORK(&qdev->client_monitors_config_work,
41786 qxl_client_monitors_config_work_func);
41787- atomic_set(&qdev->irq_received, 0);
41788- atomic_set(&qdev->irq_received_display, 0);
41789- atomic_set(&qdev->irq_received_cursor, 0);
41790- atomic_set(&qdev->irq_received_io_cmd, 0);
41791+ atomic_set_unchecked(&qdev->irq_received, 0);
41792+ atomic_set_unchecked(&qdev->irq_received_display, 0);
41793+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
41794+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
41795 qdev->irq_received_error = 0;
41796 ret = drm_irq_install(qdev->ddev, qdev->ddev->pdev->irq);
41797 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
41798diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
41799index 71a1bae..cb1f103 100644
41800--- a/drivers/gpu/drm/qxl/qxl_ttm.c
41801+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
41802@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
41803 }
41804 }
41805
41806-static struct vm_operations_struct qxl_ttm_vm_ops;
41807+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
41808 static const struct vm_operations_struct *ttm_vm_ops;
41809
41810 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41811@@ -145,8 +145,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
41812 return r;
41813 if (unlikely(ttm_vm_ops == NULL)) {
41814 ttm_vm_ops = vma->vm_ops;
41815+ pax_open_kernel();
41816 qxl_ttm_vm_ops = *ttm_vm_ops;
41817 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
41818+ pax_close_kernel();
41819 }
41820 vma->vm_ops = &qxl_ttm_vm_ops;
41821 return 0;
41822@@ -555,25 +557,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
41823 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
41824 {
41825 #if defined(CONFIG_DEBUG_FS)
41826- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
41827- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
41828- unsigned i;
41829+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
41830+ {
41831+ .name = "qxl_mem_mm",
41832+ .show = &qxl_mm_dump_table,
41833+ },
41834+ {
41835+ .name = "qxl_surf_mm",
41836+ .show = &qxl_mm_dump_table,
41837+ }
41838+ };
41839
41840- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
41841- if (i == 0)
41842- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
41843- else
41844- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
41845- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
41846- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
41847- qxl_mem_types_list[i].driver_features = 0;
41848- if (i == 0)
41849- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41850- else
41851- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41852+ pax_open_kernel();
41853+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
41854+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
41855+ pax_close_kernel();
41856
41857- }
41858- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
41859+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
41860 #else
41861 return 0;
41862 #endif
41863diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
41864index 59459fe..be26b31 100644
41865--- a/drivers/gpu/drm/r128/r128_cce.c
41866+++ b/drivers/gpu/drm/r128/r128_cce.c
41867@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
41868
41869 /* GH: Simple idle check.
41870 */
41871- atomic_set(&dev_priv->idle_count, 0);
41872+ atomic_set_unchecked(&dev_priv->idle_count, 0);
41873
41874 /* We don't support anything other than bus-mastering ring mode,
41875 * but the ring can be in either AGP or PCI space for the ring
41876diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
41877index 5bf3f5f..7000661 100644
41878--- a/drivers/gpu/drm/r128/r128_drv.h
41879+++ b/drivers/gpu/drm/r128/r128_drv.h
41880@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
41881 int is_pci;
41882 unsigned long cce_buffers_offset;
41883
41884- atomic_t idle_count;
41885+ atomic_unchecked_t idle_count;
41886
41887 int page_flipping;
41888 int current_page;
41889 u32 crtc_offset;
41890 u32 crtc_offset_cntl;
41891
41892- atomic_t vbl_received;
41893+ atomic_unchecked_t vbl_received;
41894
41895 u32 color_fmt;
41896 unsigned int front_offset;
41897diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
41898index 663f38c..c689495 100644
41899--- a/drivers/gpu/drm/r128/r128_ioc32.c
41900+++ b/drivers/gpu/drm/r128/r128_ioc32.c
41901@@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
41902 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
41903 }
41904
41905-drm_ioctl_compat_t *r128_compat_ioctls[] = {
41906+drm_ioctl_compat_t r128_compat_ioctls[] = {
41907 [DRM_R128_INIT] = compat_r128_init,
41908 [DRM_R128_DEPTH] = compat_r128_depth,
41909 [DRM_R128_STIPPLE] = compat_r128_stipple,
41910@@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
41911 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
41912 {
41913 unsigned int nr = DRM_IOCTL_NR(cmd);
41914- drm_ioctl_compat_t *fn = NULL;
41915 int ret;
41916
41917 if (nr < DRM_COMMAND_BASE)
41918 return drm_compat_ioctl(filp, cmd, arg);
41919
41920- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls))
41921- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41922-
41923- if (fn != NULL)
41924+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(r128_compat_ioctls)) {
41925+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
41926 ret = (*fn) (filp, cmd, arg);
41927- else
41928+ } else
41929 ret = drm_ioctl(filp, cmd, arg);
41930
41931 return ret;
41932diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
41933index c2ae496..30b5993 100644
41934--- a/drivers/gpu/drm/r128/r128_irq.c
41935+++ b/drivers/gpu/drm/r128/r128_irq.c
41936@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
41937 if (crtc != 0)
41938 return 0;
41939
41940- return atomic_read(&dev_priv->vbl_received);
41941+ return atomic_read_unchecked(&dev_priv->vbl_received);
41942 }
41943
41944 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41945@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
41946 /* VBLANK interrupt */
41947 if (status & R128_CRTC_VBLANK_INT) {
41948 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
41949- atomic_inc(&dev_priv->vbl_received);
41950+ atomic_inc_unchecked(&dev_priv->vbl_received);
41951 drm_handle_vblank(dev, 0);
41952 return IRQ_HANDLED;
41953 }
41954diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
41955index 575e986..66e62ca 100644
41956--- a/drivers/gpu/drm/r128/r128_state.c
41957+++ b/drivers/gpu/drm/r128/r128_state.c
41958@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
41959
41960 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
41961 {
41962- if (atomic_read(&dev_priv->idle_count) == 0)
41963+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
41964 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
41965 else
41966- atomic_set(&dev_priv->idle_count, 0);
41967+ atomic_set_unchecked(&dev_priv->idle_count, 0);
41968 }
41969
41970 #endif
41971diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
41972index 4a85bb6..aaea819 100644
41973--- a/drivers/gpu/drm/radeon/mkregtable.c
41974+++ b/drivers/gpu/drm/radeon/mkregtable.c
41975@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
41976 regex_t mask_rex;
41977 regmatch_t match[4];
41978 char buf[1024];
41979- size_t end;
41980+ long end;
41981 int len;
41982 int done = 0;
41983 int r;
41984 unsigned o;
41985 struct offset *offset;
41986 char last_reg_s[10];
41987- int last_reg;
41988+ unsigned long last_reg;
41989
41990 if (regcomp
41991 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
41992diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
41993index 6684fbf..2e11bf0 100644
41994--- a/drivers/gpu/drm/radeon/radeon_device.c
41995+++ b/drivers/gpu/drm/radeon/radeon_device.c
41996@@ -1213,7 +1213,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
41997 * locking inversion with the driver load path. And the access here is
41998 * completely racy anyway. So don't bother with locking for now.
41999 */
42000- return dev->open_count == 0;
42001+ return local_read(&dev->open_count) == 0;
42002 }
42003
42004 static const struct vga_switcheroo_client_ops radeon_switcheroo_ops = {
42005diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
42006index dafd812..1bf20c7 100644
42007--- a/drivers/gpu/drm/radeon/radeon_drv.h
42008+++ b/drivers/gpu/drm/radeon/radeon_drv.h
42009@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
42010
42011 /* SW interrupt */
42012 wait_queue_head_t swi_queue;
42013- atomic_t swi_emitted;
42014+ atomic_unchecked_t swi_emitted;
42015 int vblank_crtc;
42016 uint32_t irq_enable_reg;
42017 uint32_t r500_disp_irq_reg;
42018diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
42019index 0b98ea1..0881827 100644
42020--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
42021+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
42022@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42023 request = compat_alloc_user_space(sizeof(*request));
42024 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
42025 || __put_user(req32.param, &request->param)
42026- || __put_user((void __user *)(unsigned long)req32.value,
42027+ || __put_user((unsigned long)req32.value,
42028 &request->value))
42029 return -EFAULT;
42030
42031@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
42032 #define compat_radeon_cp_setparam NULL
42033 #endif /* X86_64 || IA64 */
42034
42035-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42036+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
42037 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
42038 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
42039 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
42040@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
42041 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
42042 {
42043 unsigned int nr = DRM_IOCTL_NR(cmd);
42044- drm_ioctl_compat_t *fn = NULL;
42045 int ret;
42046
42047 if (nr < DRM_COMMAND_BASE)
42048 return drm_compat_ioctl(filp, cmd, arg);
42049
42050- if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls))
42051- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42052-
42053- if (fn != NULL)
42054+ if (nr < DRM_COMMAND_BASE + ARRAY_SIZE(radeon_compat_ioctls)) {
42055+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
42056 ret = (*fn) (filp, cmd, arg);
42057- else
42058+ } else
42059 ret = drm_ioctl(filp, cmd, arg);
42060
42061 return ret;
42062diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
42063index 244b19b..c19226d 100644
42064--- a/drivers/gpu/drm/radeon/radeon_irq.c
42065+++ b/drivers/gpu/drm/radeon/radeon_irq.c
42066@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
42067 unsigned int ret;
42068 RING_LOCALS;
42069
42070- atomic_inc(&dev_priv->swi_emitted);
42071- ret = atomic_read(&dev_priv->swi_emitted);
42072+ atomic_inc_unchecked(&dev_priv->swi_emitted);
42073+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
42074
42075 BEGIN_RING(4);
42076 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
42077@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
42078 drm_radeon_private_t *dev_priv =
42079 (drm_radeon_private_t *) dev->dev_private;
42080
42081- atomic_set(&dev_priv->swi_emitted, 0);
42082+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
42083 init_waitqueue_head(&dev_priv->swi_queue);
42084
42085 dev->max_vblank_count = 0x001fffff;
42086diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
42087index 23bb64f..69d7234 100644
42088--- a/drivers/gpu/drm/radeon/radeon_state.c
42089+++ b/drivers/gpu/drm/radeon/radeon_state.c
42090@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
42091 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
42092 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
42093
42094- if (copy_from_user(&depth_boxes, clear->depth_boxes,
42095+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
42096 sarea_priv->nbox * sizeof(depth_boxes[0])))
42097 return -EFAULT;
42098
42099@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
42100 {
42101 drm_radeon_private_t *dev_priv = dev->dev_private;
42102 drm_radeon_getparam_t *param = data;
42103- int value;
42104+ int value = 0;
42105
42106 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
42107
42108diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
42109index 72afe82..056a57a 100644
42110--- a/drivers/gpu/drm/radeon/radeon_ttm.c
42111+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
42112@@ -801,7 +801,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
42113 man->size = size >> PAGE_SHIFT;
42114 }
42115
42116-static struct vm_operations_struct radeon_ttm_vm_ops;
42117+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
42118 static const struct vm_operations_struct *ttm_vm_ops = NULL;
42119
42120 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
42121@@ -842,8 +842,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
42122 }
42123 if (unlikely(ttm_vm_ops == NULL)) {
42124 ttm_vm_ops = vma->vm_ops;
42125+ pax_open_kernel();
42126 radeon_ttm_vm_ops = *ttm_vm_ops;
42127 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
42128+ pax_close_kernel();
42129 }
42130 vma->vm_ops = &radeon_ttm_vm_ops;
42131 return 0;
42132diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
42133index 6553fd2..aecd29c 100644
42134--- a/drivers/gpu/drm/tegra/dc.c
42135+++ b/drivers/gpu/drm/tegra/dc.c
42136@@ -1243,7 +1243,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
42137 }
42138
42139 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
42140- dc->debugfs_files[i].data = dc;
42141+ *(void **)&dc->debugfs_files[i].data = dc;
42142
42143 err = drm_debugfs_create_files(dc->debugfs_files,
42144 ARRAY_SIZE(debugfs_files),
42145diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
42146index f787445..2df2c65 100644
42147--- a/drivers/gpu/drm/tegra/dsi.c
42148+++ b/drivers/gpu/drm/tegra/dsi.c
42149@@ -41,7 +41,7 @@ struct tegra_dsi {
42150 struct clk *clk_lp;
42151 struct clk *clk;
42152
42153- struct drm_info_list *debugfs_files;
42154+ drm_info_list_no_const *debugfs_files;
42155 struct drm_minor *minor;
42156 struct dentry *debugfs;
42157
42158diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
42159index ffe2654..03c7b1c 100644
42160--- a/drivers/gpu/drm/tegra/hdmi.c
42161+++ b/drivers/gpu/drm/tegra/hdmi.c
42162@@ -60,7 +60,7 @@ struct tegra_hdmi {
42163 bool stereo;
42164 bool dvi;
42165
42166- struct drm_info_list *debugfs_files;
42167+ drm_info_list_no_const *debugfs_files;
42168 struct drm_minor *minor;
42169 struct dentry *debugfs;
42170 };
42171diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42172index 9e103a48..0e117f3 100644
42173--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
42174+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
42175@@ -147,10 +147,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
42176 }
42177
42178 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
42179- ttm_bo_man_init,
42180- ttm_bo_man_takedown,
42181- ttm_bo_man_get_node,
42182- ttm_bo_man_put_node,
42183- ttm_bo_man_debug
42184+ .init = ttm_bo_man_init,
42185+ .takedown = ttm_bo_man_takedown,
42186+ .get_node = ttm_bo_man_get_node,
42187+ .put_node = ttm_bo_man_put_node,
42188+ .debug = ttm_bo_man_debug
42189 };
42190 EXPORT_SYMBOL(ttm_bo_manager_func);
42191diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
42192index dbc2def..0a9f710 100644
42193--- a/drivers/gpu/drm/ttm/ttm_memory.c
42194+++ b/drivers/gpu/drm/ttm/ttm_memory.c
42195@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
42196 zone->glob = glob;
42197 glob->zone_kernel = zone;
42198 ret = kobject_init_and_add(
42199- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
42200+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
42201 if (unlikely(ret != 0)) {
42202 kobject_put(&zone->kobj);
42203 return ret;
42204@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
42205 zone->glob = glob;
42206 glob->zone_dma32 = zone;
42207 ret = kobject_init_and_add(
42208- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
42209+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
42210 if (unlikely(ret != 0)) {
42211 kobject_put(&zone->kobj);
42212 return ret;
42213diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
42214index d1da339..829235e 100644
42215--- a/drivers/gpu/drm/udl/udl_fb.c
42216+++ b/drivers/gpu/drm/udl/udl_fb.c
42217@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
42218 fb_deferred_io_cleanup(info);
42219 kfree(info->fbdefio);
42220 info->fbdefio = NULL;
42221- info->fbops->fb_mmap = udl_fb_mmap;
42222 }
42223
42224 pr_warn("released /dev/fb%d user=%d count=%d\n",
42225diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
42226index ad02732..144f5ed 100644
42227--- a/drivers/gpu/drm/via/via_drv.h
42228+++ b/drivers/gpu/drm/via/via_drv.h
42229@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
42230 typedef uint32_t maskarray_t[5];
42231
42232 typedef struct drm_via_irq {
42233- atomic_t irq_received;
42234+ atomic_unchecked_t irq_received;
42235 uint32_t pending_mask;
42236 uint32_t enable_mask;
42237 wait_queue_head_t irq_queue;
42238@@ -75,7 +75,7 @@ typedef struct drm_via_private {
42239 struct timeval last_vblank;
42240 int last_vblank_valid;
42241 unsigned usec_per_vblank;
42242- atomic_t vbl_received;
42243+ atomic_unchecked_t vbl_received;
42244 drm_via_state_t hc_state;
42245 char pci_buf[VIA_PCI_BUF_SIZE];
42246 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
42247diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
42248index 1319433..a993b0c 100644
42249--- a/drivers/gpu/drm/via/via_irq.c
42250+++ b/drivers/gpu/drm/via/via_irq.c
42251@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
42252 if (crtc != 0)
42253 return 0;
42254
42255- return atomic_read(&dev_priv->vbl_received);
42256+ return atomic_read_unchecked(&dev_priv->vbl_received);
42257 }
42258
42259 irqreturn_t via_driver_irq_handler(int irq, void *arg)
42260@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42261
42262 status = VIA_READ(VIA_REG_INTERRUPT);
42263 if (status & VIA_IRQ_VBLANK_PENDING) {
42264- atomic_inc(&dev_priv->vbl_received);
42265- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
42266+ atomic_inc_unchecked(&dev_priv->vbl_received);
42267+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
42268 do_gettimeofday(&cur_vblank);
42269 if (dev_priv->last_vblank_valid) {
42270 dev_priv->usec_per_vblank =
42271@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42272 dev_priv->last_vblank = cur_vblank;
42273 dev_priv->last_vblank_valid = 1;
42274 }
42275- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
42276+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
42277 DRM_DEBUG("US per vblank is: %u\n",
42278 dev_priv->usec_per_vblank);
42279 }
42280@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
42281
42282 for (i = 0; i < dev_priv->num_irqs; ++i) {
42283 if (status & cur_irq->pending_mask) {
42284- atomic_inc(&cur_irq->irq_received);
42285+ atomic_inc_unchecked(&cur_irq->irq_received);
42286 wake_up(&cur_irq->irq_queue);
42287 handled = 1;
42288 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
42289@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
42290 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
42291 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
42292 masks[irq][4]));
42293- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
42294+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
42295 } else {
42296 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
42297 (((cur_irq_sequence =
42298- atomic_read(&cur_irq->irq_received)) -
42299+ atomic_read_unchecked(&cur_irq->irq_received)) -
42300 *sequence) <= (1 << 23)));
42301 }
42302 *sequence = cur_irq_sequence;
42303@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
42304 }
42305
42306 for (i = 0; i < dev_priv->num_irqs; ++i) {
42307- atomic_set(&cur_irq->irq_received, 0);
42308+ atomic_set_unchecked(&cur_irq->irq_received, 0);
42309 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
42310 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
42311 init_waitqueue_head(&cur_irq->irq_queue);
42312@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
42313 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
42314 case VIA_IRQ_RELATIVE:
42315 irqwait->request.sequence +=
42316- atomic_read(&cur_irq->irq_received);
42317+ atomic_read_unchecked(&cur_irq->irq_received);
42318 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
42319 case VIA_IRQ_ABSOLUTE:
42320 break;
42321diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42322index 99f7317..33a835b 100644
42323--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42324+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
42325@@ -447,7 +447,7 @@ struct vmw_private {
42326 * Fencing and IRQs.
42327 */
42328
42329- atomic_t marker_seq;
42330+ atomic_unchecked_t marker_seq;
42331 wait_queue_head_t fence_queue;
42332 wait_queue_head_t fifo_queue;
42333 int fence_queue_waiters; /* Protected by hw_mutex */
42334diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42335index 6eae14d..aa311b3 100644
42336--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42337+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
42338@@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
42339 (unsigned int) min,
42340 (unsigned int) fifo->capabilities);
42341
42342- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
42343+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
42344 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
42345 vmw_marker_queue_init(&fifo->marker_queue);
42346 return vmw_fifo_send_fence(dev_priv, &dummy);
42347@@ -373,7 +373,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
42348 if (reserveable)
42349 iowrite32(bytes, fifo_mem +
42350 SVGA_FIFO_RESERVED);
42351- return fifo_mem + (next_cmd >> 2);
42352+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
42353 } else {
42354 need_bounce = true;
42355 }
42356@@ -493,7 +493,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
42357
42358 fm = vmw_fifo_reserve(dev_priv, bytes);
42359 if (unlikely(fm == NULL)) {
42360- *seqno = atomic_read(&dev_priv->marker_seq);
42361+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
42362 ret = -ENOMEM;
42363 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
42364 false, 3*HZ);
42365@@ -501,7 +501,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
42366 }
42367
42368 do {
42369- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
42370+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
42371 } while (*seqno == 0);
42372
42373 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
42374diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42375index 26f8bdd..90a0008 100644
42376--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42377+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
42378@@ -165,9 +165,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
42379 }
42380
42381 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
42382- vmw_gmrid_man_init,
42383- vmw_gmrid_man_takedown,
42384- vmw_gmrid_man_get_node,
42385- vmw_gmrid_man_put_node,
42386- vmw_gmrid_man_debug
42387+ .init = vmw_gmrid_man_init,
42388+ .takedown = vmw_gmrid_man_takedown,
42389+ .get_node = vmw_gmrid_man_get_node,
42390+ .put_node = vmw_gmrid_man_put_node,
42391+ .debug = vmw_gmrid_man_debug
42392 };
42393diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42394index 37881ec..319065d 100644
42395--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42396+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
42397@@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
42398 int ret;
42399
42400 num_clips = arg->num_clips;
42401- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
42402+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
42403
42404 if (unlikely(num_clips == 0))
42405 return 0;
42406@@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
42407 int ret;
42408
42409 num_clips = arg->num_clips;
42410- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
42411+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
42412
42413 if (unlikely(num_clips == 0))
42414 return 0;
42415diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42416index 0c42376..6febe77 100644
42417--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42418+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
42419@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
42420 * emitted. Then the fence is stale and signaled.
42421 */
42422
42423- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
42424+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
42425 > VMW_FENCE_WRAP);
42426
42427 return ret;
42428@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
42429
42430 if (fifo_idle)
42431 down_read(&fifo_state->rwsem);
42432- signal_seq = atomic_read(&dev_priv->marker_seq);
42433+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
42434 ret = 0;
42435
42436 for (;;) {
42437diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42438index efd1ffd..0ae13ca 100644
42439--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42440+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
42441@@ -135,7 +135,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
42442 while (!vmw_lag_lt(queue, us)) {
42443 spin_lock(&queue->lock);
42444 if (list_empty(&queue->head))
42445- seqno = atomic_read(&dev_priv->marker_seq);
42446+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
42447 else {
42448 marker = list_first_entry(&queue->head,
42449 struct vmw_marker, head);
42450diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
42451index 37ac7b5..d52a5c9 100644
42452--- a/drivers/gpu/vga/vga_switcheroo.c
42453+++ b/drivers/gpu/vga/vga_switcheroo.c
42454@@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
42455
42456 /* this version is for the case where the power switch is separate
42457 to the device being powered down. */
42458-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
42459+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
42460 {
42461 /* copy over all the bus versions */
42462 if (dev->bus && dev->bus->pm) {
42463@@ -695,7 +695,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
42464 return ret;
42465 }
42466
42467-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
42468+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
42469 {
42470 /* copy over all the bus versions */
42471 if (dev->bus && dev->bus->pm) {
42472diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
42473index 12b6e67..ddd983c 100644
42474--- a/drivers/hid/hid-core.c
42475+++ b/drivers/hid/hid-core.c
42476@@ -2500,7 +2500,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
42477
42478 int hid_add_device(struct hid_device *hdev)
42479 {
42480- static atomic_t id = ATOMIC_INIT(0);
42481+ static atomic_unchecked_t id = ATOMIC_INIT(0);
42482 int ret;
42483
42484 if (WARN_ON(hdev->status & HID_STAT_ADDED))
42485@@ -2542,7 +2542,7 @@ int hid_add_device(struct hid_device *hdev)
42486 /* XXX hack, any other cleaner solution after the driver core
42487 * is converted to allow more than 20 bytes as the device name? */
42488 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
42489- hdev->vendor, hdev->product, atomic_inc_return(&id));
42490+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
42491
42492 hid_debug_register(hdev, dev_name(&hdev->dev));
42493 ret = device_add(&hdev->dev);
42494diff --git a/drivers/hid/hid-logitech-dj.c b/drivers/hid/hid-logitech-dj.c
42495index 9bf8637..f462416 100644
42496--- a/drivers/hid/hid-logitech-dj.c
42497+++ b/drivers/hid/hid-logitech-dj.c
42498@@ -682,6 +682,12 @@ static int logi_dj_raw_event(struct hid_device *hdev,
42499 * device (via hid_input_report() ) and return 1 so hid-core does not do
42500 * anything else with it.
42501 */
42502+ if ((dj_report->device_index < DJ_DEVICE_INDEX_MIN) ||
42503+ (dj_report->device_index > DJ_DEVICE_INDEX_MAX)) {
42504+ dev_err(&hdev->dev, "%s: invalid device index:%d\n",
42505+ __func__, dj_report->device_index);
42506+ return false;
42507+ }
42508
42509 /* case 1) */
42510 if (data[0] != REPORT_ID_DJ_SHORT)
42511diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
42512index c13fb5b..55a3802 100644
42513--- a/drivers/hid/hid-wiimote-debug.c
42514+++ b/drivers/hid/hid-wiimote-debug.c
42515@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
42516 else if (size == 0)
42517 return -EIO;
42518
42519- if (copy_to_user(u, buf, size))
42520+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
42521 return -EFAULT;
42522
42523 *off += size;
42524diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
42525index 0cb92e3..c7d453d 100644
42526--- a/drivers/hid/uhid.c
42527+++ b/drivers/hid/uhid.c
42528@@ -47,7 +47,7 @@ struct uhid_device {
42529 struct mutex report_lock;
42530 wait_queue_head_t report_wait;
42531 atomic_t report_done;
42532- atomic_t report_id;
42533+ atomic_unchecked_t report_id;
42534 struct uhid_event report_buf;
42535 };
42536
42537@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
42538
42539 spin_lock_irqsave(&uhid->qlock, flags);
42540 ev->type = UHID_FEATURE;
42541- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
42542+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
42543 ev->u.feature.rnum = rnum;
42544 ev->u.feature.rtype = report_type;
42545
42546@@ -538,7 +538,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
42547 spin_lock_irqsave(&uhid->qlock, flags);
42548
42549 /* id for old report; drop it silently */
42550- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
42551+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
42552 goto unlock;
42553 if (atomic_read(&uhid->report_done))
42554 goto unlock;
42555diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
42556index 19bad59..ca24eaf 100644
42557--- a/drivers/hv/channel.c
42558+++ b/drivers/hv/channel.c
42559@@ -366,8 +366,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
42560 unsigned long flags;
42561 int ret = 0;
42562
42563- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
42564- atomic_inc(&vmbus_connection.next_gpadl_handle);
42565+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
42566+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
42567
42568 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
42569 if (ret)
42570diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
42571index 3e4235c..877d0e5 100644
42572--- a/drivers/hv/hv.c
42573+++ b/drivers/hv/hv.c
42574@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
42575 u64 output_address = (output) ? virt_to_phys(output) : 0;
42576 u32 output_address_hi = output_address >> 32;
42577 u32 output_address_lo = output_address & 0xFFFFFFFF;
42578- void *hypercall_page = hv_context.hypercall_page;
42579+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
42580
42581 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
42582 "=a"(hv_status_lo) : "d" (control_hi),
42583@@ -156,7 +156,7 @@ int hv_init(void)
42584 /* See if the hypercall page is already set */
42585 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
42586
42587- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
42588+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
42589
42590 if (!virtaddr)
42591 goto cleanup;
42592diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
42593index 5e90c5d..d8fcefb 100644
42594--- a/drivers/hv/hv_balloon.c
42595+++ b/drivers/hv/hv_balloon.c
42596@@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
42597
42598 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
42599 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
42600-static atomic_t trans_id = ATOMIC_INIT(0);
42601+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
42602
42603 static int dm_ring_size = (5 * PAGE_SIZE);
42604
42605@@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
42606 pr_info("Memory hot add failed\n");
42607
42608 dm->state = DM_INITIALIZED;
42609- resp.hdr.trans_id = atomic_inc_return(&trans_id);
42610+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42611 vmbus_sendpacket(dm->dev->channel, &resp,
42612 sizeof(struct dm_hot_add_response),
42613 (unsigned long)NULL,
42614@@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
42615 memset(&status, 0, sizeof(struct dm_status));
42616 status.hdr.type = DM_STATUS_REPORT;
42617 status.hdr.size = sizeof(struct dm_status);
42618- status.hdr.trans_id = atomic_inc_return(&trans_id);
42619+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42620
42621 /*
42622 * The host expects the guest to report free memory.
42623@@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
42624 * send the status. This can happen if we were interrupted
42625 * after we picked our transaction ID.
42626 */
42627- if (status.hdr.trans_id != atomic_read(&trans_id))
42628+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
42629 return;
42630
42631 /*
42632@@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
42633 */
42634
42635 do {
42636- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
42637+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42638 ret = vmbus_sendpacket(dm_device.dev->channel,
42639 bl_resp,
42640 bl_resp->hdr.size,
42641@@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
42642
42643 memset(&resp, 0, sizeof(struct dm_unballoon_response));
42644 resp.hdr.type = DM_UNBALLOON_RESPONSE;
42645- resp.hdr.trans_id = atomic_inc_return(&trans_id);
42646+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42647 resp.hdr.size = sizeof(struct dm_unballoon_response);
42648
42649 vmbus_sendpacket(dm_device.dev->channel, &resp,
42650@@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
42651 memset(&version_req, 0, sizeof(struct dm_version_request));
42652 version_req.hdr.type = DM_VERSION_REQUEST;
42653 version_req.hdr.size = sizeof(struct dm_version_request);
42654- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42655+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42656 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
42657 version_req.is_last_attempt = 1;
42658
42659@@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
42660 memset(&version_req, 0, sizeof(struct dm_version_request));
42661 version_req.hdr.type = DM_VERSION_REQUEST;
42662 version_req.hdr.size = sizeof(struct dm_version_request);
42663- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
42664+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42665 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
42666 version_req.is_last_attempt = 0;
42667
42668@@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
42669 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
42670 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
42671 cap_msg.hdr.size = sizeof(struct dm_capabilities);
42672- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
42673+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
42674
42675 cap_msg.caps.cap_bits.balloon = 1;
42676 cap_msg.caps.cap_bits.hot_add = 1;
42677diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
42678index c386d8d..d6004c4 100644
42679--- a/drivers/hv/hyperv_vmbus.h
42680+++ b/drivers/hv/hyperv_vmbus.h
42681@@ -611,7 +611,7 @@ enum vmbus_connect_state {
42682 struct vmbus_connection {
42683 enum vmbus_connect_state conn_state;
42684
42685- atomic_t next_gpadl_handle;
42686+ atomic_unchecked_t next_gpadl_handle;
42687
42688 /*
42689 * Represents channel interrupts. Each bit position represents a
42690diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
42691index 4d6b269..2e23b86 100644
42692--- a/drivers/hv/vmbus_drv.c
42693+++ b/drivers/hv/vmbus_drv.c
42694@@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
42695 {
42696 int ret = 0;
42697
42698- static atomic_t device_num = ATOMIC_INIT(0);
42699+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
42700
42701 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
42702- atomic_inc_return(&device_num));
42703+ atomic_inc_return_unchecked(&device_num));
42704
42705 child_device_obj->device.bus = &hv_bus;
42706 child_device_obj->device.parent = &hv_acpi_dev->dev;
42707diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
42708index 579bdf9..75118b5 100644
42709--- a/drivers/hwmon/acpi_power_meter.c
42710+++ b/drivers/hwmon/acpi_power_meter.c
42711@@ -116,7 +116,7 @@ struct sensor_template {
42712 struct device_attribute *devattr,
42713 const char *buf, size_t count);
42714 int index;
42715-};
42716+} __do_const;
42717
42718 /* Averaging interval */
42719 static int update_avg_interval(struct acpi_power_meter_resource *resource)
42720@@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
42721 struct sensor_template *attrs)
42722 {
42723 struct device *dev = &resource->acpi_dev->dev;
42724- struct sensor_device_attribute *sensors =
42725+ sensor_device_attribute_no_const *sensors =
42726 &resource->sensors[resource->num_sensors];
42727 int res = 0;
42728
42729diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
42730index 3288f13..71cfb4e 100644
42731--- a/drivers/hwmon/applesmc.c
42732+++ b/drivers/hwmon/applesmc.c
42733@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
42734 {
42735 struct applesmc_node_group *grp;
42736 struct applesmc_dev_attr *node;
42737- struct attribute *attr;
42738+ attribute_no_const *attr;
42739 int ret, i;
42740
42741 for (grp = groups; grp->format; grp++) {
42742diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
42743index cccef87..06ce8ec 100644
42744--- a/drivers/hwmon/asus_atk0110.c
42745+++ b/drivers/hwmon/asus_atk0110.c
42746@@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
42747 struct atk_sensor_data {
42748 struct list_head list;
42749 struct atk_data *data;
42750- struct device_attribute label_attr;
42751- struct device_attribute input_attr;
42752- struct device_attribute limit1_attr;
42753- struct device_attribute limit2_attr;
42754+ device_attribute_no_const label_attr;
42755+ device_attribute_no_const input_attr;
42756+ device_attribute_no_const limit1_attr;
42757+ device_attribute_no_const limit2_attr;
42758 char label_attr_name[ATTR_NAME_SIZE];
42759 char input_attr_name[ATTR_NAME_SIZE];
42760 char limit1_attr_name[ATTR_NAME_SIZE];
42761@@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
42762 static struct device_attribute atk_name_attr =
42763 __ATTR(name, 0444, atk_name_show, NULL);
42764
42765-static void atk_init_attribute(struct device_attribute *attr, char *name,
42766+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
42767 sysfs_show_func show)
42768 {
42769 sysfs_attr_init(&attr->attr);
42770diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
42771index d76f0b7..55ae976 100644
42772--- a/drivers/hwmon/coretemp.c
42773+++ b/drivers/hwmon/coretemp.c
42774@@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
42775 return NOTIFY_OK;
42776 }
42777
42778-static struct notifier_block coretemp_cpu_notifier __refdata = {
42779+static struct notifier_block coretemp_cpu_notifier = {
42780 .notifier_call = coretemp_cpu_callback,
42781 };
42782
42783diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
42784index 7a8a6fb..015c1fd 100644
42785--- a/drivers/hwmon/ibmaem.c
42786+++ b/drivers/hwmon/ibmaem.c
42787@@ -924,7 +924,7 @@ static int aem_register_sensors(struct aem_data *data,
42788 struct aem_rw_sensor_template *rw)
42789 {
42790 struct device *dev = &data->pdev->dev;
42791- struct sensor_device_attribute *sensors = data->sensors;
42792+ sensor_device_attribute_no_const *sensors = data->sensors;
42793 int err;
42794
42795 /* Set up read-only sensors */
42796diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
42797index 14c82da..09b25d7 100644
42798--- a/drivers/hwmon/iio_hwmon.c
42799+++ b/drivers/hwmon/iio_hwmon.c
42800@@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42801 {
42802 struct device *dev = &pdev->dev;
42803 struct iio_hwmon_state *st;
42804- struct sensor_device_attribute *a;
42805+ sensor_device_attribute_no_const *a;
42806 int ret, i;
42807 int in_i = 1, temp_i = 1, curr_i = 1;
42808 enum iio_chan_type type;
42809diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
42810index 7710f46..427a28d 100644
42811--- a/drivers/hwmon/nct6683.c
42812+++ b/drivers/hwmon/nct6683.c
42813@@ -397,11 +397,11 @@ static struct attribute_group *
42814 nct6683_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42815 int repeat)
42816 {
42817- struct sensor_device_attribute_2 *a2;
42818- struct sensor_device_attribute *a;
42819+ sensor_device_attribute_2_no_const *a2;
42820+ sensor_device_attribute_no_const *a;
42821 struct sensor_device_template **t;
42822 struct sensor_device_attr_u *su;
42823- struct attribute_group *group;
42824+ attribute_group_no_const *group;
42825 struct attribute **attrs;
42826 int i, j, count;
42827
42828diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
42829index 504cbdd..35d6f25 100644
42830--- a/drivers/hwmon/nct6775.c
42831+++ b/drivers/hwmon/nct6775.c
42832@@ -943,10 +943,10 @@ static struct attribute_group *
42833 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
42834 int repeat)
42835 {
42836- struct attribute_group *group;
42837+ attribute_group_no_const *group;
42838 struct sensor_device_attr_u *su;
42839- struct sensor_device_attribute *a;
42840- struct sensor_device_attribute_2 *a2;
42841+ sensor_device_attribute_no_const *a;
42842+ sensor_device_attribute_2_no_const *a2;
42843 struct attribute **attrs;
42844 struct sensor_device_template **t;
42845 int i, count;
42846diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
42847index 291d11f..3f0dbbd 100644
42848--- a/drivers/hwmon/pmbus/pmbus_core.c
42849+++ b/drivers/hwmon/pmbus/pmbus_core.c
42850@@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
42851 return 0;
42852 }
42853
42854-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42855+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
42856 const char *name,
42857 umode_t mode,
42858 ssize_t (*show)(struct device *dev,
42859@@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
42860 dev_attr->store = store;
42861 }
42862
42863-static void pmbus_attr_init(struct sensor_device_attribute *a,
42864+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
42865 const char *name,
42866 umode_t mode,
42867 ssize_t (*show)(struct device *dev,
42868@@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
42869 u16 reg, u8 mask)
42870 {
42871 struct pmbus_boolean *boolean;
42872- struct sensor_device_attribute *a;
42873+ sensor_device_attribute_no_const *a;
42874
42875 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
42876 if (!boolean)
42877@@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
42878 bool update, bool readonly)
42879 {
42880 struct pmbus_sensor *sensor;
42881- struct device_attribute *a;
42882+ device_attribute_no_const *a;
42883
42884 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
42885 if (!sensor)
42886@@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
42887 const char *lstring, int index)
42888 {
42889 struct pmbus_label *label;
42890- struct device_attribute *a;
42891+ device_attribute_no_const *a;
42892
42893 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
42894 if (!label)
42895diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
42896index 97cd45a..ac54d8b 100644
42897--- a/drivers/hwmon/sht15.c
42898+++ b/drivers/hwmon/sht15.c
42899@@ -169,7 +169,7 @@ struct sht15_data {
42900 int supply_uv;
42901 bool supply_uv_valid;
42902 struct work_struct update_supply_work;
42903- atomic_t interrupt_handled;
42904+ atomic_unchecked_t interrupt_handled;
42905 };
42906
42907 /**
42908@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
42909 ret = gpio_direction_input(data->pdata->gpio_data);
42910 if (ret)
42911 return ret;
42912- atomic_set(&data->interrupt_handled, 0);
42913+ atomic_set_unchecked(&data->interrupt_handled, 0);
42914
42915 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42916 if (gpio_get_value(data->pdata->gpio_data) == 0) {
42917 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
42918 /* Only relevant if the interrupt hasn't occurred. */
42919- if (!atomic_read(&data->interrupt_handled))
42920+ if (!atomic_read_unchecked(&data->interrupt_handled))
42921 schedule_work(&data->read_work);
42922 }
42923 ret = wait_event_timeout(data->wait_queue,
42924@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
42925
42926 /* First disable the interrupt */
42927 disable_irq_nosync(irq);
42928- atomic_inc(&data->interrupt_handled);
42929+ atomic_inc_unchecked(&data->interrupt_handled);
42930 /* Then schedule a reading work struct */
42931 if (data->state != SHT15_READING_NOTHING)
42932 schedule_work(&data->read_work);
42933@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
42934 * If not, then start the interrupt again - care here as could
42935 * have gone low in meantime so verify it hasn't!
42936 */
42937- atomic_set(&data->interrupt_handled, 0);
42938+ atomic_set_unchecked(&data->interrupt_handled, 0);
42939 enable_irq(gpio_to_irq(data->pdata->gpio_data));
42940 /* If still not occurred or another handler was scheduled */
42941 if (gpio_get_value(data->pdata->gpio_data)
42942- || atomic_read(&data->interrupt_handled))
42943+ || atomic_read_unchecked(&data->interrupt_handled))
42944 return;
42945 }
42946
42947diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
42948index 8df43c5..b07b91d 100644
42949--- a/drivers/hwmon/via-cputemp.c
42950+++ b/drivers/hwmon/via-cputemp.c
42951@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
42952 return NOTIFY_OK;
42953 }
42954
42955-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
42956+static struct notifier_block via_cputemp_cpu_notifier = {
42957 .notifier_call = via_cputemp_cpu_callback,
42958 };
42959
42960diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
42961index 41fc683..a39cfea 100644
42962--- a/drivers/i2c/busses/i2c-amd756-s4882.c
42963+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
42964@@ -43,7 +43,7 @@
42965 extern struct i2c_adapter amd756_smbus;
42966
42967 static struct i2c_adapter *s4882_adapter;
42968-static struct i2c_algorithm *s4882_algo;
42969+static i2c_algorithm_no_const *s4882_algo;
42970
42971 /* Wrapper access functions for multiplexed SMBus */
42972 static DEFINE_MUTEX(amd756_lock);
42973diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
42974index b19a310..d6eece0 100644
42975--- a/drivers/i2c/busses/i2c-diolan-u2c.c
42976+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
42977@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
42978 /* usb layer */
42979
42980 /* Send command to device, and get response. */
42981-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42982+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
42983 {
42984 int ret = 0;
42985 int actual;
42986diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
42987index b170bdf..3c76427 100644
42988--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
42989+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
42990@@ -41,7 +41,7 @@
42991 extern struct i2c_adapter *nforce2_smbus;
42992
42993 static struct i2c_adapter *s4985_adapter;
42994-static struct i2c_algorithm *s4985_algo;
42995+static i2c_algorithm_no_const *s4985_algo;
42996
42997 /* Wrapper access functions for multiplexed SMBus */
42998 static DEFINE_MUTEX(nforce2_lock);
42999diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
43000index 80b47e8..1a6040d9 100644
43001--- a/drivers/i2c/i2c-dev.c
43002+++ b/drivers/i2c/i2c-dev.c
43003@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
43004 break;
43005 }
43006
43007- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
43008+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
43009 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
43010 if (IS_ERR(rdwr_pa[i].buf)) {
43011 res = PTR_ERR(rdwr_pa[i].buf);
43012diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
43013index 0b510ba..4fbb5085 100644
43014--- a/drivers/ide/ide-cd.c
43015+++ b/drivers/ide/ide-cd.c
43016@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
43017 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
43018 if ((unsigned long)buf & alignment
43019 || blk_rq_bytes(rq) & q->dma_pad_mask
43020- || object_is_on_stack(buf))
43021+ || object_starts_on_stack(buf))
43022 drive->dma = 0;
43023 }
43024 }
43025diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
43026index af3e76d..96dfe5e 100644
43027--- a/drivers/iio/industrialio-core.c
43028+++ b/drivers/iio/industrialio-core.c
43029@@ -555,7 +555,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
43030 }
43031
43032 static
43033-int __iio_device_attr_init(struct device_attribute *dev_attr,
43034+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
43035 const char *postfix,
43036 struct iio_chan_spec const *chan,
43037 ssize_t (*readfunc)(struct device *dev,
43038diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
43039index e28a494..f7c2671 100644
43040--- a/drivers/infiniband/core/cm.c
43041+++ b/drivers/infiniband/core/cm.c
43042@@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
43043
43044 struct cm_counter_group {
43045 struct kobject obj;
43046- atomic_long_t counter[CM_ATTR_COUNT];
43047+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
43048 };
43049
43050 struct cm_counter_attribute {
43051@@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
43052 struct ib_mad_send_buf *msg = NULL;
43053 int ret;
43054
43055- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43056+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43057 counter[CM_REQ_COUNTER]);
43058
43059 /* Quick state check to discard duplicate REQs. */
43060@@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
43061 if (!cm_id_priv)
43062 return;
43063
43064- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43065+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43066 counter[CM_REP_COUNTER]);
43067 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
43068 if (ret)
43069@@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
43070 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
43071 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
43072 spin_unlock_irq(&cm_id_priv->lock);
43073- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43074+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43075 counter[CM_RTU_COUNTER]);
43076 goto out;
43077 }
43078@@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
43079 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
43080 dreq_msg->local_comm_id);
43081 if (!cm_id_priv) {
43082- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43083+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43084 counter[CM_DREQ_COUNTER]);
43085 cm_issue_drep(work->port, work->mad_recv_wc);
43086 return -EINVAL;
43087@@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
43088 case IB_CM_MRA_REP_RCVD:
43089 break;
43090 case IB_CM_TIMEWAIT:
43091- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43092+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43093 counter[CM_DREQ_COUNTER]);
43094 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
43095 goto unlock;
43096@@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
43097 cm_free_msg(msg);
43098 goto deref;
43099 case IB_CM_DREQ_RCVD:
43100- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43101+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43102 counter[CM_DREQ_COUNTER]);
43103 goto unlock;
43104 default:
43105@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
43106 ib_modify_mad(cm_id_priv->av.port->mad_agent,
43107 cm_id_priv->msg, timeout)) {
43108 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
43109- atomic_long_inc(&work->port->
43110+ atomic_long_inc_unchecked(&work->port->
43111 counter_group[CM_RECV_DUPLICATES].
43112 counter[CM_MRA_COUNTER]);
43113 goto out;
43114@@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
43115 break;
43116 case IB_CM_MRA_REQ_RCVD:
43117 case IB_CM_MRA_REP_RCVD:
43118- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43119+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43120 counter[CM_MRA_COUNTER]);
43121 /* fall through */
43122 default:
43123@@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
43124 case IB_CM_LAP_IDLE:
43125 break;
43126 case IB_CM_MRA_LAP_SENT:
43127- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43128+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43129 counter[CM_LAP_COUNTER]);
43130 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
43131 goto unlock;
43132@@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
43133 cm_free_msg(msg);
43134 goto deref;
43135 case IB_CM_LAP_RCVD:
43136- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43137+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43138 counter[CM_LAP_COUNTER]);
43139 goto unlock;
43140 default:
43141@@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
43142 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
43143 if (cur_cm_id_priv) {
43144 spin_unlock_irq(&cm.lock);
43145- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
43146+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
43147 counter[CM_SIDR_REQ_COUNTER]);
43148 goto out; /* Duplicate message. */
43149 }
43150@@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
43151 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
43152 msg->retries = 1;
43153
43154- atomic_long_add(1 + msg->retries,
43155+ atomic_long_add_unchecked(1 + msg->retries,
43156 &port->counter_group[CM_XMIT].counter[attr_index]);
43157 if (msg->retries)
43158- atomic_long_add(msg->retries,
43159+ atomic_long_add_unchecked(msg->retries,
43160 &port->counter_group[CM_XMIT_RETRIES].
43161 counter[attr_index]);
43162
43163@@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
43164 }
43165
43166 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
43167- atomic_long_inc(&port->counter_group[CM_RECV].
43168+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
43169 counter[attr_id - CM_ATTR_ID_OFFSET]);
43170
43171 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
43172@@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
43173 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
43174
43175 return sprintf(buf, "%ld\n",
43176- atomic_long_read(&group->counter[cm_attr->index]));
43177+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
43178 }
43179
43180 static const struct sysfs_ops cm_counter_ops = {
43181diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
43182index 9f5ad7c..588cd84 100644
43183--- a/drivers/infiniband/core/fmr_pool.c
43184+++ b/drivers/infiniband/core/fmr_pool.c
43185@@ -98,8 +98,8 @@ struct ib_fmr_pool {
43186
43187 struct task_struct *thread;
43188
43189- atomic_t req_ser;
43190- atomic_t flush_ser;
43191+ atomic_unchecked_t req_ser;
43192+ atomic_unchecked_t flush_ser;
43193
43194 wait_queue_head_t force_wait;
43195 };
43196@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
43197 struct ib_fmr_pool *pool = pool_ptr;
43198
43199 do {
43200- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
43201+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
43202 ib_fmr_batch_release(pool);
43203
43204- atomic_inc(&pool->flush_ser);
43205+ atomic_inc_unchecked(&pool->flush_ser);
43206 wake_up_interruptible(&pool->force_wait);
43207
43208 if (pool->flush_function)
43209@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
43210 }
43211
43212 set_current_state(TASK_INTERRUPTIBLE);
43213- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
43214+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
43215 !kthread_should_stop())
43216 schedule();
43217 __set_current_state(TASK_RUNNING);
43218@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
43219 pool->dirty_watermark = params->dirty_watermark;
43220 pool->dirty_len = 0;
43221 spin_lock_init(&pool->pool_lock);
43222- atomic_set(&pool->req_ser, 0);
43223- atomic_set(&pool->flush_ser, 0);
43224+ atomic_set_unchecked(&pool->req_ser, 0);
43225+ atomic_set_unchecked(&pool->flush_ser, 0);
43226 init_waitqueue_head(&pool->force_wait);
43227
43228 pool->thread = kthread_run(ib_fmr_cleanup_thread,
43229@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
43230 }
43231 spin_unlock_irq(&pool->pool_lock);
43232
43233- serial = atomic_inc_return(&pool->req_ser);
43234+ serial = atomic_inc_return_unchecked(&pool->req_ser);
43235 wake_up_process(pool->thread);
43236
43237 if (wait_event_interruptible(pool->force_wait,
43238- atomic_read(&pool->flush_ser) - serial >= 0))
43239+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
43240 return -EINTR;
43241
43242 return 0;
43243@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
43244 } else {
43245 list_add_tail(&fmr->list, &pool->dirty_list);
43246 if (++pool->dirty_len >= pool->dirty_watermark) {
43247- atomic_inc(&pool->req_ser);
43248+ atomic_inc_unchecked(&pool->req_ser);
43249 wake_up_process(pool->thread);
43250 }
43251 }
43252diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
43253index ec7a298..8742e59 100644
43254--- a/drivers/infiniband/hw/cxgb4/mem.c
43255+++ b/drivers/infiniband/hw/cxgb4/mem.c
43256@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
43257 int err;
43258 struct fw_ri_tpte tpt;
43259 u32 stag_idx;
43260- static atomic_t key;
43261+ static atomic_unchecked_t key;
43262
43263 if (c4iw_fatal_error(rdev))
43264 return -EIO;
43265@@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
43266 if (rdev->stats.stag.cur > rdev->stats.stag.max)
43267 rdev->stats.stag.max = rdev->stats.stag.cur;
43268 mutex_unlock(&rdev->stats.lock);
43269- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
43270+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
43271 }
43272 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
43273 __func__, stag_state, type, pdid, stag_idx);
43274diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
43275index 79b3dbc..96e5fcc 100644
43276--- a/drivers/infiniband/hw/ipath/ipath_rc.c
43277+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
43278@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
43279 struct ib_atomic_eth *ateth;
43280 struct ipath_ack_entry *e;
43281 u64 vaddr;
43282- atomic64_t *maddr;
43283+ atomic64_unchecked_t *maddr;
43284 u64 sdata;
43285 u32 rkey;
43286 u8 next;
43287@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
43288 IB_ACCESS_REMOTE_ATOMIC)))
43289 goto nack_acc_unlck;
43290 /* Perform atomic OP and save result. */
43291- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
43292+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
43293 sdata = be64_to_cpu(ateth->swap_data);
43294 e = &qp->s_ack_queue[qp->r_head_ack_queue];
43295 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
43296- (u64) atomic64_add_return(sdata, maddr) - sdata :
43297+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
43298 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
43299 be64_to_cpu(ateth->compare_data),
43300 sdata);
43301diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
43302index 1f95bba..9530f87 100644
43303--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
43304+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
43305@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
43306 unsigned long flags;
43307 struct ib_wc wc;
43308 u64 sdata;
43309- atomic64_t *maddr;
43310+ atomic64_unchecked_t *maddr;
43311 enum ib_wc_status send_status;
43312
43313 /*
43314@@ -382,11 +382,11 @@ again:
43315 IB_ACCESS_REMOTE_ATOMIC)))
43316 goto acc_err;
43317 /* Perform atomic OP and save result. */
43318- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
43319+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
43320 sdata = wqe->wr.wr.atomic.compare_add;
43321 *(u64 *) sqp->s_sge.sge.vaddr =
43322 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
43323- (u64) atomic64_add_return(sdata, maddr) - sdata :
43324+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
43325 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
43326 sdata, wqe->wr.wr.atomic.swap);
43327 goto send_comp;
43328diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
43329index 82a7dd8..8fb6ba6 100644
43330--- a/drivers/infiniband/hw/mlx4/mad.c
43331+++ b/drivers/infiniband/hw/mlx4/mad.c
43332@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
43333
43334 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
43335 {
43336- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
43337+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
43338 cpu_to_be64(0xff00000000000000LL);
43339 }
43340
43341diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
43342index ed327e6..ca1739e0 100644
43343--- a/drivers/infiniband/hw/mlx4/mcg.c
43344+++ b/drivers/infiniband/hw/mlx4/mcg.c
43345@@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
43346 {
43347 char name[20];
43348
43349- atomic_set(&ctx->tid, 0);
43350+ atomic_set_unchecked(&ctx->tid, 0);
43351 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
43352 ctx->mcg_wq = create_singlethread_workqueue(name);
43353 if (!ctx->mcg_wq)
43354diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
43355index 6eb743f..a7b0f6d 100644
43356--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
43357+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
43358@@ -426,7 +426,7 @@ struct mlx4_ib_demux_ctx {
43359 struct list_head mcg_mgid0_list;
43360 struct workqueue_struct *mcg_wq;
43361 struct mlx4_ib_demux_pv_ctx **tun;
43362- atomic_t tid;
43363+ atomic_unchecked_t tid;
43364 int flushing; /* flushing the work queue */
43365 };
43366
43367diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
43368index 9d3e5c1..6f166df 100644
43369--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
43370+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
43371@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
43372 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
43373 }
43374
43375-int mthca_QUERY_FW(struct mthca_dev *dev)
43376+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
43377 {
43378 struct mthca_mailbox *mailbox;
43379 u32 *outbox;
43380@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43381 CMD_TIME_CLASS_B);
43382 }
43383
43384-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43385+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43386 int num_mtt)
43387 {
43388 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
43389@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
43390 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
43391 }
43392
43393-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43394+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
43395 int eq_num)
43396 {
43397 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
43398@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
43399 CMD_TIME_CLASS_B);
43400 }
43401
43402-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43403+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
43404 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
43405 void *in_mad, void *response_mad)
43406 {
43407diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
43408index ded76c1..0cf0a08 100644
43409--- a/drivers/infiniband/hw/mthca/mthca_main.c
43410+++ b/drivers/infiniband/hw/mthca/mthca_main.c
43411@@ -692,7 +692,7 @@ err_close:
43412 return err;
43413 }
43414
43415-static int mthca_setup_hca(struct mthca_dev *dev)
43416+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
43417 {
43418 int err;
43419
43420diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
43421index ed9a989..6aa5dc2 100644
43422--- a/drivers/infiniband/hw/mthca/mthca_mr.c
43423+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
43424@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
43425 * through the bitmaps)
43426 */
43427
43428-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43429+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
43430 {
43431 int o;
43432 int m;
43433@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
43434 return key;
43435 }
43436
43437-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43438+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
43439 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
43440 {
43441 struct mthca_mailbox *mailbox;
43442@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
43443 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
43444 }
43445
43446-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43447+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
43448 u64 *buffer_list, int buffer_size_shift,
43449 int list_len, u64 iova, u64 total_size,
43450 u32 access, struct mthca_mr *mr)
43451diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
43452index 415f8e1..e34214e 100644
43453--- a/drivers/infiniband/hw/mthca/mthca_provider.c
43454+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
43455@@ -764,7 +764,7 @@ unlock:
43456 return 0;
43457 }
43458
43459-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43460+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
43461 {
43462 struct mthca_dev *dev = to_mdev(ibcq->device);
43463 struct mthca_cq *cq = to_mcq(ibcq);
43464diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
43465index 3b2a6dc..bce26ff 100644
43466--- a/drivers/infiniband/hw/nes/nes.c
43467+++ b/drivers/infiniband/hw/nes/nes.c
43468@@ -97,7 +97,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
43469 LIST_HEAD(nes_adapter_list);
43470 static LIST_HEAD(nes_dev_list);
43471
43472-atomic_t qps_destroyed;
43473+atomic_unchecked_t qps_destroyed;
43474
43475 static unsigned int ee_flsh_adapter;
43476 static unsigned int sysfs_nonidx_addr;
43477@@ -278,7 +278,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
43478 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
43479 struct nes_adapter *nesadapter = nesdev->nesadapter;
43480
43481- atomic_inc(&qps_destroyed);
43482+ atomic_inc_unchecked(&qps_destroyed);
43483
43484 /* Free the control structures */
43485
43486diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
43487index bd9d132..70d84f4 100644
43488--- a/drivers/infiniband/hw/nes/nes.h
43489+++ b/drivers/infiniband/hw/nes/nes.h
43490@@ -180,17 +180,17 @@ extern unsigned int nes_debug_level;
43491 extern unsigned int wqm_quanta;
43492 extern struct list_head nes_adapter_list;
43493
43494-extern atomic_t cm_connects;
43495-extern atomic_t cm_accepts;
43496-extern atomic_t cm_disconnects;
43497-extern atomic_t cm_closes;
43498-extern atomic_t cm_connecteds;
43499-extern atomic_t cm_connect_reqs;
43500-extern atomic_t cm_rejects;
43501-extern atomic_t mod_qp_timouts;
43502-extern atomic_t qps_created;
43503-extern atomic_t qps_destroyed;
43504-extern atomic_t sw_qps_destroyed;
43505+extern atomic_unchecked_t cm_connects;
43506+extern atomic_unchecked_t cm_accepts;
43507+extern atomic_unchecked_t cm_disconnects;
43508+extern atomic_unchecked_t cm_closes;
43509+extern atomic_unchecked_t cm_connecteds;
43510+extern atomic_unchecked_t cm_connect_reqs;
43511+extern atomic_unchecked_t cm_rejects;
43512+extern atomic_unchecked_t mod_qp_timouts;
43513+extern atomic_unchecked_t qps_created;
43514+extern atomic_unchecked_t qps_destroyed;
43515+extern atomic_unchecked_t sw_qps_destroyed;
43516 extern u32 mh_detected;
43517 extern u32 mh_pauses_sent;
43518 extern u32 cm_packets_sent;
43519@@ -199,16 +199,16 @@ extern u32 cm_packets_created;
43520 extern u32 cm_packets_received;
43521 extern u32 cm_packets_dropped;
43522 extern u32 cm_packets_retrans;
43523-extern atomic_t cm_listens_created;
43524-extern atomic_t cm_listens_destroyed;
43525+extern atomic_unchecked_t cm_listens_created;
43526+extern atomic_unchecked_t cm_listens_destroyed;
43527 extern u32 cm_backlog_drops;
43528-extern atomic_t cm_loopbacks;
43529-extern atomic_t cm_nodes_created;
43530-extern atomic_t cm_nodes_destroyed;
43531-extern atomic_t cm_accel_dropped_pkts;
43532-extern atomic_t cm_resets_recvd;
43533-extern atomic_t pau_qps_created;
43534-extern atomic_t pau_qps_destroyed;
43535+extern atomic_unchecked_t cm_loopbacks;
43536+extern atomic_unchecked_t cm_nodes_created;
43537+extern atomic_unchecked_t cm_nodes_destroyed;
43538+extern atomic_unchecked_t cm_accel_dropped_pkts;
43539+extern atomic_unchecked_t cm_resets_recvd;
43540+extern atomic_unchecked_t pau_qps_created;
43541+extern atomic_unchecked_t pau_qps_destroyed;
43542
43543 extern u32 int_mod_timer_init;
43544 extern u32 int_mod_cq_depth_256;
43545diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
43546index 6f09a72..cf4399d 100644
43547--- a/drivers/infiniband/hw/nes/nes_cm.c
43548+++ b/drivers/infiniband/hw/nes/nes_cm.c
43549@@ -69,14 +69,14 @@ u32 cm_packets_dropped;
43550 u32 cm_packets_retrans;
43551 u32 cm_packets_created;
43552 u32 cm_packets_received;
43553-atomic_t cm_listens_created;
43554-atomic_t cm_listens_destroyed;
43555+atomic_unchecked_t cm_listens_created;
43556+atomic_unchecked_t cm_listens_destroyed;
43557 u32 cm_backlog_drops;
43558-atomic_t cm_loopbacks;
43559-atomic_t cm_nodes_created;
43560-atomic_t cm_nodes_destroyed;
43561-atomic_t cm_accel_dropped_pkts;
43562-atomic_t cm_resets_recvd;
43563+atomic_unchecked_t cm_loopbacks;
43564+atomic_unchecked_t cm_nodes_created;
43565+atomic_unchecked_t cm_nodes_destroyed;
43566+atomic_unchecked_t cm_accel_dropped_pkts;
43567+atomic_unchecked_t cm_resets_recvd;
43568
43569 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
43570 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
43571@@ -135,28 +135,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
43572 /* instance of function pointers for client API */
43573 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
43574 static struct nes_cm_ops nes_cm_api = {
43575- mini_cm_accelerated,
43576- mini_cm_listen,
43577- mini_cm_del_listen,
43578- mini_cm_connect,
43579- mini_cm_close,
43580- mini_cm_accept,
43581- mini_cm_reject,
43582- mini_cm_recv_pkt,
43583- mini_cm_dealloc_core,
43584- mini_cm_get,
43585- mini_cm_set
43586+ .accelerated = mini_cm_accelerated,
43587+ .listen = mini_cm_listen,
43588+ .stop_listener = mini_cm_del_listen,
43589+ .connect = mini_cm_connect,
43590+ .close = mini_cm_close,
43591+ .accept = mini_cm_accept,
43592+ .reject = mini_cm_reject,
43593+ .recv_pkt = mini_cm_recv_pkt,
43594+ .destroy_cm_core = mini_cm_dealloc_core,
43595+ .get = mini_cm_get,
43596+ .set = mini_cm_set
43597 };
43598
43599 static struct nes_cm_core *g_cm_core;
43600
43601-atomic_t cm_connects;
43602-atomic_t cm_accepts;
43603-atomic_t cm_disconnects;
43604-atomic_t cm_closes;
43605-atomic_t cm_connecteds;
43606-atomic_t cm_connect_reqs;
43607-atomic_t cm_rejects;
43608+atomic_unchecked_t cm_connects;
43609+atomic_unchecked_t cm_accepts;
43610+atomic_unchecked_t cm_disconnects;
43611+atomic_unchecked_t cm_closes;
43612+atomic_unchecked_t cm_connecteds;
43613+atomic_unchecked_t cm_connect_reqs;
43614+atomic_unchecked_t cm_rejects;
43615
43616 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
43617 {
43618@@ -1436,7 +1436,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
43619 kfree(listener);
43620 listener = NULL;
43621 ret = 0;
43622- atomic_inc(&cm_listens_destroyed);
43623+ atomic_inc_unchecked(&cm_listens_destroyed);
43624 } else {
43625 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
43626 }
43627@@ -1637,7 +1637,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
43628 cm_node->rem_mac);
43629
43630 add_hte_node(cm_core, cm_node);
43631- atomic_inc(&cm_nodes_created);
43632+ atomic_inc_unchecked(&cm_nodes_created);
43633
43634 return cm_node;
43635 }
43636@@ -1698,7 +1698,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
43637 }
43638
43639 atomic_dec(&cm_core->node_cnt);
43640- atomic_inc(&cm_nodes_destroyed);
43641+ atomic_inc_unchecked(&cm_nodes_destroyed);
43642 nesqp = cm_node->nesqp;
43643 if (nesqp) {
43644 nesqp->cm_node = NULL;
43645@@ -1762,7 +1762,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
43646
43647 static void drop_packet(struct sk_buff *skb)
43648 {
43649- atomic_inc(&cm_accel_dropped_pkts);
43650+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
43651 dev_kfree_skb_any(skb);
43652 }
43653
43654@@ -1825,7 +1825,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
43655 {
43656
43657 int reset = 0; /* whether to send reset in case of err.. */
43658- atomic_inc(&cm_resets_recvd);
43659+ atomic_inc_unchecked(&cm_resets_recvd);
43660 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
43661 " refcnt=%d\n", cm_node, cm_node->state,
43662 atomic_read(&cm_node->ref_count));
43663@@ -2492,7 +2492,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
43664 rem_ref_cm_node(cm_node->cm_core, cm_node);
43665 return NULL;
43666 }
43667- atomic_inc(&cm_loopbacks);
43668+ atomic_inc_unchecked(&cm_loopbacks);
43669 loopbackremotenode->loopbackpartner = cm_node;
43670 loopbackremotenode->tcp_cntxt.rcv_wscale =
43671 NES_CM_DEFAULT_RCV_WND_SCALE;
43672@@ -2773,7 +2773,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
43673 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
43674 else {
43675 rem_ref_cm_node(cm_core, cm_node);
43676- atomic_inc(&cm_accel_dropped_pkts);
43677+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
43678 dev_kfree_skb_any(skb);
43679 }
43680 break;
43681@@ -3081,7 +3081,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43682
43683 if ((cm_id) && (cm_id->event_handler)) {
43684 if (issue_disconn) {
43685- atomic_inc(&cm_disconnects);
43686+ atomic_inc_unchecked(&cm_disconnects);
43687 cm_event.event = IW_CM_EVENT_DISCONNECT;
43688 cm_event.status = disconn_status;
43689 cm_event.local_addr = cm_id->local_addr;
43690@@ -3103,7 +3103,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
43691 }
43692
43693 if (issue_close) {
43694- atomic_inc(&cm_closes);
43695+ atomic_inc_unchecked(&cm_closes);
43696 nes_disconnect(nesqp, 1);
43697
43698 cm_id->provider_data = nesqp;
43699@@ -3241,7 +3241,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43700
43701 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
43702 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
43703- atomic_inc(&cm_accepts);
43704+ atomic_inc_unchecked(&cm_accepts);
43705
43706 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
43707 netdev_refcnt_read(nesvnic->netdev));
43708@@ -3439,7 +3439,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
43709 struct nes_cm_core *cm_core;
43710 u8 *start_buff;
43711
43712- atomic_inc(&cm_rejects);
43713+ atomic_inc_unchecked(&cm_rejects);
43714 cm_node = (struct nes_cm_node *)cm_id->provider_data;
43715 loopback = cm_node->loopbackpartner;
43716 cm_core = cm_node->cm_core;
43717@@ -3504,7 +3504,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
43718 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
43719 ntohs(laddr->sin_port));
43720
43721- atomic_inc(&cm_connects);
43722+ atomic_inc_unchecked(&cm_connects);
43723 nesqp->active_conn = 1;
43724
43725 /* cache the cm_id in the qp */
43726@@ -3649,7 +3649,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
43727 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
43728 return err;
43729 }
43730- atomic_inc(&cm_listens_created);
43731+ atomic_inc_unchecked(&cm_listens_created);
43732 }
43733
43734 cm_id->add_ref(cm_id);
43735@@ -3756,7 +3756,7 @@ static void cm_event_connected(struct nes_cm_event *event)
43736
43737 if (nesqp->destroyed)
43738 return;
43739- atomic_inc(&cm_connecteds);
43740+ atomic_inc_unchecked(&cm_connecteds);
43741 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
43742 " local port 0x%04X. jiffies = %lu.\n",
43743 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
43744@@ -3941,7 +3941,7 @@ static void cm_event_reset(struct nes_cm_event *event)
43745
43746 cm_id->add_ref(cm_id);
43747 ret = cm_id->event_handler(cm_id, &cm_event);
43748- atomic_inc(&cm_closes);
43749+ atomic_inc_unchecked(&cm_closes);
43750 cm_event.event = IW_CM_EVENT_CLOSE;
43751 cm_event.status = 0;
43752 cm_event.provider_data = cm_id->provider_data;
43753@@ -3981,7 +3981,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
43754 return;
43755 cm_id = cm_node->cm_id;
43756
43757- atomic_inc(&cm_connect_reqs);
43758+ atomic_inc_unchecked(&cm_connect_reqs);
43759 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43760 cm_node, cm_id, jiffies);
43761
43762@@ -4030,7 +4030,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
43763 return;
43764 cm_id = cm_node->cm_id;
43765
43766- atomic_inc(&cm_connect_reqs);
43767+ atomic_inc_unchecked(&cm_connect_reqs);
43768 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
43769 cm_node, cm_id, jiffies);
43770
43771diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
43772index 4166452..fc952c3 100644
43773--- a/drivers/infiniband/hw/nes/nes_mgt.c
43774+++ b/drivers/infiniband/hw/nes/nes_mgt.c
43775@@ -40,8 +40,8 @@
43776 #include "nes.h"
43777 #include "nes_mgt.h"
43778
43779-atomic_t pau_qps_created;
43780-atomic_t pau_qps_destroyed;
43781+atomic_unchecked_t pau_qps_created;
43782+atomic_unchecked_t pau_qps_destroyed;
43783
43784 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
43785 {
43786@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
43787 {
43788 struct sk_buff *skb;
43789 unsigned long flags;
43790- atomic_inc(&pau_qps_destroyed);
43791+ atomic_inc_unchecked(&pau_qps_destroyed);
43792
43793 /* Free packets that have not yet been forwarded */
43794 /* Lock is acquired by skb_dequeue when removing the skb */
43795@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
43796 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
43797 skb_queue_head_init(&nesqp->pau_list);
43798 spin_lock_init(&nesqp->pau_lock);
43799- atomic_inc(&pau_qps_created);
43800+ atomic_inc_unchecked(&pau_qps_created);
43801 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
43802 }
43803
43804diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
43805index 49eb511..a774366 100644
43806--- a/drivers/infiniband/hw/nes/nes_nic.c
43807+++ b/drivers/infiniband/hw/nes/nes_nic.c
43808@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
43809 target_stat_values[++index] = mh_detected;
43810 target_stat_values[++index] = mh_pauses_sent;
43811 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
43812- target_stat_values[++index] = atomic_read(&cm_connects);
43813- target_stat_values[++index] = atomic_read(&cm_accepts);
43814- target_stat_values[++index] = atomic_read(&cm_disconnects);
43815- target_stat_values[++index] = atomic_read(&cm_connecteds);
43816- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
43817- target_stat_values[++index] = atomic_read(&cm_rejects);
43818- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
43819- target_stat_values[++index] = atomic_read(&qps_created);
43820- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
43821- target_stat_values[++index] = atomic_read(&qps_destroyed);
43822- target_stat_values[++index] = atomic_read(&cm_closes);
43823+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
43824+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
43825+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
43826+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
43827+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
43828+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
43829+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
43830+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
43831+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
43832+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
43833+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
43834 target_stat_values[++index] = cm_packets_sent;
43835 target_stat_values[++index] = cm_packets_bounced;
43836 target_stat_values[++index] = cm_packets_created;
43837 target_stat_values[++index] = cm_packets_received;
43838 target_stat_values[++index] = cm_packets_dropped;
43839 target_stat_values[++index] = cm_packets_retrans;
43840- target_stat_values[++index] = atomic_read(&cm_listens_created);
43841- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
43842+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
43843+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
43844 target_stat_values[++index] = cm_backlog_drops;
43845- target_stat_values[++index] = atomic_read(&cm_loopbacks);
43846- target_stat_values[++index] = atomic_read(&cm_nodes_created);
43847- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
43848- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
43849- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
43850+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
43851+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
43852+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
43853+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
43854+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
43855 target_stat_values[++index] = nesadapter->free_4kpbl;
43856 target_stat_values[++index] = nesadapter->free_256pbl;
43857 target_stat_values[++index] = int_mod_timer_init;
43858 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
43859 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
43860 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
43861- target_stat_values[++index] = atomic_read(&pau_qps_created);
43862- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
43863+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
43864+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
43865 }
43866
43867 /**
43868diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
43869index fef067c..6a25ccd 100644
43870--- a/drivers/infiniband/hw/nes/nes_verbs.c
43871+++ b/drivers/infiniband/hw/nes/nes_verbs.c
43872@@ -46,9 +46,9 @@
43873
43874 #include <rdma/ib_umem.h>
43875
43876-atomic_t mod_qp_timouts;
43877-atomic_t qps_created;
43878-atomic_t sw_qps_destroyed;
43879+atomic_unchecked_t mod_qp_timouts;
43880+atomic_unchecked_t qps_created;
43881+atomic_unchecked_t sw_qps_destroyed;
43882
43883 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
43884
43885@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
43886 if (init_attr->create_flags)
43887 return ERR_PTR(-EINVAL);
43888
43889- atomic_inc(&qps_created);
43890+ atomic_inc_unchecked(&qps_created);
43891 switch (init_attr->qp_type) {
43892 case IB_QPT_RC:
43893 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
43894@@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
43895 struct iw_cm_event cm_event;
43896 int ret = 0;
43897
43898- atomic_inc(&sw_qps_destroyed);
43899+ atomic_inc_unchecked(&sw_qps_destroyed);
43900 nesqp->destroyed = 1;
43901
43902 /* Blow away the connection if it exists. */
43903diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
43904index c00ae09..04e91be 100644
43905--- a/drivers/infiniband/hw/qib/qib.h
43906+++ b/drivers/infiniband/hw/qib/qib.h
43907@@ -52,6 +52,7 @@
43908 #include <linux/kref.h>
43909 #include <linux/sched.h>
43910 #include <linux/kthread.h>
43911+#include <linux/slab.h>
43912
43913 #include "qib_common.h"
43914 #include "qib_verbs.h"
43915diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
43916index 24c41ba..102d71f 100644
43917--- a/drivers/input/gameport/gameport.c
43918+++ b/drivers/input/gameport/gameport.c
43919@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
43920 */
43921 static void gameport_init_port(struct gameport *gameport)
43922 {
43923- static atomic_t gameport_no = ATOMIC_INIT(0);
43924+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
43925
43926 __module_get(THIS_MODULE);
43927
43928 mutex_init(&gameport->drv_mutex);
43929 device_initialize(&gameport->dev);
43930 dev_set_name(&gameport->dev, "gameport%lu",
43931- (unsigned long)atomic_inc_return(&gameport_no) - 1);
43932+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
43933 gameport->dev.bus = &gameport_bus;
43934 gameport->dev.release = gameport_release_port;
43935 if (gameport->parent)
43936diff --git a/drivers/input/input.c b/drivers/input/input.c
43937index 29ca0bb..f4bc2e3 100644
43938--- a/drivers/input/input.c
43939+++ b/drivers/input/input.c
43940@@ -1774,7 +1774,7 @@ EXPORT_SYMBOL_GPL(input_class);
43941 */
43942 struct input_dev *input_allocate_device(void)
43943 {
43944- static atomic_t input_no = ATOMIC_INIT(0);
43945+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
43946 struct input_dev *dev;
43947
43948 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
43949@@ -1789,7 +1789,7 @@ struct input_dev *input_allocate_device(void)
43950 INIT_LIST_HEAD(&dev->node);
43951
43952 dev_set_name(&dev->dev, "input%ld",
43953- (unsigned long) atomic_inc_return(&input_no) - 1);
43954+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
43955
43956 __module_get(THIS_MODULE);
43957 }
43958diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
43959index 4a95b22..874c182 100644
43960--- a/drivers/input/joystick/sidewinder.c
43961+++ b/drivers/input/joystick/sidewinder.c
43962@@ -30,6 +30,7 @@
43963 #include <linux/kernel.h>
43964 #include <linux/module.h>
43965 #include <linux/slab.h>
43966+#include <linux/sched.h>
43967 #include <linux/input.h>
43968 #include <linux/gameport.h>
43969 #include <linux/jiffies.h>
43970diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
43971index 177602c..ec78499 100644
43972--- a/drivers/input/joystick/xpad.c
43973+++ b/drivers/input/joystick/xpad.c
43974@@ -850,7 +850,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
43975
43976 static int xpad_led_probe(struct usb_xpad *xpad)
43977 {
43978- static atomic_t led_seq = ATOMIC_INIT(0);
43979+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
43980 long led_no;
43981 struct xpad_led *led;
43982 struct led_classdev *led_cdev;
43983@@ -863,7 +863,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
43984 if (!led)
43985 return -ENOMEM;
43986
43987- led_no = (long)atomic_inc_return(&led_seq) - 1;
43988+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
43989
43990 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
43991 led->xpad = xpad;
43992diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
43993index 719410f..1896169 100644
43994--- a/drivers/input/misc/ims-pcu.c
43995+++ b/drivers/input/misc/ims-pcu.c
43996@@ -1851,7 +1851,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
43997
43998 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
43999 {
44000- static atomic_t device_no = ATOMIC_INIT(0);
44001+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
44002
44003 const struct ims_pcu_device_info *info;
44004 int error;
44005@@ -1882,7 +1882,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
44006 }
44007
44008 /* Device appears to be operable, complete initialization */
44009- pcu->device_no = atomic_inc_return(&device_no) - 1;
44010+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
44011
44012 /*
44013 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
44014diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
44015index 2f0b39d..7370f13 100644
44016--- a/drivers/input/mouse/psmouse.h
44017+++ b/drivers/input/mouse/psmouse.h
44018@@ -116,7 +116,7 @@ struct psmouse_attribute {
44019 ssize_t (*set)(struct psmouse *psmouse, void *data,
44020 const char *buf, size_t count);
44021 bool protect;
44022-};
44023+} __do_const;
44024 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
44025
44026 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
44027diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
44028index b604564..3f14ae4 100644
44029--- a/drivers/input/mousedev.c
44030+++ b/drivers/input/mousedev.c
44031@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
44032
44033 spin_unlock_irq(&client->packet_lock);
44034
44035- if (copy_to_user(buffer, data, count))
44036+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
44037 return -EFAULT;
44038
44039 return count;
44040diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
44041index b29134d..394deb0 100644
44042--- a/drivers/input/serio/serio.c
44043+++ b/drivers/input/serio/serio.c
44044@@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
44045 */
44046 static void serio_init_port(struct serio *serio)
44047 {
44048- static atomic_t serio_no = ATOMIC_INIT(0);
44049+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
44050
44051 __module_get(THIS_MODULE);
44052
44053@@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
44054 mutex_init(&serio->drv_mutex);
44055 device_initialize(&serio->dev);
44056 dev_set_name(&serio->dev, "serio%ld",
44057- (long)atomic_inc_return(&serio_no) - 1);
44058+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
44059 serio->dev.bus = &serio_bus;
44060 serio->dev.release = serio_release_port;
44061 serio->dev.groups = serio_device_attr_groups;
44062diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
44063index c9a02fe..0debc75 100644
44064--- a/drivers/input/serio/serio_raw.c
44065+++ b/drivers/input/serio/serio_raw.c
44066@@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
44067
44068 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
44069 {
44070- static atomic_t serio_raw_no = ATOMIC_INIT(0);
44071+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
44072 struct serio_raw *serio_raw;
44073 int err;
44074
44075@@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
44076 }
44077
44078 snprintf(serio_raw->name, sizeof(serio_raw->name),
44079- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
44080+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
44081 kref_init(&serio_raw->kref);
44082 INIT_LIST_HEAD(&serio_raw->client_list);
44083 init_waitqueue_head(&serio_raw->wait);
44084diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
44085index a83cc2a..64462e6 100644
44086--- a/drivers/iommu/arm-smmu.c
44087+++ b/drivers/iommu/arm-smmu.c
44088@@ -921,7 +921,7 @@ static int arm_smmu_init_domain_context(struct iommu_domain *domain,
44089 cfg->irptndx = cfg->cbndx;
44090 }
44091
44092- ACCESS_ONCE(smmu_domain->smmu) = smmu;
44093+ ACCESS_ONCE_RW(smmu_domain->smmu) = smmu;
44094 arm_smmu_init_context_bank(smmu_domain);
44095 spin_unlock_irqrestore(&smmu_domain->lock, flags);
44096
44097diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
44098index 33c4395..e06447e 100644
44099--- a/drivers/iommu/irq_remapping.c
44100+++ b/drivers/iommu/irq_remapping.c
44101@@ -354,7 +354,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
44102 void panic_if_irq_remap(const char *msg)
44103 {
44104 if (irq_remapping_enabled)
44105- panic(msg);
44106+ panic("%s", msg);
44107 }
44108
44109 static void ir_ack_apic_edge(struct irq_data *data)
44110@@ -375,10 +375,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
44111
44112 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
44113 {
44114- chip->irq_print_chip = ir_print_prefix;
44115- chip->irq_ack = ir_ack_apic_edge;
44116- chip->irq_eoi = ir_ack_apic_level;
44117- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
44118+ pax_open_kernel();
44119+ *(void **)&chip->irq_print_chip = ir_print_prefix;
44120+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
44121+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
44122+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
44123+ pax_close_kernel();
44124 }
44125
44126 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
44127diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
44128index dda6dbc..f9adebb 100644
44129--- a/drivers/irqchip/irq-gic.c
44130+++ b/drivers/irqchip/irq-gic.c
44131@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
44132 * Supported arch specific GIC irq extension.
44133 * Default make them NULL.
44134 */
44135-struct irq_chip gic_arch_extn = {
44136+irq_chip_no_const gic_arch_extn = {
44137 .irq_eoi = NULL,
44138 .irq_mask = NULL,
44139 .irq_unmask = NULL,
44140@@ -312,7 +312,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
44141 chained_irq_exit(chip, desc);
44142 }
44143
44144-static struct irq_chip gic_chip = {
44145+static irq_chip_no_const gic_chip __read_only = {
44146 .name = "GIC",
44147 .irq_mask = gic_mask_irq,
44148 .irq_unmask = gic_unmask_irq,
44149diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
44150index 8777065..a4a9967 100644
44151--- a/drivers/irqchip/irq-renesas-irqc.c
44152+++ b/drivers/irqchip/irq-renesas-irqc.c
44153@@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
44154 struct irqc_priv *p;
44155 struct resource *io;
44156 struct resource *irq;
44157- struct irq_chip *irq_chip;
44158+ irq_chip_no_const *irq_chip;
44159 const char *name = dev_name(&pdev->dev);
44160 int ret;
44161 int k;
44162diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
44163index 6a2df32..dc962f1 100644
44164--- a/drivers/isdn/capi/capi.c
44165+++ b/drivers/isdn/capi/capi.c
44166@@ -81,8 +81,8 @@ struct capiminor {
44167
44168 struct capi20_appl *ap;
44169 u32 ncci;
44170- atomic_t datahandle;
44171- atomic_t msgid;
44172+ atomic_unchecked_t datahandle;
44173+ atomic_unchecked_t msgid;
44174
44175 struct tty_port port;
44176 int ttyinstop;
44177@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
44178 capimsg_setu16(s, 2, mp->ap->applid);
44179 capimsg_setu8 (s, 4, CAPI_DATA_B3);
44180 capimsg_setu8 (s, 5, CAPI_RESP);
44181- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
44182+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
44183 capimsg_setu32(s, 8, mp->ncci);
44184 capimsg_setu16(s, 12, datahandle);
44185 }
44186@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
44187 mp->outbytes -= len;
44188 spin_unlock_bh(&mp->outlock);
44189
44190- datahandle = atomic_inc_return(&mp->datahandle);
44191+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
44192 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
44193 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
44194 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
44195 capimsg_setu16(skb->data, 2, mp->ap->applid);
44196 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
44197 capimsg_setu8 (skb->data, 5, CAPI_REQ);
44198- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
44199+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
44200 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
44201 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
44202 capimsg_setu16(skb->data, 16, len); /* Data length */
44203diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
44204index b7ae0a0..04590fa 100644
44205--- a/drivers/isdn/gigaset/bas-gigaset.c
44206+++ b/drivers/isdn/gigaset/bas-gigaset.c
44207@@ -2565,22 +2565,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
44208
44209
44210 static const struct gigaset_ops gigops = {
44211- gigaset_write_cmd,
44212- gigaset_write_room,
44213- gigaset_chars_in_buffer,
44214- gigaset_brkchars,
44215- gigaset_init_bchannel,
44216- gigaset_close_bchannel,
44217- gigaset_initbcshw,
44218- gigaset_freebcshw,
44219- gigaset_reinitbcshw,
44220- gigaset_initcshw,
44221- gigaset_freecshw,
44222- gigaset_set_modem_ctrl,
44223- gigaset_baud_rate,
44224- gigaset_set_line_ctrl,
44225- gigaset_isoc_send_skb,
44226- gigaset_isoc_input,
44227+ .write_cmd = gigaset_write_cmd,
44228+ .write_room = gigaset_write_room,
44229+ .chars_in_buffer = gigaset_chars_in_buffer,
44230+ .brkchars = gigaset_brkchars,
44231+ .init_bchannel = gigaset_init_bchannel,
44232+ .close_bchannel = gigaset_close_bchannel,
44233+ .initbcshw = gigaset_initbcshw,
44234+ .freebcshw = gigaset_freebcshw,
44235+ .reinitbcshw = gigaset_reinitbcshw,
44236+ .initcshw = gigaset_initcshw,
44237+ .freecshw = gigaset_freecshw,
44238+ .set_modem_ctrl = gigaset_set_modem_ctrl,
44239+ .baud_rate = gigaset_baud_rate,
44240+ .set_line_ctrl = gigaset_set_line_ctrl,
44241+ .send_skb = gigaset_isoc_send_skb,
44242+ .handle_input = gigaset_isoc_input,
44243 };
44244
44245 /* bas_gigaset_init
44246diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
44247index 600c79b..3752bab 100644
44248--- a/drivers/isdn/gigaset/interface.c
44249+++ b/drivers/isdn/gigaset/interface.c
44250@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
44251 }
44252 tty->driver_data = cs;
44253
44254- ++cs->port.count;
44255+ atomic_inc(&cs->port.count);
44256
44257- if (cs->port.count == 1) {
44258+ if (atomic_read(&cs->port.count) == 1) {
44259 tty_port_tty_set(&cs->port, tty);
44260 cs->port.low_latency = 1;
44261 }
44262@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
44263
44264 if (!cs->connected)
44265 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
44266- else if (!cs->port.count)
44267+ else if (!atomic_read(&cs->port.count))
44268 dev_warn(cs->dev, "%s: device not opened\n", __func__);
44269- else if (!--cs->port.count)
44270+ else if (!atomic_dec_return(&cs->port.count))
44271 tty_port_tty_set(&cs->port, NULL);
44272
44273 mutex_unlock(&cs->mutex);
44274diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
44275index 8c91fd5..14f13ce 100644
44276--- a/drivers/isdn/gigaset/ser-gigaset.c
44277+++ b/drivers/isdn/gigaset/ser-gigaset.c
44278@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
44279 }
44280
44281 static const struct gigaset_ops ops = {
44282- gigaset_write_cmd,
44283- gigaset_write_room,
44284- gigaset_chars_in_buffer,
44285- gigaset_brkchars,
44286- gigaset_init_bchannel,
44287- gigaset_close_bchannel,
44288- gigaset_initbcshw,
44289- gigaset_freebcshw,
44290- gigaset_reinitbcshw,
44291- gigaset_initcshw,
44292- gigaset_freecshw,
44293- gigaset_set_modem_ctrl,
44294- gigaset_baud_rate,
44295- gigaset_set_line_ctrl,
44296- gigaset_m10x_send_skb, /* asyncdata.c */
44297- gigaset_m10x_input, /* asyncdata.c */
44298+ .write_cmd = gigaset_write_cmd,
44299+ .write_room = gigaset_write_room,
44300+ .chars_in_buffer = gigaset_chars_in_buffer,
44301+ .brkchars = gigaset_brkchars,
44302+ .init_bchannel = gigaset_init_bchannel,
44303+ .close_bchannel = gigaset_close_bchannel,
44304+ .initbcshw = gigaset_initbcshw,
44305+ .freebcshw = gigaset_freebcshw,
44306+ .reinitbcshw = gigaset_reinitbcshw,
44307+ .initcshw = gigaset_initcshw,
44308+ .freecshw = gigaset_freecshw,
44309+ .set_modem_ctrl = gigaset_set_modem_ctrl,
44310+ .baud_rate = gigaset_baud_rate,
44311+ .set_line_ctrl = gigaset_set_line_ctrl,
44312+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
44313+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
44314 };
44315
44316
44317diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
44318index d0a41cb..b953e50 100644
44319--- a/drivers/isdn/gigaset/usb-gigaset.c
44320+++ b/drivers/isdn/gigaset/usb-gigaset.c
44321@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
44322 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
44323 memcpy(cs->hw.usb->bchars, buf, 6);
44324 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
44325- 0, 0, &buf, 6, 2000);
44326+ 0, 0, buf, 6, 2000);
44327 }
44328
44329 static void gigaset_freebcshw(struct bc_state *bcs)
44330@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
44331 }
44332
44333 static const struct gigaset_ops ops = {
44334- gigaset_write_cmd,
44335- gigaset_write_room,
44336- gigaset_chars_in_buffer,
44337- gigaset_brkchars,
44338- gigaset_init_bchannel,
44339- gigaset_close_bchannel,
44340- gigaset_initbcshw,
44341- gigaset_freebcshw,
44342- gigaset_reinitbcshw,
44343- gigaset_initcshw,
44344- gigaset_freecshw,
44345- gigaset_set_modem_ctrl,
44346- gigaset_baud_rate,
44347- gigaset_set_line_ctrl,
44348- gigaset_m10x_send_skb,
44349- gigaset_m10x_input,
44350+ .write_cmd = gigaset_write_cmd,
44351+ .write_room = gigaset_write_room,
44352+ .chars_in_buffer = gigaset_chars_in_buffer,
44353+ .brkchars = gigaset_brkchars,
44354+ .init_bchannel = gigaset_init_bchannel,
44355+ .close_bchannel = gigaset_close_bchannel,
44356+ .initbcshw = gigaset_initbcshw,
44357+ .freebcshw = gigaset_freebcshw,
44358+ .reinitbcshw = gigaset_reinitbcshw,
44359+ .initcshw = gigaset_initcshw,
44360+ .freecshw = gigaset_freecshw,
44361+ .set_modem_ctrl = gigaset_set_modem_ctrl,
44362+ .baud_rate = gigaset_baud_rate,
44363+ .set_line_ctrl = gigaset_set_line_ctrl,
44364+ .send_skb = gigaset_m10x_send_skb,
44365+ .handle_input = gigaset_m10x_input,
44366 };
44367
44368 /*
44369diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
44370index 4d9b195..455075c 100644
44371--- a/drivers/isdn/hardware/avm/b1.c
44372+++ b/drivers/isdn/hardware/avm/b1.c
44373@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
44374 }
44375 if (left) {
44376 if (t4file->user) {
44377- if (copy_from_user(buf, dp, left))
44378+ if (left > sizeof buf || copy_from_user(buf, dp, left))
44379 return -EFAULT;
44380 } else {
44381 memcpy(buf, dp, left);
44382@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
44383 }
44384 if (left) {
44385 if (config->user) {
44386- if (copy_from_user(buf, dp, left))
44387+ if (left > sizeof buf || copy_from_user(buf, dp, left))
44388 return -EFAULT;
44389 } else {
44390 memcpy(buf, dp, left);
44391diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
44392index 9b856e1..fa03c92 100644
44393--- a/drivers/isdn/i4l/isdn_common.c
44394+++ b/drivers/isdn/i4l/isdn_common.c
44395@@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
44396 } else
44397 return -EINVAL;
44398 case IIOCDBGVAR:
44399+ if (!capable(CAP_SYS_RAWIO))
44400+ return -EPERM;
44401 if (arg) {
44402 if (copy_to_user(argp, &dev, sizeof(ulong)))
44403 return -EFAULT;
44404diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
44405index 91d5730..336523e 100644
44406--- a/drivers/isdn/i4l/isdn_concap.c
44407+++ b/drivers/isdn/i4l/isdn_concap.c
44408@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
44409 }
44410
44411 struct concap_device_ops isdn_concap_reliable_dl_dops = {
44412- &isdn_concap_dl_data_req,
44413- &isdn_concap_dl_connect_req,
44414- &isdn_concap_dl_disconn_req
44415+ .data_req = &isdn_concap_dl_data_req,
44416+ .connect_req = &isdn_concap_dl_connect_req,
44417+ .disconn_req = &isdn_concap_dl_disconn_req
44418 };
44419
44420 /* The following should better go into a dedicated source file such that
44421diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
44422index 3c5f249..5fac4d0 100644
44423--- a/drivers/isdn/i4l/isdn_tty.c
44424+++ b/drivers/isdn/i4l/isdn_tty.c
44425@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
44426
44427 #ifdef ISDN_DEBUG_MODEM_OPEN
44428 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
44429- port->count);
44430+ atomic_read(&port->count));
44431 #endif
44432- port->count++;
44433+ atomic_inc(&port->count);
44434 port->tty = tty;
44435 /*
44436 * Start up serial port
44437@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44438 #endif
44439 return;
44440 }
44441- if ((tty->count == 1) && (port->count != 1)) {
44442+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
44443 /*
44444 * Uh, oh. tty->count is 1, which means that the tty
44445 * structure will be freed. Info->count should always
44446@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
44447 * serial port won't be shutdown.
44448 */
44449 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
44450- "info->count is %d\n", port->count);
44451- port->count = 1;
44452+ "info->count is %d\n", atomic_read(&port->count));
44453+ atomic_set(&port->count, 1);
44454 }
44455- if (--port->count < 0) {
44456+ if (atomic_dec_return(&port->count) < 0) {
44457 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
44458- info->line, port->count);
44459- port->count = 0;
44460+ info->line, atomic_read(&port->count));
44461+ atomic_set(&port->count, 0);
44462 }
44463- if (port->count) {
44464+ if (atomic_read(&port->count)) {
44465 #ifdef ISDN_DEBUG_MODEM_OPEN
44466 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
44467 #endif
44468@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
44469 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
44470 return;
44471 isdn_tty_shutdown(info);
44472- port->count = 0;
44473+ atomic_set(&port->count, 0);
44474 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44475 port->tty = NULL;
44476 wake_up_interruptible(&port->open_wait);
44477@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
44478 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
44479 modem_info *info = &dev->mdm.info[i];
44480
44481- if (info->port.count == 0)
44482+ if (atomic_read(&info->port.count) == 0)
44483 continue;
44484 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
44485 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
44486diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
44487index e2d4e58..40cd045 100644
44488--- a/drivers/isdn/i4l/isdn_x25iface.c
44489+++ b/drivers/isdn/i4l/isdn_x25iface.c
44490@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
44491
44492
44493 static struct concap_proto_ops ix25_pops = {
44494- &isdn_x25iface_proto_new,
44495- &isdn_x25iface_proto_del,
44496- &isdn_x25iface_proto_restart,
44497- &isdn_x25iface_proto_close,
44498- &isdn_x25iface_xmit,
44499- &isdn_x25iface_receive,
44500- &isdn_x25iface_connect_ind,
44501- &isdn_x25iface_disconn_ind
44502+ .proto_new = &isdn_x25iface_proto_new,
44503+ .proto_del = &isdn_x25iface_proto_del,
44504+ .restart = &isdn_x25iface_proto_restart,
44505+ .close = &isdn_x25iface_proto_close,
44506+ .encap_and_xmit = &isdn_x25iface_xmit,
44507+ .data_ind = &isdn_x25iface_receive,
44508+ .connect_ind = &isdn_x25iface_connect_ind,
44509+ .disconn_ind = &isdn_x25iface_disconn_ind
44510 };
44511
44512 /* error message helper function */
44513diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
44514index 6a7447c..cae33fe 100644
44515--- a/drivers/isdn/icn/icn.c
44516+++ b/drivers/isdn/icn/icn.c
44517@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
44518 if (count > len)
44519 count = len;
44520 if (user) {
44521- if (copy_from_user(msg, buf, count))
44522+ if (count > sizeof msg || copy_from_user(msg, buf, count))
44523 return -EFAULT;
44524 } else
44525 memcpy(msg, buf, count);
44526diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
44527index a4f05c5..1433bc5 100644
44528--- a/drivers/isdn/mISDN/dsp_cmx.c
44529+++ b/drivers/isdn/mISDN/dsp_cmx.c
44530@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
44531 static u16 dsp_count; /* last sample count */
44532 static int dsp_count_valid; /* if we have last sample count */
44533
44534-void
44535+void __intentional_overflow(-1)
44536 dsp_cmx_send(void *arg)
44537 {
44538 struct dsp_conf *conf;
44539diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
44540index f58a354..fbae176 100644
44541--- a/drivers/leds/leds-clevo-mail.c
44542+++ b/drivers/leds/leds-clevo-mail.c
44543@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
44544 * detected as working, but in reality it is not) as low as
44545 * possible.
44546 */
44547-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
44548+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
44549 {
44550 .callback = clevo_mail_led_dmi_callback,
44551 .ident = "Clevo D410J",
44552diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
44553index 046cb70..6b20d39 100644
44554--- a/drivers/leds/leds-ss4200.c
44555+++ b/drivers/leds/leds-ss4200.c
44556@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
44557 * detected as working, but in reality it is not) as low as
44558 * possible.
44559 */
44560-static struct dmi_system_id nas_led_whitelist[] __initdata = {
44561+static struct dmi_system_id nas_led_whitelist[] __initconst = {
44562 {
44563 .callback = ss4200_led_dmi_callback,
44564 .ident = "Intel SS4200-E",
44565diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
44566index 6590558..a74c5dd 100644
44567--- a/drivers/lguest/core.c
44568+++ b/drivers/lguest/core.c
44569@@ -96,9 +96,17 @@ static __init int map_switcher(void)
44570 * The end address needs +1 because __get_vm_area allocates an
44571 * extra guard page, so we need space for that.
44572 */
44573+
44574+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
44575+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44576+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
44577+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44578+#else
44579 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
44580 VM_ALLOC, switcher_addr, switcher_addr
44581 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
44582+#endif
44583+
44584 if (!switcher_vma) {
44585 err = -ENOMEM;
44586 printk("lguest: could not map switcher pages high\n");
44587@@ -121,7 +129,7 @@ static __init int map_switcher(void)
44588 * Now the Switcher is mapped at the right address, we can't fail!
44589 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
44590 */
44591- memcpy(switcher_vma->addr, start_switcher_text,
44592+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
44593 end_switcher_text - start_switcher_text);
44594
44595 printk(KERN_INFO "lguest: mapped switcher at %p\n",
44596diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
44597index e8b55c3..3514c37 100644
44598--- a/drivers/lguest/page_tables.c
44599+++ b/drivers/lguest/page_tables.c
44600@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
44601 /*:*/
44602
44603 #ifdef CONFIG_X86_PAE
44604-static void release_pmd(pmd_t *spmd)
44605+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
44606 {
44607 /* If the entry's not present, there's nothing to release. */
44608 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
44609diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
44610index 922a1ac..9dd0c2a 100644
44611--- a/drivers/lguest/x86/core.c
44612+++ b/drivers/lguest/x86/core.c
44613@@ -59,7 +59,7 @@ static struct {
44614 /* Offset from where switcher.S was compiled to where we've copied it */
44615 static unsigned long switcher_offset(void)
44616 {
44617- return switcher_addr - (unsigned long)start_switcher_text;
44618+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
44619 }
44620
44621 /* This cpu's struct lguest_pages (after the Switcher text page) */
44622@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
44623 * These copies are pretty cheap, so we do them unconditionally: */
44624 /* Save the current Host top-level page directory.
44625 */
44626+
44627+#ifdef CONFIG_PAX_PER_CPU_PGD
44628+ pages->state.host_cr3 = read_cr3();
44629+#else
44630 pages->state.host_cr3 = __pa(current->mm->pgd);
44631+#endif
44632+
44633 /*
44634 * Set up the Guest's page tables to see this CPU's pages (and no
44635 * other CPU's pages).
44636@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
44637 * compiled-in switcher code and the high-mapped copy we just made.
44638 */
44639 for (i = 0; i < IDT_ENTRIES; i++)
44640- default_idt_entries[i] += switcher_offset();
44641+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
44642
44643 /*
44644 * Set up the Switcher's per-cpu areas.
44645@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
44646 * it will be undisturbed when we switch. To change %cs and jump we
44647 * need this structure to feed to Intel's "lcall" instruction.
44648 */
44649- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
44650+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
44651 lguest_entry.segment = LGUEST_CS;
44652
44653 /*
44654diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
44655index 40634b0..4f5855e 100644
44656--- a/drivers/lguest/x86/switcher_32.S
44657+++ b/drivers/lguest/x86/switcher_32.S
44658@@ -87,6 +87,7 @@
44659 #include <asm/page.h>
44660 #include <asm/segment.h>
44661 #include <asm/lguest.h>
44662+#include <asm/processor-flags.h>
44663
44664 // We mark the start of the code to copy
44665 // It's placed in .text tho it's never run here
44666@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
44667 // Changes type when we load it: damn Intel!
44668 // For after we switch over our page tables
44669 // That entry will be read-only: we'd crash.
44670+
44671+#ifdef CONFIG_PAX_KERNEXEC
44672+ mov %cr0, %edx
44673+ xor $X86_CR0_WP, %edx
44674+ mov %edx, %cr0
44675+#endif
44676+
44677 movl $(GDT_ENTRY_TSS*8), %edx
44678 ltr %dx
44679
44680@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
44681 // Let's clear it again for our return.
44682 // The GDT descriptor of the Host
44683 // Points to the table after two "size" bytes
44684- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
44685+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
44686 // Clear "used" from type field (byte 5, bit 2)
44687- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
44688+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
44689+
44690+#ifdef CONFIG_PAX_KERNEXEC
44691+ mov %cr0, %eax
44692+ xor $X86_CR0_WP, %eax
44693+ mov %eax, %cr0
44694+#endif
44695
44696 // Once our page table's switched, the Guest is live!
44697 // The Host fades as we run this final step.
44698@@ -295,13 +309,12 @@ deliver_to_host:
44699 // I consulted gcc, and it gave
44700 // These instructions, which I gladly credit:
44701 leal (%edx,%ebx,8), %eax
44702- movzwl (%eax),%edx
44703- movl 4(%eax), %eax
44704- xorw %ax, %ax
44705- orl %eax, %edx
44706+ movl 4(%eax), %edx
44707+ movw (%eax), %dx
44708 // Now the address of the handler's in %edx
44709 // We call it now: its "iret" drops us home.
44710- jmp *%edx
44711+ ljmp $__KERNEL_CS, $1f
44712+1: jmp *%edx
44713
44714 // Every interrupt can come to us here
44715 // But we must truly tell each apart.
44716diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
44717index a08e3ee..df8ade2 100644
44718--- a/drivers/md/bcache/closure.h
44719+++ b/drivers/md/bcache/closure.h
44720@@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
44721 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
44722 struct workqueue_struct *wq)
44723 {
44724- BUG_ON(object_is_on_stack(cl));
44725+ BUG_ON(object_starts_on_stack(cl));
44726 closure_set_ip(cl);
44727 cl->fn = fn;
44728 cl->wq = wq;
44729diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
44730index 67f8b31..9418f2b 100644
44731--- a/drivers/md/bitmap.c
44732+++ b/drivers/md/bitmap.c
44733@@ -1775,7 +1775,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
44734 chunk_kb ? "KB" : "B");
44735 if (bitmap->storage.file) {
44736 seq_printf(seq, ", file: ");
44737- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
44738+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
44739 }
44740
44741 seq_printf(seq, "\n");
44742diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
44743index 5152142..623d141 100644
44744--- a/drivers/md/dm-ioctl.c
44745+++ b/drivers/md/dm-ioctl.c
44746@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
44747 cmd == DM_LIST_VERSIONS_CMD)
44748 return 0;
44749
44750- if ((cmd == DM_DEV_CREATE_CMD)) {
44751+ if (cmd == DM_DEV_CREATE_CMD) {
44752 if (!*param->name) {
44753 DMWARN("name not supplied when creating device");
44754 return -EINVAL;
44755diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
44756index 7dfdb5c..4caada6 100644
44757--- a/drivers/md/dm-raid1.c
44758+++ b/drivers/md/dm-raid1.c
44759@@ -40,7 +40,7 @@ enum dm_raid1_error {
44760
44761 struct mirror {
44762 struct mirror_set *ms;
44763- atomic_t error_count;
44764+ atomic_unchecked_t error_count;
44765 unsigned long error_type;
44766 struct dm_dev *dev;
44767 sector_t offset;
44768@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
44769 struct mirror *m;
44770
44771 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
44772- if (!atomic_read(&m->error_count))
44773+ if (!atomic_read_unchecked(&m->error_count))
44774 return m;
44775
44776 return NULL;
44777@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
44778 * simple way to tell if a device has encountered
44779 * errors.
44780 */
44781- atomic_inc(&m->error_count);
44782+ atomic_inc_unchecked(&m->error_count);
44783
44784 if (test_and_set_bit(error_type, &m->error_type))
44785 return;
44786@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
44787 struct mirror *m = get_default_mirror(ms);
44788
44789 do {
44790- if (likely(!atomic_read(&m->error_count)))
44791+ if (likely(!atomic_read_unchecked(&m->error_count)))
44792 return m;
44793
44794 if (m-- == ms->mirror)
44795@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
44796 {
44797 struct mirror *default_mirror = get_default_mirror(m->ms);
44798
44799- return !atomic_read(&default_mirror->error_count);
44800+ return !atomic_read_unchecked(&default_mirror->error_count);
44801 }
44802
44803 static int mirror_available(struct mirror_set *ms, struct bio *bio)
44804@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
44805 */
44806 if (likely(region_in_sync(ms, region, 1)))
44807 m = choose_mirror(ms, bio->bi_iter.bi_sector);
44808- else if (m && atomic_read(&m->error_count))
44809+ else if (m && atomic_read_unchecked(&m->error_count))
44810 m = NULL;
44811
44812 if (likely(m))
44813@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
44814 }
44815
44816 ms->mirror[mirror].ms = ms;
44817- atomic_set(&(ms->mirror[mirror].error_count), 0);
44818+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
44819 ms->mirror[mirror].error_type = 0;
44820 ms->mirror[mirror].offset = offset;
44821
44822@@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
44823 */
44824 static char device_status_char(struct mirror *m)
44825 {
44826- if (!atomic_read(&(m->error_count)))
44827+ if (!atomic_read_unchecked(&(m->error_count)))
44828 return 'A';
44829
44830 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
44831diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
44832index 28a9012..9c0f6a5 100644
44833--- a/drivers/md/dm-stats.c
44834+++ b/drivers/md/dm-stats.c
44835@@ -382,7 +382,7 @@ do_sync_free:
44836 synchronize_rcu_expedited();
44837 dm_stat_free(&s->rcu_head);
44838 } else {
44839- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
44840+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
44841 call_rcu(&s->rcu_head, dm_stat_free);
44842 }
44843 return 0;
44844@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
44845 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
44846 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
44847 ));
44848- ACCESS_ONCE(last->last_sector) = end_sector;
44849- ACCESS_ONCE(last->last_rw) = bi_rw;
44850+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
44851+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
44852 }
44853
44854 rcu_read_lock();
44855diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
44856index d1600d2..4c3af3a 100644
44857--- a/drivers/md/dm-stripe.c
44858+++ b/drivers/md/dm-stripe.c
44859@@ -21,7 +21,7 @@ struct stripe {
44860 struct dm_dev *dev;
44861 sector_t physical_start;
44862
44863- atomic_t error_count;
44864+ atomic_unchecked_t error_count;
44865 };
44866
44867 struct stripe_c {
44868@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
44869 kfree(sc);
44870 return r;
44871 }
44872- atomic_set(&(sc->stripe[i].error_count), 0);
44873+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
44874 }
44875
44876 ti->private = sc;
44877@@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
44878 DMEMIT("%d ", sc->stripes);
44879 for (i = 0; i < sc->stripes; i++) {
44880 DMEMIT("%s ", sc->stripe[i].dev->name);
44881- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
44882+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
44883 'D' : 'A';
44884 }
44885 buffer[i] = '\0';
44886@@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
44887 */
44888 for (i = 0; i < sc->stripes; i++)
44889 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
44890- atomic_inc(&(sc->stripe[i].error_count));
44891- if (atomic_read(&(sc->stripe[i].error_count)) <
44892+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
44893+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
44894 DM_IO_ERROR_THRESHOLD)
44895 schedule_work(&sc->trigger_event);
44896 }
44897diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
44898index f9c6cb8..e272df6 100644
44899--- a/drivers/md/dm-table.c
44900+++ b/drivers/md/dm-table.c
44901@@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
44902 static int open_dev(struct dm_dev_internal *d, dev_t dev,
44903 struct mapped_device *md)
44904 {
44905- static char *_claim_ptr = "I belong to device-mapper";
44906+ static char _claim_ptr[] = "I belong to device-mapper";
44907 struct block_device *bdev;
44908
44909 int r;
44910@@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
44911 if (!dev_size)
44912 return 0;
44913
44914- if ((start >= dev_size) || (start + len > dev_size)) {
44915+ if ((start >= dev_size) || (len > dev_size - start)) {
44916 DMWARN("%s: %s too small for target: "
44917 "start=%llu, len=%llu, dev_size=%llu",
44918 dm_device_name(ti->table->md), bdevname(bdev, b),
44919diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
44920index e9d33ad..dae9880d 100644
44921--- a/drivers/md/dm-thin-metadata.c
44922+++ b/drivers/md/dm-thin-metadata.c
44923@@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44924 {
44925 pmd->info.tm = pmd->tm;
44926 pmd->info.levels = 2;
44927- pmd->info.value_type.context = pmd->data_sm;
44928+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44929 pmd->info.value_type.size = sizeof(__le64);
44930 pmd->info.value_type.inc = data_block_inc;
44931 pmd->info.value_type.dec = data_block_dec;
44932@@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
44933
44934 pmd->bl_info.tm = pmd->tm;
44935 pmd->bl_info.levels = 1;
44936- pmd->bl_info.value_type.context = pmd->data_sm;
44937+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
44938 pmd->bl_info.value_type.size = sizeof(__le64);
44939 pmd->bl_info.value_type.inc = data_block_inc;
44940 pmd->bl_info.value_type.dec = data_block_dec;
44941diff --git a/drivers/md/dm.c b/drivers/md/dm.c
44942index 32b958d..34011e8 100644
44943--- a/drivers/md/dm.c
44944+++ b/drivers/md/dm.c
44945@@ -180,9 +180,9 @@ struct mapped_device {
44946 /*
44947 * Event handling.
44948 */
44949- atomic_t event_nr;
44950+ atomic_unchecked_t event_nr;
44951 wait_queue_head_t eventq;
44952- atomic_t uevent_seq;
44953+ atomic_unchecked_t uevent_seq;
44954 struct list_head uevent_list;
44955 spinlock_t uevent_lock; /* Protect access to uevent_list */
44956
44957@@ -1952,8 +1952,8 @@ static struct mapped_device *alloc_dev(int minor)
44958 spin_lock_init(&md->deferred_lock);
44959 atomic_set(&md->holders, 1);
44960 atomic_set(&md->open_count, 0);
44961- atomic_set(&md->event_nr, 0);
44962- atomic_set(&md->uevent_seq, 0);
44963+ atomic_set_unchecked(&md->event_nr, 0);
44964+ atomic_set_unchecked(&md->uevent_seq, 0);
44965 INIT_LIST_HEAD(&md->uevent_list);
44966 spin_lock_init(&md->uevent_lock);
44967
44968@@ -2107,7 +2107,7 @@ static void event_callback(void *context)
44969
44970 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
44971
44972- atomic_inc(&md->event_nr);
44973+ atomic_inc_unchecked(&md->event_nr);
44974 wake_up(&md->eventq);
44975 }
44976
44977@@ -2800,18 +2800,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
44978
44979 uint32_t dm_next_uevent_seq(struct mapped_device *md)
44980 {
44981- return atomic_add_return(1, &md->uevent_seq);
44982+ return atomic_add_return_unchecked(1, &md->uevent_seq);
44983 }
44984
44985 uint32_t dm_get_event_nr(struct mapped_device *md)
44986 {
44987- return atomic_read(&md->event_nr);
44988+ return atomic_read_unchecked(&md->event_nr);
44989 }
44990
44991 int dm_wait_event(struct mapped_device *md, int event_nr)
44992 {
44993 return wait_event_interruptible(md->eventq,
44994- (event_nr != atomic_read(&md->event_nr)));
44995+ (event_nr != atomic_read_unchecked(&md->event_nr)));
44996 }
44997
44998 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
44999diff --git a/drivers/md/md.c b/drivers/md/md.c
45000index 1294238..a442227 100644
45001--- a/drivers/md/md.c
45002+++ b/drivers/md/md.c
45003@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
45004 * start build, activate spare
45005 */
45006 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
45007-static atomic_t md_event_count;
45008+static atomic_unchecked_t md_event_count;
45009 void md_new_event(struct mddev *mddev)
45010 {
45011- atomic_inc(&md_event_count);
45012+ atomic_inc_unchecked(&md_event_count);
45013 wake_up(&md_event_waiters);
45014 }
45015 EXPORT_SYMBOL_GPL(md_new_event);
45016@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
45017 */
45018 static void md_new_event_inintr(struct mddev *mddev)
45019 {
45020- atomic_inc(&md_event_count);
45021+ atomic_inc_unchecked(&md_event_count);
45022 wake_up(&md_event_waiters);
45023 }
45024
45025@@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
45026 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
45027 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
45028 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
45029- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
45030+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
45031
45032 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
45033 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
45034@@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
45035 else
45036 sb->resync_offset = cpu_to_le64(0);
45037
45038- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
45039+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
45040
45041 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
45042 sb->size = cpu_to_le64(mddev->dev_sectors);
45043@@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
45044 static ssize_t
45045 errors_show(struct md_rdev *rdev, char *page)
45046 {
45047- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
45048+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
45049 }
45050
45051 static ssize_t
45052@@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
45053 char *e;
45054 unsigned long n = simple_strtoul(buf, &e, 10);
45055 if (*buf && (*e == 0 || *e == '\n')) {
45056- atomic_set(&rdev->corrected_errors, n);
45057+ atomic_set_unchecked(&rdev->corrected_errors, n);
45058 return len;
45059 }
45060 return -EINVAL;
45061@@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
45062 rdev->sb_loaded = 0;
45063 rdev->bb_page = NULL;
45064 atomic_set(&rdev->nr_pending, 0);
45065- atomic_set(&rdev->read_errors, 0);
45066- atomic_set(&rdev->corrected_errors, 0);
45067+ atomic_set_unchecked(&rdev->read_errors, 0);
45068+ atomic_set_unchecked(&rdev->corrected_errors, 0);
45069
45070 INIT_LIST_HEAD(&rdev->same_set);
45071 init_waitqueue_head(&rdev->blocked_wait);
45072@@ -7068,7 +7068,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
45073
45074 spin_unlock(&pers_lock);
45075 seq_printf(seq, "\n");
45076- seq->poll_event = atomic_read(&md_event_count);
45077+ seq->poll_event = atomic_read_unchecked(&md_event_count);
45078 return 0;
45079 }
45080 if (v == (void*)2) {
45081@@ -7171,7 +7171,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
45082 return error;
45083
45084 seq = file->private_data;
45085- seq->poll_event = atomic_read(&md_event_count);
45086+ seq->poll_event = atomic_read_unchecked(&md_event_count);
45087 return error;
45088 }
45089
45090@@ -7188,7 +7188,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
45091 /* always allow read */
45092 mask = POLLIN | POLLRDNORM;
45093
45094- if (seq->poll_event != atomic_read(&md_event_count))
45095+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
45096 mask |= POLLERR | POLLPRI;
45097 return mask;
45098 }
45099@@ -7232,7 +7232,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
45100 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
45101 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
45102 (int)part_stat_read(&disk->part0, sectors[1]) -
45103- atomic_read(&disk->sync_io);
45104+ atomic_read_unchecked(&disk->sync_io);
45105 /* sync IO will cause sync_io to increase before the disk_stats
45106 * as sync_io is counted when a request starts, and
45107 * disk_stats is counted when it completes.
45108diff --git a/drivers/md/md.h b/drivers/md/md.h
45109index a49d991..3582bb7 100644
45110--- a/drivers/md/md.h
45111+++ b/drivers/md/md.h
45112@@ -94,13 +94,13 @@ struct md_rdev {
45113 * only maintained for arrays that
45114 * support hot removal
45115 */
45116- atomic_t read_errors; /* number of consecutive read errors that
45117+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
45118 * we have tried to ignore.
45119 */
45120 struct timespec last_read_error; /* monotonic time since our
45121 * last read error
45122 */
45123- atomic_t corrected_errors; /* number of corrected read errors,
45124+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
45125 * for reporting to userspace and storing
45126 * in superblock.
45127 */
45128@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
45129
45130 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
45131 {
45132- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
45133+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
45134 }
45135
45136 struct md_personality
45137diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
45138index 786b689..ea8c956 100644
45139--- a/drivers/md/persistent-data/dm-space-map-metadata.c
45140+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
45141@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
45142 * Flick into a mode where all blocks get allocated in the new area.
45143 */
45144 smm->begin = old_len;
45145- memcpy(sm, &bootstrap_ops, sizeof(*sm));
45146+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
45147
45148 /*
45149 * Extend.
45150@@ -710,7 +710,7 @@ out:
45151 /*
45152 * Switch back to normal behaviour.
45153 */
45154- memcpy(sm, &ops, sizeof(*sm));
45155+ memcpy((void *)sm, &ops, sizeof(*sm));
45156 return r;
45157 }
45158
45159diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
45160index 3e6d115..ffecdeb 100644
45161--- a/drivers/md/persistent-data/dm-space-map.h
45162+++ b/drivers/md/persistent-data/dm-space-map.h
45163@@ -71,6 +71,7 @@ struct dm_space_map {
45164 dm_sm_threshold_fn fn,
45165 void *context);
45166 };
45167+typedef struct dm_space_map __no_const dm_space_map_no_const;
45168
45169 /*----------------------------------------------------------------*/
45170
45171diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
45172index 55de4f6..b1c57fe 100644
45173--- a/drivers/md/raid1.c
45174+++ b/drivers/md/raid1.c
45175@@ -1936,7 +1936,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
45176 if (r1_sync_page_io(rdev, sect, s,
45177 bio->bi_io_vec[idx].bv_page,
45178 READ) != 0)
45179- atomic_add(s, &rdev->corrected_errors);
45180+ atomic_add_unchecked(s, &rdev->corrected_errors);
45181 }
45182 sectors -= s;
45183 sect += s;
45184@@ -2170,7 +2170,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
45185 !test_bit(Faulty, &rdev->flags)) {
45186 if (r1_sync_page_io(rdev, sect, s,
45187 conf->tmppage, READ)) {
45188- atomic_add(s, &rdev->corrected_errors);
45189+ atomic_add_unchecked(s, &rdev->corrected_errors);
45190 printk(KERN_INFO
45191 "md/raid1:%s: read error corrected "
45192 "(%d sectors at %llu on %s)\n",
45193diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
45194index 6703751..187af1e 100644
45195--- a/drivers/md/raid10.c
45196+++ b/drivers/md/raid10.c
45197@@ -1948,7 +1948,7 @@ static void end_sync_read(struct bio *bio, int error)
45198 /* The write handler will notice the lack of
45199 * R10BIO_Uptodate and record any errors etc
45200 */
45201- atomic_add(r10_bio->sectors,
45202+ atomic_add_unchecked(r10_bio->sectors,
45203 &conf->mirrors[d].rdev->corrected_errors);
45204
45205 /* for reconstruct, we always reschedule after a read.
45206@@ -2306,7 +2306,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
45207 {
45208 struct timespec cur_time_mon;
45209 unsigned long hours_since_last;
45210- unsigned int read_errors = atomic_read(&rdev->read_errors);
45211+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
45212
45213 ktime_get_ts(&cur_time_mon);
45214
45215@@ -2328,9 +2328,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
45216 * overflowing the shift of read_errors by hours_since_last.
45217 */
45218 if (hours_since_last >= 8 * sizeof(read_errors))
45219- atomic_set(&rdev->read_errors, 0);
45220+ atomic_set_unchecked(&rdev->read_errors, 0);
45221 else
45222- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
45223+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
45224 }
45225
45226 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
45227@@ -2384,8 +2384,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
45228 return;
45229
45230 check_decay_read_errors(mddev, rdev);
45231- atomic_inc(&rdev->read_errors);
45232- if (atomic_read(&rdev->read_errors) > max_read_errors) {
45233+ atomic_inc_unchecked(&rdev->read_errors);
45234+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
45235 char b[BDEVNAME_SIZE];
45236 bdevname(rdev->bdev, b);
45237
45238@@ -2393,7 +2393,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
45239 "md/raid10:%s: %s: Raid device exceeded "
45240 "read_error threshold [cur %d:max %d]\n",
45241 mdname(mddev), b,
45242- atomic_read(&rdev->read_errors), max_read_errors);
45243+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
45244 printk(KERN_NOTICE
45245 "md/raid10:%s: %s: Failing raid device\n",
45246 mdname(mddev), b);
45247@@ -2548,7 +2548,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
45248 sect +
45249 choose_data_offset(r10_bio, rdev)),
45250 bdevname(rdev->bdev, b));
45251- atomic_add(s, &rdev->corrected_errors);
45252+ atomic_add_unchecked(s, &rdev->corrected_errors);
45253 }
45254
45255 rdev_dec_pending(rdev, mddev);
45256diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
45257index 9f0fbec..991e7a1 100644
45258--- a/drivers/md/raid5.c
45259+++ b/drivers/md/raid5.c
45260@@ -1735,6 +1735,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
45261 return 1;
45262 }
45263
45264+#ifdef CONFIG_GRKERNSEC_HIDESYM
45265+static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
45266+#endif
45267+
45268 static int grow_stripes(struct r5conf *conf, int num)
45269 {
45270 struct kmem_cache *sc;
45271@@ -1746,7 +1750,11 @@ static int grow_stripes(struct r5conf *conf, int num)
45272 "raid%d-%s", conf->level, mdname(conf->mddev));
45273 else
45274 sprintf(conf->cache_name[0],
45275+#ifdef CONFIG_GRKERNSEC_HIDESYM
45276+ "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
45277+#else
45278 "raid%d-%p", conf->level, conf->mddev);
45279+#endif
45280 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
45281
45282 conf->active_name = 0;
45283@@ -2022,21 +2030,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
45284 mdname(conf->mddev), STRIPE_SECTORS,
45285 (unsigned long long)s,
45286 bdevname(rdev->bdev, b));
45287- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
45288+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
45289 clear_bit(R5_ReadError, &sh->dev[i].flags);
45290 clear_bit(R5_ReWrite, &sh->dev[i].flags);
45291 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
45292 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
45293
45294- if (atomic_read(&rdev->read_errors))
45295- atomic_set(&rdev->read_errors, 0);
45296+ if (atomic_read_unchecked(&rdev->read_errors))
45297+ atomic_set_unchecked(&rdev->read_errors, 0);
45298 } else {
45299 const char *bdn = bdevname(rdev->bdev, b);
45300 int retry = 0;
45301 int set_bad = 0;
45302
45303 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
45304- atomic_inc(&rdev->read_errors);
45305+ atomic_inc_unchecked(&rdev->read_errors);
45306 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
45307 printk_ratelimited(
45308 KERN_WARNING
45309@@ -2064,7 +2072,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
45310 mdname(conf->mddev),
45311 (unsigned long long)s,
45312 bdn);
45313- } else if (atomic_read(&rdev->read_errors)
45314+ } else if (atomic_read_unchecked(&rdev->read_errors)
45315 > conf->max_nr_stripes)
45316 printk(KERN_WARNING
45317 "md/raid:%s: Too many read errors, failing device %s.\n",
45318diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
45319index 983db75..ef9248c 100644
45320--- a/drivers/media/dvb-core/dvbdev.c
45321+++ b/drivers/media/dvb-core/dvbdev.c
45322@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
45323 const struct dvb_device *template, void *priv, int type)
45324 {
45325 struct dvb_device *dvbdev;
45326- struct file_operations *dvbdevfops;
45327+ file_operations_no_const *dvbdevfops;
45328 struct device *clsdev;
45329 int minor;
45330 int id;
45331diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
45332index 539f4db..cdd403b 100644
45333--- a/drivers/media/dvb-frontends/af9033.h
45334+++ b/drivers/media/dvb-frontends/af9033.h
45335@@ -82,7 +82,7 @@ struct af9033_ops {
45336 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
45337 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
45338 int onoff);
45339-};
45340+} __no_const;
45341
45342
45343 #if IS_ENABLED(CONFIG_DVB_AF9033)
45344diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
45345index 9b6c3bb..baeb5c7 100644
45346--- a/drivers/media/dvb-frontends/dib3000.h
45347+++ b/drivers/media/dvb-frontends/dib3000.h
45348@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
45349 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
45350 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
45351 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
45352-};
45353+} __no_const;
45354
45355 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
45356 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
45357diff --git a/drivers/media/dvb-frontends/dib7000p.h b/drivers/media/dvb-frontends/dib7000p.h
45358index 1fea0e9..321ce8f 100644
45359--- a/drivers/media/dvb-frontends/dib7000p.h
45360+++ b/drivers/media/dvb-frontends/dib7000p.h
45361@@ -64,7 +64,7 @@ struct dib7000p_ops {
45362 int (*get_adc_power)(struct dvb_frontend *fe);
45363 int (*slave_reset)(struct dvb_frontend *fe);
45364 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000p_config *cfg);
45365-};
45366+} __no_const;
45367
45368 #if IS_ENABLED(CONFIG_DVB_DIB7000P)
45369 void *dib7000p_attach(struct dib7000p_ops *ops);
45370diff --git a/drivers/media/dvb-frontends/dib8000.h b/drivers/media/dvb-frontends/dib8000.h
45371index 84cc103..5780c54 100644
45372--- a/drivers/media/dvb-frontends/dib8000.h
45373+++ b/drivers/media/dvb-frontends/dib8000.h
45374@@ -61,7 +61,7 @@ struct dib8000_ops {
45375 int (*pid_filter_ctrl)(struct dvb_frontend *fe, u8 onoff);
45376 int (*pid_filter)(struct dvb_frontend *fe, u8 id, u16 pid, u8 onoff);
45377 struct dvb_frontend *(*init)(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib8000_config *cfg);
45378-};
45379+} __no_const;
45380
45381 #if IS_ENABLED(CONFIG_DVB_DIB8000)
45382 void *dib8000_attach(struct dib8000_ops *ops);
45383diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
45384index ed8cb90..5ef7f79 100644
45385--- a/drivers/media/pci/cx88/cx88-video.c
45386+++ b/drivers/media/pci/cx88/cx88-video.c
45387@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
45388
45389 /* ------------------------------------------------------------------ */
45390
45391-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45392-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45393-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45394+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45395+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45396+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
45397
45398 module_param_array(video_nr, int, NULL, 0444);
45399 module_param_array(vbi_nr, int, NULL, 0444);
45400diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
45401index 802642d..5534900 100644
45402--- a/drivers/media/pci/ivtv/ivtv-driver.c
45403+++ b/drivers/media/pci/ivtv/ivtv-driver.c
45404@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
45405 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
45406
45407 /* ivtv instance counter */
45408-static atomic_t ivtv_instance = ATOMIC_INIT(0);
45409+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
45410
45411 /* Parameter declarations */
45412 static int cardtype[IVTV_MAX_CARDS];
45413diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
45414index 172583d..0f806f4 100644
45415--- a/drivers/media/pci/solo6x10/solo6x10-core.c
45416+++ b/drivers/media/pci/solo6x10/solo6x10-core.c
45417@@ -430,7 +430,7 @@ static void solo_device_release(struct device *dev)
45418
45419 static int solo_sysfs_init(struct solo_dev *solo_dev)
45420 {
45421- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
45422+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
45423 struct device *dev = &solo_dev->dev;
45424 const char *driver;
45425 int i;
45426diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
45427index c7141f2..5301fec 100644
45428--- a/drivers/media/pci/solo6x10/solo6x10-g723.c
45429+++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
45430@@ -351,7 +351,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
45431
45432 int solo_g723_init(struct solo_dev *solo_dev)
45433 {
45434- static struct snd_device_ops ops = { NULL };
45435+ static struct snd_device_ops ops = { };
45436 struct snd_card *card;
45437 struct snd_kcontrol_new kctl;
45438 char name[32];
45439diff --git a/drivers/media/pci/solo6x10/solo6x10-p2m.c b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45440index 8c84846..27b4f83 100644
45441--- a/drivers/media/pci/solo6x10/solo6x10-p2m.c
45442+++ b/drivers/media/pci/solo6x10/solo6x10-p2m.c
45443@@ -73,7 +73,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
45444
45445 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
45446 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
45447- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
45448+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
45449 if (p2m_id < 0)
45450 p2m_id = -p2m_id;
45451 }
45452diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
45453index c6154b0..73e4ae9 100644
45454--- a/drivers/media/pci/solo6x10/solo6x10.h
45455+++ b/drivers/media/pci/solo6x10/solo6x10.h
45456@@ -219,7 +219,7 @@ struct solo_dev {
45457
45458 /* P2M DMA Engine */
45459 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
45460- atomic_t p2m_count;
45461+ atomic_unchecked_t p2m_count;
45462 int p2m_jiffies;
45463 unsigned int p2m_timeouts;
45464
45465diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
45466index 2d177fa..5b925a1 100644
45467--- a/drivers/media/platform/omap/omap_vout.c
45468+++ b/drivers/media/platform/omap/omap_vout.c
45469@@ -63,7 +63,6 @@ enum omap_vout_channels {
45470 OMAP_VIDEO2,
45471 };
45472
45473-static struct videobuf_queue_ops video_vbq_ops;
45474 /* Variables configurable through module params*/
45475 static u32 video1_numbuffers = 3;
45476 static u32 video2_numbuffers = 3;
45477@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
45478 {
45479 struct videobuf_queue *q;
45480 struct omap_vout_device *vout = NULL;
45481+ static struct videobuf_queue_ops video_vbq_ops = {
45482+ .buf_setup = omap_vout_buffer_setup,
45483+ .buf_prepare = omap_vout_buffer_prepare,
45484+ .buf_release = omap_vout_buffer_release,
45485+ .buf_queue = omap_vout_buffer_queue,
45486+ };
45487
45488 vout = video_drvdata(file);
45489 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
45490@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
45491 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
45492
45493 q = &vout->vbq;
45494- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
45495- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
45496- video_vbq_ops.buf_release = omap_vout_buffer_release;
45497- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
45498 spin_lock_init(&vout->vbq_lock);
45499
45500 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
45501diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
45502index fb2acc5..a2fcbdc4 100644
45503--- a/drivers/media/platform/s5p-tv/mixer.h
45504+++ b/drivers/media/platform/s5p-tv/mixer.h
45505@@ -156,7 +156,7 @@ struct mxr_layer {
45506 /** layer index (unique identifier) */
45507 int idx;
45508 /** callbacks for layer methods */
45509- struct mxr_layer_ops ops;
45510+ struct mxr_layer_ops *ops;
45511 /** format array */
45512 const struct mxr_format **fmt_array;
45513 /** size of format array */
45514diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45515index 74344c7..a39e70e 100644
45516--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45517+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
45518@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
45519 {
45520 struct mxr_layer *layer;
45521 int ret;
45522- struct mxr_layer_ops ops = {
45523+ static struct mxr_layer_ops ops = {
45524 .release = mxr_graph_layer_release,
45525 .buffer_set = mxr_graph_buffer_set,
45526 .stream_set = mxr_graph_stream_set,
45527diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
45528index b713403..53cb5ad 100644
45529--- a/drivers/media/platform/s5p-tv/mixer_reg.c
45530+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
45531@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
45532 layer->update_buf = next;
45533 }
45534
45535- layer->ops.buffer_set(layer, layer->update_buf);
45536+ layer->ops->buffer_set(layer, layer->update_buf);
45537
45538 if (done && done != layer->shadow_buf)
45539 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
45540diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
45541index b4d2696..91df48e 100644
45542--- a/drivers/media/platform/s5p-tv/mixer_video.c
45543+++ b/drivers/media/platform/s5p-tv/mixer_video.c
45544@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
45545 layer->geo.src.height = layer->geo.src.full_height;
45546
45547 mxr_geometry_dump(mdev, &layer->geo);
45548- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45549+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45550 mxr_geometry_dump(mdev, &layer->geo);
45551 }
45552
45553@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
45554 layer->geo.dst.full_width = mbus_fmt.width;
45555 layer->geo.dst.full_height = mbus_fmt.height;
45556 layer->geo.dst.field = mbus_fmt.field;
45557- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45558+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
45559
45560 mxr_geometry_dump(mdev, &layer->geo);
45561 }
45562@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
45563 /* set source size to highest accepted value */
45564 geo->src.full_width = max(geo->dst.full_width, pix->width);
45565 geo->src.full_height = max(geo->dst.full_height, pix->height);
45566- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45567+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45568 mxr_geometry_dump(mdev, &layer->geo);
45569 /* set cropping to total visible screen */
45570 geo->src.width = pix->width;
45571@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
45572 geo->src.x_offset = 0;
45573 geo->src.y_offset = 0;
45574 /* assure consistency of geometry */
45575- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45576+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
45577 mxr_geometry_dump(mdev, &layer->geo);
45578 /* set full size to lowest possible value */
45579 geo->src.full_width = 0;
45580 geo->src.full_height = 0;
45581- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45582+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
45583 mxr_geometry_dump(mdev, &layer->geo);
45584
45585 /* returning results */
45586@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
45587 target->width = s->r.width;
45588 target->height = s->r.height;
45589
45590- layer->ops.fix_geometry(layer, stage, s->flags);
45591+ layer->ops->fix_geometry(layer, stage, s->flags);
45592
45593 /* retrieve update selection rectangle */
45594 res.left = target->x_offset;
45595@@ -954,13 +954,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
45596 mxr_output_get(mdev);
45597
45598 mxr_layer_update_output(layer);
45599- layer->ops.format_set(layer);
45600+ layer->ops->format_set(layer);
45601 /* enabling layer in hardware */
45602 spin_lock_irqsave(&layer->enq_slock, flags);
45603 layer->state = MXR_LAYER_STREAMING;
45604 spin_unlock_irqrestore(&layer->enq_slock, flags);
45605
45606- layer->ops.stream_set(layer, MXR_ENABLE);
45607+ layer->ops->stream_set(layer, MXR_ENABLE);
45608 mxr_streamer_get(mdev);
45609
45610 return 0;
45611@@ -1030,7 +1030,7 @@ static void stop_streaming(struct vb2_queue *vq)
45612 spin_unlock_irqrestore(&layer->enq_slock, flags);
45613
45614 /* disabling layer in hardware */
45615- layer->ops.stream_set(layer, MXR_DISABLE);
45616+ layer->ops->stream_set(layer, MXR_DISABLE);
45617 /* remove one streamer */
45618 mxr_streamer_put(mdev);
45619 /* allow changes in output configuration */
45620@@ -1068,8 +1068,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
45621
45622 void mxr_layer_release(struct mxr_layer *layer)
45623 {
45624- if (layer->ops.release)
45625- layer->ops.release(layer);
45626+ if (layer->ops->release)
45627+ layer->ops->release(layer);
45628 }
45629
45630 void mxr_base_layer_release(struct mxr_layer *layer)
45631@@ -1095,7 +1095,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
45632
45633 layer->mdev = mdev;
45634 layer->idx = idx;
45635- layer->ops = *ops;
45636+ layer->ops = ops;
45637
45638 spin_lock_init(&layer->enq_slock);
45639 INIT_LIST_HEAD(&layer->enq_list);
45640diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45641index c9388c4..ce71ece 100644
45642--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45643+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
45644@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
45645 {
45646 struct mxr_layer *layer;
45647 int ret;
45648- struct mxr_layer_ops ops = {
45649+ static struct mxr_layer_ops ops = {
45650 .release = mxr_vp_layer_release,
45651 .buffer_set = mxr_vp_buffer_set,
45652 .stream_set = mxr_vp_stream_set,
45653diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
45654index 8033371..de5bca0 100644
45655--- a/drivers/media/platform/vivi.c
45656+++ b/drivers/media/platform/vivi.c
45657@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
45658 MODULE_LICENSE("Dual BSD/GPL");
45659 MODULE_VERSION(VIVI_VERSION);
45660
45661-static unsigned video_nr = -1;
45662-module_param(video_nr, uint, 0644);
45663+static int video_nr = -1;
45664+module_param(video_nr, int, 0644);
45665 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
45666
45667 static unsigned n_devs = 1;
45668diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
45669index 82affae..42833ec 100644
45670--- a/drivers/media/radio/radio-cadet.c
45671+++ b/drivers/media/radio/radio-cadet.c
45672@@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45673 unsigned char readbuf[RDS_BUFFER];
45674 int i = 0;
45675
45676+ if (count > RDS_BUFFER)
45677+ return -EFAULT;
45678 mutex_lock(&dev->lock);
45679 if (dev->rdsstat == 0)
45680 cadet_start_rds(dev);
45681@@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
45682 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
45683 mutex_unlock(&dev->lock);
45684
45685- if (i && copy_to_user(data, readbuf, i))
45686- return -EFAULT;
45687+ if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
45688+ i = -EFAULT;
45689+
45690 return i;
45691 }
45692
45693diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
45694index 5236035..c622c74 100644
45695--- a/drivers/media/radio/radio-maxiradio.c
45696+++ b/drivers/media/radio/radio-maxiradio.c
45697@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
45698 /* TEA5757 pin mappings */
45699 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
45700
45701-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
45702+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
45703
45704 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
45705 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
45706diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
45707index 050b3bb..79f62b9 100644
45708--- a/drivers/media/radio/radio-shark.c
45709+++ b/drivers/media/radio/radio-shark.c
45710@@ -79,7 +79,7 @@ struct shark_device {
45711 u32 last_val;
45712 };
45713
45714-static atomic_t shark_instance = ATOMIC_INIT(0);
45715+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45716
45717 static void shark_write_val(struct snd_tea575x *tea, u32 val)
45718 {
45719diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
45720index 8654e0d..0608a64 100644
45721--- a/drivers/media/radio/radio-shark2.c
45722+++ b/drivers/media/radio/radio-shark2.c
45723@@ -74,7 +74,7 @@ struct shark_device {
45724 u8 *transfer_buffer;
45725 };
45726
45727-static atomic_t shark_instance = ATOMIC_INIT(0);
45728+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
45729
45730 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
45731 {
45732diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
45733index 633022b..7f10754 100644
45734--- a/drivers/media/radio/radio-si476x.c
45735+++ b/drivers/media/radio/radio-si476x.c
45736@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
45737 struct si476x_radio *radio;
45738 struct v4l2_ctrl *ctrl;
45739
45740- static atomic_t instance = ATOMIC_INIT(0);
45741+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
45742
45743 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
45744 if (!radio)
45745diff --git a/drivers/media/usb/dvb-usb/cinergyT2-core.c b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45746index 9fd1527..8927230 100644
45747--- a/drivers/media/usb/dvb-usb/cinergyT2-core.c
45748+++ b/drivers/media/usb/dvb-usb/cinergyT2-core.c
45749@@ -50,29 +50,73 @@ static struct dvb_usb_device_properties cinergyt2_properties;
45750
45751 static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
45752 {
45753- char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
45754- char result[64];
45755- return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
45756- sizeof(result), 0);
45757+ char *buf;
45758+ char *result;
45759+ int retval;
45760+
45761+ buf = kmalloc(2, GFP_KERNEL);
45762+ if (buf == NULL)
45763+ return -ENOMEM;
45764+ result = kmalloc(64, GFP_KERNEL);
45765+ if (result == NULL) {
45766+ kfree(buf);
45767+ return -ENOMEM;
45768+ }
45769+
45770+ buf[0] = CINERGYT2_EP1_CONTROL_STREAM_TRANSFER;
45771+ buf[1] = enable ? 1 : 0;
45772+
45773+ retval = dvb_usb_generic_rw(adap->dev, buf, 2, result, 64, 0);
45774+
45775+ kfree(buf);
45776+ kfree(result);
45777+ return retval;
45778 }
45779
45780 static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
45781 {
45782- char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
45783- char state[3];
45784- return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
45785+ char *buf;
45786+ char *state;
45787+ int retval;
45788+
45789+ buf = kmalloc(2, GFP_KERNEL);
45790+ if (buf == NULL)
45791+ return -ENOMEM;
45792+ state = kmalloc(3, GFP_KERNEL);
45793+ if (state == NULL) {
45794+ kfree(buf);
45795+ return -ENOMEM;
45796+ }
45797+
45798+ buf[0] = CINERGYT2_EP1_SLEEP_MODE;
45799+ buf[1] = enable ? 1 : 0;
45800+
45801+ retval = dvb_usb_generic_rw(d, buf, 2, state, 3, 0);
45802+
45803+ kfree(buf);
45804+ kfree(state);
45805+ return retval;
45806 }
45807
45808 static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45809 {
45810- char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
45811- char state[3];
45812+ char *query;
45813+ char *state;
45814 int ret;
45815+ query = kmalloc(1, GFP_KERNEL);
45816+ if (query == NULL)
45817+ return -ENOMEM;
45818+ state = kmalloc(3, GFP_KERNEL);
45819+ if (state == NULL) {
45820+ kfree(query);
45821+ return -ENOMEM;
45822+ }
45823+
45824+ query[0] = CINERGYT2_EP1_GET_FIRMWARE_VERSION;
45825
45826 adap->fe_adap[0].fe = cinergyt2_fe_attach(adap->dev);
45827
45828- ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
45829- sizeof(state), 0);
45830+ ret = dvb_usb_generic_rw(adap->dev, query, 1, state, 3, 0);
45831 if (ret < 0) {
45832 deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
45833 "state info\n");
45834@@ -80,7 +124,8 @@ static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
45835
45836 /* Copy this pointer as we are gonna need it in the release phase */
45837 cinergyt2_usb_device = adap->dev;
45838-
45839+ kfree(query);
45840+ kfree(state);
45841 return 0;
45842 }
45843
45844@@ -141,12 +186,23 @@ static int repeatable_keys[] = {
45845 static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45846 {
45847 struct cinergyt2_state *st = d->priv;
45848- u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
45849+ u8 *key, *cmd;
45850 int i;
45851
45852+ cmd = kmalloc(1, GFP_KERNEL);
45853+ if (cmd == NULL)
45854+ return -EINVAL;
45855+ key = kzalloc(5, GFP_KERNEL);
45856+ if (key == NULL) {
45857+ kfree(cmd);
45858+ return -EINVAL;
45859+ }
45860+
45861+ cmd[0] = CINERGYT2_EP1_GET_RC_EVENTS;
45862+
45863 *state = REMOTE_NO_KEY_PRESSED;
45864
45865- dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
45866+ dvb_usb_generic_rw(d, cmd, 1, key, 5, 0);
45867 if (key[4] == 0xff) {
45868 /* key repeat */
45869 st->rc_counter++;
45870@@ -157,12 +213,12 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45871 *event = d->last_event;
45872 deb_rc("repeat key, event %x\n",
45873 *event);
45874- return 0;
45875+ goto out;
45876 }
45877 }
45878 deb_rc("repeated key (non repeatable)\n");
45879 }
45880- return 0;
45881+ goto out;
45882 }
45883
45884 /* hack to pass checksum on the custom field */
45885@@ -174,6 +230,9 @@ static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
45886
45887 deb_rc("key: %*ph\n", 5, key);
45888 }
45889+out:
45890+ kfree(cmd);
45891+ kfree(key);
45892 return 0;
45893 }
45894
45895diff --git a/drivers/media/usb/dvb-usb/cinergyT2-fe.c b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45896index c890fe4..f9b2ae6 100644
45897--- a/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45898+++ b/drivers/media/usb/dvb-usb/cinergyT2-fe.c
45899@@ -145,103 +145,176 @@ static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
45900 fe_status_t *status)
45901 {
45902 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45903- struct dvbt_get_status_msg result;
45904- u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45905+ struct dvbt_get_status_msg *result;
45906+ u8 *cmd;
45907 int ret;
45908
45909- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
45910- sizeof(result), 0);
45911+ cmd = kmalloc(1, GFP_KERNEL);
45912+ if (cmd == NULL)
45913+ return -ENOMEM;
45914+ result = kmalloc(sizeof(*result), GFP_KERNEL);
45915+ if (result == NULL) {
45916+ kfree(cmd);
45917+ return -ENOMEM;
45918+ }
45919+
45920+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45921+
45922+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)result,
45923+ sizeof(*result), 0);
45924 if (ret < 0)
45925- return ret;
45926+ goto out;
45927
45928 *status = 0;
45929
45930- if (0xffff - le16_to_cpu(result.gain) > 30)
45931+ if (0xffff - le16_to_cpu(result->gain) > 30)
45932 *status |= FE_HAS_SIGNAL;
45933- if (result.lock_bits & (1 << 6))
45934+ if (result->lock_bits & (1 << 6))
45935 *status |= FE_HAS_LOCK;
45936- if (result.lock_bits & (1 << 5))
45937+ if (result->lock_bits & (1 << 5))
45938 *status |= FE_HAS_SYNC;
45939- if (result.lock_bits & (1 << 4))
45940+ if (result->lock_bits & (1 << 4))
45941 *status |= FE_HAS_CARRIER;
45942- if (result.lock_bits & (1 << 1))
45943+ if (result->lock_bits & (1 << 1))
45944 *status |= FE_HAS_VITERBI;
45945
45946 if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
45947 (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
45948 *status &= ~FE_HAS_LOCK;
45949
45950- return 0;
45951+out:
45952+ kfree(cmd);
45953+ kfree(result);
45954+ return ret;
45955 }
45956
45957 static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
45958 {
45959 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45960- struct dvbt_get_status_msg status;
45961- char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45962+ struct dvbt_get_status_msg *status;
45963+ char *cmd;
45964 int ret;
45965
45966- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
45967- sizeof(status), 0);
45968+ cmd = kmalloc(1, GFP_KERNEL);
45969+ if (cmd == NULL)
45970+ return -ENOMEM;
45971+ status = kmalloc(sizeof(*status), GFP_KERNEL);
45972+ if (status == NULL) {
45973+ kfree(cmd);
45974+ return -ENOMEM;
45975+ }
45976+
45977+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
45978+
45979+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
45980+ sizeof(*status), 0);
45981 if (ret < 0)
45982- return ret;
45983+ goto out;
45984
45985- *ber = le32_to_cpu(status.viterbi_error_rate);
45986+ *ber = le32_to_cpu(status->viterbi_error_rate);
45987+out:
45988+ kfree(cmd);
45989+ kfree(status);
45990 return 0;
45991 }
45992
45993 static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
45994 {
45995 struct cinergyt2_fe_state *state = fe->demodulator_priv;
45996- struct dvbt_get_status_msg status;
45997- u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
45998+ struct dvbt_get_status_msg *status;
45999+ u8 *cmd;
46000 int ret;
46001
46002- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
46003- sizeof(status), 0);
46004+ cmd = kmalloc(1, GFP_KERNEL);
46005+ if (cmd == NULL)
46006+ return -ENOMEM;
46007+ status = kmalloc(sizeof(*status), GFP_KERNEL);
46008+ if (status == NULL) {
46009+ kfree(cmd);
46010+ return -ENOMEM;
46011+ }
46012+
46013+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46014+
46015+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (u8 *)status,
46016+ sizeof(*status), 0);
46017 if (ret < 0) {
46018 err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
46019 ret);
46020- return ret;
46021+ goto out;
46022 }
46023- *unc = le32_to_cpu(status.uncorrected_block_count);
46024- return 0;
46025+ *unc = le32_to_cpu(status->uncorrected_block_count);
46026+
46027+out:
46028+ kfree(cmd);
46029+ kfree(status);
46030+ return ret;
46031 }
46032
46033 static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
46034 u16 *strength)
46035 {
46036 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46037- struct dvbt_get_status_msg status;
46038- char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46039+ struct dvbt_get_status_msg *status;
46040+ char *cmd;
46041 int ret;
46042
46043- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
46044- sizeof(status), 0);
46045+ cmd = kmalloc(1, GFP_KERNEL);
46046+ if (cmd == NULL)
46047+ return -ENOMEM;
46048+ status = kmalloc(sizeof(*status), GFP_KERNEL);
46049+ if (status == NULL) {
46050+ kfree(cmd);
46051+ return -ENOMEM;
46052+ }
46053+
46054+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46055+
46056+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
46057+ sizeof(*status), 0);
46058 if (ret < 0) {
46059 err("cinergyt2_fe_read_signal_strength() Failed!"
46060 " (Error=%d)\n", ret);
46061- return ret;
46062+ goto out;
46063 }
46064- *strength = (0xffff - le16_to_cpu(status.gain));
46065+ *strength = (0xffff - le16_to_cpu(status->gain));
46066+
46067+out:
46068+ kfree(cmd);
46069+ kfree(status);
46070 return 0;
46071 }
46072
46073 static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
46074 {
46075 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46076- struct dvbt_get_status_msg status;
46077- char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
46078+ struct dvbt_get_status_msg *status;
46079+ char *cmd;
46080 int ret;
46081
46082- ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
46083- sizeof(status), 0);
46084+ cmd = kmalloc(1, GFP_KERNEL);
46085+ if (cmd == NULL)
46086+ return -ENOMEM;
46087+ status = kmalloc(sizeof(*status), GFP_KERNEL);
46088+ if (status == NULL) {
46089+ kfree(cmd);
46090+ return -ENOMEM;
46091+ }
46092+
46093+ cmd[0] = CINERGYT2_EP1_GET_TUNER_STATUS;
46094+
46095+ ret = dvb_usb_generic_rw(state->d, cmd, 1, (char *)status,
46096+ sizeof(*status), 0);
46097 if (ret < 0) {
46098 err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
46099- return ret;
46100+ goto out;
46101 }
46102- *snr = (status.snr << 8) | status.snr;
46103- return 0;
46104+ *snr = (status->snr << 8) | status->snr;
46105+
46106+out:
46107+ kfree(cmd);
46108+ kfree(status);
46109+ return ret;
46110 }
46111
46112 static int cinergyt2_fe_init(struct dvb_frontend *fe)
46113@@ -266,35 +339,46 @@ static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe)
46114 {
46115 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
46116 struct cinergyt2_fe_state *state = fe->demodulator_priv;
46117- struct dvbt_set_parameters_msg param;
46118- char result[2];
46119+ struct dvbt_set_parameters_msg *param;
46120+ char *result;
46121 int err;
46122
46123- param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
46124- param.tps = cpu_to_le16(compute_tps(fep));
46125- param.freq = cpu_to_le32(fep->frequency / 1000);
46126- param.flags = 0;
46127+ result = kmalloc(2, GFP_KERNEL);
46128+ if (result == NULL)
46129+ return -ENOMEM;
46130+ param = kmalloc(sizeof(*param), GFP_KERNEL);
46131+ if (param == NULL) {
46132+ kfree(result);
46133+ return -ENOMEM;
46134+ }
46135+
46136+ param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
46137+ param->tps = cpu_to_le16(compute_tps(fep));
46138+ param->freq = cpu_to_le32(fep->frequency / 1000);
46139+ param->flags = 0;
46140
46141 switch (fep->bandwidth_hz) {
46142 default:
46143 case 8000000:
46144- param.bandwidth = 8;
46145+ param->bandwidth = 8;
46146 break;
46147 case 7000000:
46148- param.bandwidth = 7;
46149+ param->bandwidth = 7;
46150 break;
46151 case 6000000:
46152- param.bandwidth = 6;
46153+ param->bandwidth = 6;
46154 break;
46155 }
46156
46157 err = dvb_usb_generic_rw(state->d,
46158- (char *)&param, sizeof(param),
46159- result, sizeof(result), 0);
46160+ (char *)param, sizeof(*param),
46161+ result, 2, 0);
46162 if (err < 0)
46163 err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
46164
46165- return (err < 0) ? err : 0;
46166+ kfree(result);
46167+ kfree(param);
46168+ return err;
46169 }
46170
46171 static void cinergyt2_fe_release(struct dvb_frontend *fe)
46172diff --git a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46173index 733a7ff..f8b52e3 100644
46174--- a/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46175+++ b/drivers/media/usb/dvb-usb/dvb-usb-firmware.c
46176@@ -35,42 +35,57 @@ static int usb_cypress_writemem(struct usb_device *udev,u16 addr,u8 *data, u8 le
46177
46178 int usb_cypress_load_firmware(struct usb_device *udev, const struct firmware *fw, int type)
46179 {
46180- struct hexline hx;
46181- u8 reset;
46182+ struct hexline *hx;
46183+ u8 *reset;
46184 int ret,pos=0;
46185
46186+ reset = kmalloc(1, GFP_KERNEL);
46187+ if (reset == NULL)
46188+ return -ENOMEM;
46189+
46190+ hx = kmalloc(sizeof(struct hexline), GFP_KERNEL);
46191+ if (hx == NULL) {
46192+ kfree(reset);
46193+ return -ENOMEM;
46194+ }
46195+
46196 /* stop the CPU */
46197- reset = 1;
46198- if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1)) != 1)
46199+ reset[0] = 1;
46200+ if ((ret = usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1)) != 1)
46201 err("could not stop the USB controller CPU.");
46202
46203- while ((ret = dvb_usb_get_hexline(fw,&hx,&pos)) > 0) {
46204- deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx.addr,hx.len,hx.chk);
46205- ret = usb_cypress_writemem(udev,hx.addr,hx.data,hx.len);
46206+ while ((ret = dvb_usb_get_hexline(fw,hx,&pos)) > 0) {
46207+ deb_fw("writing to address 0x%04x (buffer: 0x%02x %02x)\n",hx->addr,hx->len,hx->chk);
46208+ ret = usb_cypress_writemem(udev,hx->addr,hx->data,hx->len);
46209
46210- if (ret != hx.len) {
46211+ if (ret != hx->len) {
46212 err("error while transferring firmware "
46213 "(transferred size: %d, block size: %d)",
46214- ret,hx.len);
46215+ ret,hx->len);
46216 ret = -EINVAL;
46217 break;
46218 }
46219 }
46220 if (ret < 0) {
46221 err("firmware download failed at %d with %d",pos,ret);
46222+ kfree(reset);
46223+ kfree(hx);
46224 return ret;
46225 }
46226
46227 if (ret == 0) {
46228 /* restart the CPU */
46229- reset = 0;
46230- if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,&reset,1) != 1) {
46231+ reset[0] = 0;
46232+ if (ret || usb_cypress_writemem(udev,cypress[type].cpu_cs_register,reset,1) != 1) {
46233 err("could not restart the USB controller CPU.");
46234 ret = -EINVAL;
46235 }
46236 } else
46237 ret = -EIO;
46238
46239+ kfree(reset);
46240+ kfree(hx);
46241+
46242 return ret;
46243 }
46244 EXPORT_SYMBOL(usb_cypress_load_firmware);
46245diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
46246index 2add8c5..c33b854 100644
46247--- a/drivers/media/usb/dvb-usb/dw2102.c
46248+++ b/drivers/media/usb/dvb-usb/dw2102.c
46249@@ -118,7 +118,7 @@ struct su3000_state {
46250
46251 struct s6x0_state {
46252 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
46253-};
46254+} __no_const;
46255
46256 /* debug */
46257 static int dvb_usb_dw2102_debug;
46258diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
46259index 6b0b8b6b..4038398 100644
46260--- a/drivers/media/usb/dvb-usb/technisat-usb2.c
46261+++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
46262@@ -87,8 +87,11 @@ struct technisat_usb2_state {
46263 static int technisat_usb2_i2c_access(struct usb_device *udev,
46264 u8 device_addr, u8 *tx, u8 txlen, u8 *rx, u8 rxlen)
46265 {
46266- u8 b[64];
46267- int ret, actual_length;
46268+ u8 *b = kmalloc(64, GFP_KERNEL);
46269+ int ret, actual_length, error = 0;
46270+
46271+ if (b == NULL)
46272+ return -ENOMEM;
46273
46274 deb_i2c("i2c-access: %02x, tx: ", device_addr);
46275 debug_dump(tx, txlen, deb_i2c);
46276@@ -121,7 +124,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46277
46278 if (ret < 0) {
46279 err("i2c-error: out failed %02x = %d", device_addr, ret);
46280- return -ENODEV;
46281+ error = -ENODEV;
46282+ goto out;
46283 }
46284
46285 ret = usb_bulk_msg(udev,
46286@@ -129,7 +133,8 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46287 b, 64, &actual_length, 1000);
46288 if (ret < 0) {
46289 err("i2c-error: in failed %02x = %d", device_addr, ret);
46290- return -ENODEV;
46291+ error = -ENODEV;
46292+ goto out;
46293 }
46294
46295 if (b[0] != I2C_STATUS_OK) {
46296@@ -137,8 +142,10 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46297 /* handle tuner-i2c-nak */
46298 if (!(b[0] == I2C_STATUS_NAK &&
46299 device_addr == 0x60
46300- /* && device_is_technisat_usb2 */))
46301- return -ENODEV;
46302+ /* && device_is_technisat_usb2 */)) {
46303+ error = -ENODEV;
46304+ goto out;
46305+ }
46306 }
46307
46308 deb_i2c("status: %d, ", b[0]);
46309@@ -152,7 +159,9 @@ static int technisat_usb2_i2c_access(struct usb_device *udev,
46310
46311 deb_i2c("\n");
46312
46313- return 0;
46314+out:
46315+ kfree(b);
46316+ return error;
46317 }
46318
46319 static int technisat_usb2_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
46320@@ -224,14 +233,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46321 {
46322 int ret;
46323
46324- u8 led[8] = {
46325- red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46326- 0
46327- };
46328+ u8 *led = kzalloc(8, GFP_KERNEL);
46329+
46330+ if (led == NULL)
46331+ return -ENOMEM;
46332
46333 if (disable_led_control && state != TECH_LED_OFF)
46334 return 0;
46335
46336+ led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
46337+
46338 switch (state) {
46339 case TECH_LED_ON:
46340 led[1] = 0x82;
46341@@ -263,16 +274,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
46342 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
46343 USB_TYPE_VENDOR | USB_DIR_OUT,
46344 0, 0,
46345- led, sizeof(led), 500);
46346+ led, 8, 500);
46347
46348 mutex_unlock(&d->i2c_mutex);
46349+
46350+ kfree(led);
46351+
46352 return ret;
46353 }
46354
46355 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
46356 {
46357 int ret;
46358- u8 b = 0;
46359+ u8 *b = kzalloc(1, GFP_KERNEL);
46360+
46361+ if (b == NULL)
46362+ return -ENOMEM;
46363
46364 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
46365 return -EAGAIN;
46366@@ -281,10 +298,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
46367 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
46368 USB_TYPE_VENDOR | USB_DIR_OUT,
46369 (red << 8) | green, 0,
46370- &b, 1, 500);
46371+ b, 1, 500);
46372
46373 mutex_unlock(&d->i2c_mutex);
46374
46375+ kfree(b);
46376+
46377 return ret;
46378 }
46379
46380@@ -328,7 +347,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46381 struct dvb_usb_device_description **desc, int *cold)
46382 {
46383 int ret;
46384- u8 version[3];
46385+ u8 *version = kmalloc(3, GFP_KERNEL);
46386
46387 /* first select the interface */
46388 if (usb_set_interface(udev, 0, 1) != 0)
46389@@ -338,11 +357,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46390
46391 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
46392
46393+ if (version == NULL)
46394+ return 0;
46395+
46396 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
46397 GET_VERSION_INFO_VENDOR_REQUEST,
46398 USB_TYPE_VENDOR | USB_DIR_IN,
46399 0, 0,
46400- version, sizeof(version), 500);
46401+ version, 3, 500);
46402
46403 if (ret < 0)
46404 *cold = 1;
46405@@ -351,6 +373,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
46406 *cold = 0;
46407 }
46408
46409+ kfree(version);
46410+
46411 return 0;
46412 }
46413
46414@@ -591,10 +615,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
46415
46416 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46417 {
46418- u8 buf[62], *b;
46419+ u8 *buf, *b;
46420 int ret;
46421 struct ir_raw_event ev;
46422
46423+ buf = kmalloc(62, GFP_KERNEL);
46424+
46425+ if (buf == NULL)
46426+ return -ENOMEM;
46427+
46428 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
46429 buf[1] = 0x08;
46430 buf[2] = 0x8f;
46431@@ -617,16 +646,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
46432 GET_IR_DATA_VENDOR_REQUEST,
46433 USB_TYPE_VENDOR | USB_DIR_IN,
46434 0x8080, 0,
46435- buf, sizeof(buf), 500);
46436+ buf, 62, 500);
46437
46438 unlock:
46439 mutex_unlock(&d->i2c_mutex);
46440
46441- if (ret < 0)
46442+ if (ret < 0) {
46443+ kfree(buf);
46444 return ret;
46445+ }
46446
46447- if (ret == 1)
46448+ if (ret == 1) {
46449+ kfree(buf);
46450 return 0; /* no key pressed */
46451+ }
46452
46453 /* decoding */
46454 b = buf+1;
46455@@ -653,6 +686,8 @@ unlock:
46456
46457 ir_raw_event_handle(d->rc_dev);
46458
46459+ kfree(buf);
46460+
46461 return 1;
46462 }
46463
46464diff --git a/drivers/media/usb/ttusb-dec/ttusbdecfe.c b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
46465index 5c45c9d..9c29552 100644
46466--- a/drivers/media/usb/ttusb-dec/ttusbdecfe.c
46467+++ b/drivers/media/usb/ttusb-dec/ttusbdecfe.c
46468@@ -156,6 +156,9 @@ static int ttusbdecfe_dvbs_diseqc_send_master_cmd(struct dvb_frontend* fe, struc
46469 0x00, 0x00, 0x00, 0x00,
46470 0x00, 0x00 };
46471
46472+ if (cmd->msg_len > sizeof(b) - 4)
46473+ return -EINVAL;
46474+
46475 memcpy(&b[4], cmd->msg, cmd->msg_len);
46476
46477 state->config->send_command(fe, 0x72,
46478diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46479index cca6c2f..77b9a18 100644
46480--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46481+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
46482@@ -328,7 +328,7 @@ struct v4l2_buffer32 {
46483 __u32 reserved;
46484 };
46485
46486-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
46487+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
46488 enum v4l2_memory memory)
46489 {
46490 void __user *up_pln;
46491@@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
46492 return 0;
46493 }
46494
46495-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
46496+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
46497 enum v4l2_memory memory)
46498 {
46499 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
46500@@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46501 * by passing a very big num_planes value */
46502 uplane = compat_alloc_user_space(num_planes *
46503 sizeof(struct v4l2_plane));
46504- kp->m.planes = uplane;
46505+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
46506
46507 while (--num_planes >= 0) {
46508 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
46509@@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
46510 if (num_planes == 0)
46511 return 0;
46512
46513- uplane = kp->m.planes;
46514+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
46515 if (get_user(p, &up->m.planes))
46516 return -EFAULT;
46517 uplane32 = compat_ptr(p);
46518@@ -562,7 +562,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
46519 get_user(kp->flags, &up->flags) ||
46520 copy_from_user(&kp->fmt, &up->fmt, sizeof(up->fmt)))
46521 return -EFAULT;
46522- kp->base = compat_ptr(tmp);
46523+ kp->base = (void __force_kernel *)compat_ptr(tmp);
46524 return 0;
46525 }
46526
46527@@ -667,7 +667,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46528 n * sizeof(struct v4l2_ext_control32)))
46529 return -EFAULT;
46530 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
46531- kp->controls = kcontrols;
46532+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
46533 while (--n >= 0) {
46534 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
46535 return -EFAULT;
46536@@ -689,7 +689,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
46537 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
46538 {
46539 struct v4l2_ext_control32 __user *ucontrols;
46540- struct v4l2_ext_control __user *kcontrols = kp->controls;
46541+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
46542 int n = kp->count;
46543 compat_caddr_t p;
46544
46545@@ -783,7 +783,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
46546 put_user(kp->start_block, &up->start_block) ||
46547 put_user(kp->blocks, &up->blocks) ||
46548 put_user(tmp, &up->edid) ||
46549- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
46550+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
46551 return -EFAULT;
46552 return 0;
46553 }
46554diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
46555index 015f92a..59e311e 100644
46556--- a/drivers/media/v4l2-core/v4l2-device.c
46557+++ b/drivers/media/v4l2-core/v4l2-device.c
46558@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
46559 EXPORT_SYMBOL_GPL(v4l2_device_put);
46560
46561 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
46562- atomic_t *instance)
46563+ atomic_unchecked_t *instance)
46564 {
46565- int num = atomic_inc_return(instance) - 1;
46566+ int num = atomic_inc_return_unchecked(instance) - 1;
46567 int len = strlen(basename);
46568
46569 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
46570diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
46571index d15e167..337f374 100644
46572--- a/drivers/media/v4l2-core/v4l2-ioctl.c
46573+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
46574@@ -2142,7 +2142,8 @@ struct v4l2_ioctl_info {
46575 struct file *file, void *fh, void *p);
46576 } u;
46577 void (*debug)(const void *arg, bool write_only);
46578-};
46579+} __do_const;
46580+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
46581
46582 /* This control needs a priority check */
46583 #define INFO_FL_PRIO (1 << 0)
46584@@ -2326,7 +2327,7 @@ static long __video_do_ioctl(struct file *file,
46585 struct video_device *vfd = video_devdata(file);
46586 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
46587 bool write_only = false;
46588- struct v4l2_ioctl_info default_info;
46589+ v4l2_ioctl_info_no_const default_info;
46590 const struct v4l2_ioctl_info *info;
46591 void *fh = file->private_data;
46592 struct v4l2_fh *vfh = NULL;
46593@@ -2413,7 +2414,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46594 ret = -EINVAL;
46595 break;
46596 }
46597- *user_ptr = (void __user *)buf->m.planes;
46598+ *user_ptr = (void __force_user *)buf->m.planes;
46599 *kernel_ptr = (void **)&buf->m.planes;
46600 *array_size = sizeof(struct v4l2_plane) * buf->length;
46601 ret = 1;
46602@@ -2430,7 +2431,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46603 ret = -EINVAL;
46604 break;
46605 }
46606- *user_ptr = (void __user *)edid->edid;
46607+ *user_ptr = (void __force_user *)edid->edid;
46608 *kernel_ptr = (void **)&edid->edid;
46609 *array_size = edid->blocks * 128;
46610 ret = 1;
46611@@ -2448,7 +2449,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
46612 ret = -EINVAL;
46613 break;
46614 }
46615- *user_ptr = (void __user *)ctrls->controls;
46616+ *user_ptr = (void __force_user *)ctrls->controls;
46617 *kernel_ptr = (void **)&ctrls->controls;
46618 *array_size = sizeof(struct v4l2_ext_control)
46619 * ctrls->count;
46620@@ -2549,7 +2550,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
46621 }
46622
46623 if (has_array_args) {
46624- *kernel_ptr = (void __force *)user_ptr;
46625+ *kernel_ptr = (void __force_kernel *)user_ptr;
46626 if (copy_to_user(user_ptr, mbuf, array_size))
46627 err = -EFAULT;
46628 goto out_array_args;
46629diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
46630index a896d94..a5d56b1 100644
46631--- a/drivers/message/fusion/mptbase.c
46632+++ b/drivers/message/fusion/mptbase.c
46633@@ -6752,8 +6752,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46634 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
46635 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
46636
46637+#ifdef CONFIG_GRKERNSEC_HIDESYM
46638+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
46639+#else
46640 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
46641 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
46642+#endif
46643+
46644 /*
46645 * Rounding UP to nearest 4-kB boundary here...
46646 */
46647@@ -6766,7 +6771,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
46648 ioc->facts.GlobalCredits);
46649
46650 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
46651+#ifdef CONFIG_GRKERNSEC_HIDESYM
46652+ NULL, NULL);
46653+#else
46654 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
46655+#endif
46656 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
46657 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
46658 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
46659diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
46660index 0707fa2..70ca794 100644
46661--- a/drivers/message/fusion/mptsas.c
46662+++ b/drivers/message/fusion/mptsas.c
46663@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
46664 return 0;
46665 }
46666
46667+static inline void
46668+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46669+{
46670+ if (phy_info->port_details) {
46671+ phy_info->port_details->rphy = rphy;
46672+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46673+ ioc->name, rphy));
46674+ }
46675+
46676+ if (rphy) {
46677+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46678+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46679+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46680+ ioc->name, rphy, rphy->dev.release));
46681+ }
46682+}
46683+
46684 /* no mutex */
46685 static void
46686 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
46687@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
46688 return NULL;
46689 }
46690
46691-static inline void
46692-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
46693-{
46694- if (phy_info->port_details) {
46695- phy_info->port_details->rphy = rphy;
46696- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
46697- ioc->name, rphy));
46698- }
46699-
46700- if (rphy) {
46701- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
46702- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
46703- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
46704- ioc->name, rphy, rphy->dev.release));
46705- }
46706-}
46707-
46708 static inline struct sas_port *
46709 mptsas_get_port(struct mptsas_phyinfo *phy_info)
46710 {
46711diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
46712index b7d87cd..3fb36da 100644
46713--- a/drivers/message/i2o/i2o_proc.c
46714+++ b/drivers/message/i2o/i2o_proc.c
46715@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
46716 "Array Controller Device"
46717 };
46718
46719-static char *chtostr(char *tmp, u8 *chars, int n)
46720-{
46721- tmp[0] = 0;
46722- return strncat(tmp, (char *)chars, n);
46723-}
46724-
46725 static int i2o_report_query_status(struct seq_file *seq, int block_status,
46726 char *group)
46727 {
46728@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
46729 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
46730 {
46731 struct i2o_controller *c = (struct i2o_controller *)seq->private;
46732- static u32 work32[5];
46733- static u8 *work8 = (u8 *) work32;
46734- static u16 *work16 = (u16 *) work32;
46735+ u32 work32[5];
46736+ u8 *work8 = (u8 *) work32;
46737+ u16 *work16 = (u16 *) work32;
46738 int token;
46739 u32 hwcap;
46740
46741@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46742 } *result;
46743
46744 i2o_exec_execute_ddm_table ddm_table;
46745- char tmp[28 + 1];
46746
46747 result = kmalloc(sizeof(*result), GFP_KERNEL);
46748 if (!result)
46749@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
46750
46751 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
46752 seq_printf(seq, "%-#8x", ddm_table.module_id);
46753- seq_printf(seq, "%-29s",
46754- chtostr(tmp, ddm_table.module_name_version, 28));
46755+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
46756 seq_printf(seq, "%9d ", ddm_table.data_size);
46757 seq_printf(seq, "%8d", ddm_table.code_size);
46758
46759@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46760
46761 i2o_driver_result_table *result;
46762 i2o_driver_store_table *dst;
46763- char tmp[28 + 1];
46764
46765 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
46766 if (result == NULL)
46767@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
46768
46769 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
46770 seq_printf(seq, "%-#8x", dst->module_id);
46771- seq_printf(seq, "%-29s",
46772- chtostr(tmp, dst->module_name_version, 28));
46773- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
46774+ seq_printf(seq, "%-.28s", dst->module_name_version);
46775+ seq_printf(seq, "%-.8s", dst->date);
46776 seq_printf(seq, "%8d ", dst->module_size);
46777 seq_printf(seq, "%8d ", dst->mpb_size);
46778 seq_printf(seq, "0x%04x", dst->module_flags);
46779@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
46780 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46781 {
46782 struct i2o_device *d = (struct i2o_device *)seq->private;
46783- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46784+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
46785 // == (allow) 512d bytes (max)
46786- static u16 *work16 = (u16 *) work32;
46787+ u16 *work16 = (u16 *) work32;
46788 int token;
46789- char tmp[16 + 1];
46790
46791 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
46792
46793@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
46794 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
46795 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
46796 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
46797- seq_printf(seq, "Vendor info : %s\n",
46798- chtostr(tmp, (u8 *) (work32 + 2), 16));
46799- seq_printf(seq, "Product info : %s\n",
46800- chtostr(tmp, (u8 *) (work32 + 6), 16));
46801- seq_printf(seq, "Description : %s\n",
46802- chtostr(tmp, (u8 *) (work32 + 10), 16));
46803- seq_printf(seq, "Product rev. : %s\n",
46804- chtostr(tmp, (u8 *) (work32 + 14), 8));
46805+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
46806+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
46807+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
46808+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
46809
46810 seq_printf(seq, "Serial number : ");
46811 print_serial_number(seq, (u8 *) (work32 + 16),
46812@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46813 u8 pad[256]; // allow up to 256 byte (max) serial number
46814 } result;
46815
46816- char tmp[24 + 1];
46817-
46818 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
46819
46820 if (token < 0) {
46821@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
46822 }
46823
46824 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
46825- seq_printf(seq, "Module name : %s\n",
46826- chtostr(tmp, result.module_name, 24));
46827- seq_printf(seq, "Module revision : %s\n",
46828- chtostr(tmp, result.module_rev, 8));
46829+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
46830+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
46831
46832 seq_printf(seq, "Serial number : ");
46833 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
46834@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46835 u8 instance_number[4];
46836 } result;
46837
46838- char tmp[64 + 1];
46839-
46840 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
46841
46842 if (token < 0) {
46843@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46844 return 0;
46845 }
46846
46847- seq_printf(seq, "Device name : %s\n",
46848- chtostr(tmp, result.device_name, 64));
46849- seq_printf(seq, "Service name : %s\n",
46850- chtostr(tmp, result.service_name, 64));
46851- seq_printf(seq, "Physical name : %s\n",
46852- chtostr(tmp, result.physical_location, 64));
46853- seq_printf(seq, "Instance number : %s\n",
46854- chtostr(tmp, result.instance_number, 4));
46855+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
46856+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
46857+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
46858+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
46859
46860 return 0;
46861 }
46862@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
46863 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
46864 {
46865 struct i2o_device *d = (struct i2o_device *)seq->private;
46866- static u32 work32[12];
46867- static u16 *work16 = (u16 *) work32;
46868- static u8 *work8 = (u8 *) work32;
46869+ u32 work32[12];
46870+ u16 *work16 = (u16 *) work32;
46871+ u8 *work8 = (u8 *) work32;
46872 int token;
46873
46874 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
46875diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
46876index 92752fb..a7494f6 100644
46877--- a/drivers/message/i2o/iop.c
46878+++ b/drivers/message/i2o/iop.c
46879@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
46880
46881 spin_lock_irqsave(&c->context_list_lock, flags);
46882
46883- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
46884- atomic_inc(&c->context_list_counter);
46885+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
46886+ atomic_inc_unchecked(&c->context_list_counter);
46887
46888- entry->context = atomic_read(&c->context_list_counter);
46889+ entry->context = atomic_read_unchecked(&c->context_list_counter);
46890
46891 list_add(&entry->list, &c->context_list);
46892
46893@@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
46894
46895 #if BITS_PER_LONG == 64
46896 spin_lock_init(&c->context_list_lock);
46897- atomic_set(&c->context_list_counter, 0);
46898+ atomic_set_unchecked(&c->context_list_counter, 0);
46899 INIT_LIST_HEAD(&c->context_list);
46900 #endif
46901
46902diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
46903index b2c7e3b..85aa4764 100644
46904--- a/drivers/mfd/ab8500-debugfs.c
46905+++ b/drivers/mfd/ab8500-debugfs.c
46906@@ -100,7 +100,7 @@ static int irq_last;
46907 static u32 *irq_count;
46908 static int num_irqs;
46909
46910-static struct device_attribute **dev_attr;
46911+static device_attribute_no_const **dev_attr;
46912 static char **event_name;
46913
46914 static u8 avg_sample = SAMPLE_16;
46915diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
46916index ecbe78e..b2ca870 100644
46917--- a/drivers/mfd/max8925-i2c.c
46918+++ b/drivers/mfd/max8925-i2c.c
46919@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
46920 const struct i2c_device_id *id)
46921 {
46922 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
46923- static struct max8925_chip *chip;
46924+ struct max8925_chip *chip;
46925 struct device_node *node = client->dev.of_node;
46926
46927 if (node && !pdata) {
46928diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
46929index f243e75..322176c 100644
46930--- a/drivers/mfd/tps65910.c
46931+++ b/drivers/mfd/tps65910.c
46932@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
46933 struct tps65910_platform_data *pdata)
46934 {
46935 int ret = 0;
46936- static struct regmap_irq_chip *tps6591x_irqs_chip;
46937+ struct regmap_irq_chip *tps6591x_irqs_chip;
46938
46939 if (!irq) {
46940 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
46941diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
46942index b1dabba..24a88f2 100644
46943--- a/drivers/mfd/twl4030-irq.c
46944+++ b/drivers/mfd/twl4030-irq.c
46945@@ -34,6 +34,7 @@
46946 #include <linux/of.h>
46947 #include <linux/irqdomain.h>
46948 #include <linux/i2c/twl.h>
46949+#include <asm/pgtable.h>
46950
46951 #include "twl-core.h"
46952
46953@@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
46954 * Install an irq handler for each of the SIH modules;
46955 * clone dummy irq_chip since PIH can't *do* anything
46956 */
46957- twl4030_irq_chip = dummy_irq_chip;
46958- twl4030_irq_chip.name = "twl4030";
46959+ pax_open_kernel();
46960+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
46961+ *(const char **)&twl4030_irq_chip.name = "twl4030";
46962
46963- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46964+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
46965+ pax_close_kernel();
46966
46967 for (i = irq_base; i < irq_end; i++) {
46968 irq_set_chip_and_handler(i, &twl4030_irq_chip,
46969diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
46970index 464419b..64bae8d 100644
46971--- a/drivers/misc/c2port/core.c
46972+++ b/drivers/misc/c2port/core.c
46973@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
46974 goto error_idr_alloc;
46975 c2dev->id = ret;
46976
46977- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46978+ pax_open_kernel();
46979+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
46980+ pax_close_kernel();
46981
46982 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
46983 "c2port%d", c2dev->id);
46984diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
46985index 3f2b625..945e179 100644
46986--- a/drivers/misc/eeprom/sunxi_sid.c
46987+++ b/drivers/misc/eeprom/sunxi_sid.c
46988@@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
46989
46990 platform_set_drvdata(pdev, sid_data);
46991
46992- sid_bin_attr.size = sid_data->keysize;
46993+ pax_open_kernel();
46994+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
46995+ pax_close_kernel();
46996 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
46997 return -ENODEV;
46998
46999diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
47000index 36f5d52..32311c3 100644
47001--- a/drivers/misc/kgdbts.c
47002+++ b/drivers/misc/kgdbts.c
47003@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
47004 char before[BREAK_INSTR_SIZE];
47005 char after[BREAK_INSTR_SIZE];
47006
47007- probe_kernel_read(before, (char *)kgdbts_break_test,
47008+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
47009 BREAK_INSTR_SIZE);
47010 init_simple_test();
47011 ts.tst = plant_and_detach_test;
47012@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
47013 /* Activate test with initial breakpoint */
47014 if (!is_early)
47015 kgdb_breakpoint();
47016- probe_kernel_read(after, (char *)kgdbts_break_test,
47017+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
47018 BREAK_INSTR_SIZE);
47019 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
47020 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
47021diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
47022index 3ef4627..8d00486 100644
47023--- a/drivers/misc/lis3lv02d/lis3lv02d.c
47024+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
47025@@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
47026 * the lid is closed. This leads to interrupts as soon as a little move
47027 * is done.
47028 */
47029- atomic_inc(&lis3->count);
47030+ atomic_inc_unchecked(&lis3->count);
47031
47032 wake_up_interruptible(&lis3->misc_wait);
47033 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
47034@@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
47035 if (lis3->pm_dev)
47036 pm_runtime_get_sync(lis3->pm_dev);
47037
47038- atomic_set(&lis3->count, 0);
47039+ atomic_set_unchecked(&lis3->count, 0);
47040 return 0;
47041 }
47042
47043@@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
47044 add_wait_queue(&lis3->misc_wait, &wait);
47045 while (true) {
47046 set_current_state(TASK_INTERRUPTIBLE);
47047- data = atomic_xchg(&lis3->count, 0);
47048+ data = atomic_xchg_unchecked(&lis3->count, 0);
47049 if (data)
47050 break;
47051
47052@@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
47053 struct lis3lv02d, miscdev);
47054
47055 poll_wait(file, &lis3->misc_wait, wait);
47056- if (atomic_read(&lis3->count))
47057+ if (atomic_read_unchecked(&lis3->count))
47058 return POLLIN | POLLRDNORM;
47059 return 0;
47060 }
47061diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
47062index c439c82..1f20f57 100644
47063--- a/drivers/misc/lis3lv02d/lis3lv02d.h
47064+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
47065@@ -297,7 +297,7 @@ struct lis3lv02d {
47066 struct input_polled_dev *idev; /* input device */
47067 struct platform_device *pdev; /* platform device */
47068 struct regulator_bulk_data regulators[2];
47069- atomic_t count; /* interrupt count after last read */
47070+ atomic_unchecked_t count; /* interrupt count after last read */
47071 union axis_conversion ac; /* hw -> logical axis */
47072 int mapped_btns[3];
47073
47074diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
47075index 2f30bad..c4c13d0 100644
47076--- a/drivers/misc/sgi-gru/gruhandles.c
47077+++ b/drivers/misc/sgi-gru/gruhandles.c
47078@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
47079 unsigned long nsec;
47080
47081 nsec = CLKS2NSEC(clks);
47082- atomic_long_inc(&mcs_op_statistics[op].count);
47083- atomic_long_add(nsec, &mcs_op_statistics[op].total);
47084+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
47085+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
47086 if (mcs_op_statistics[op].max < nsec)
47087 mcs_op_statistics[op].max = nsec;
47088 }
47089diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
47090index 4f76359..cdfcb2e 100644
47091--- a/drivers/misc/sgi-gru/gruprocfs.c
47092+++ b/drivers/misc/sgi-gru/gruprocfs.c
47093@@ -32,9 +32,9 @@
47094
47095 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
47096
47097-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
47098+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
47099 {
47100- unsigned long val = atomic_long_read(v);
47101+ unsigned long val = atomic_long_read_unchecked(v);
47102
47103 seq_printf(s, "%16lu %s\n", val, id);
47104 }
47105@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
47106
47107 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
47108 for (op = 0; op < mcsop_last; op++) {
47109- count = atomic_long_read(&mcs_op_statistics[op].count);
47110- total = atomic_long_read(&mcs_op_statistics[op].total);
47111+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
47112+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
47113 max = mcs_op_statistics[op].max;
47114 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
47115 count ? total / count : 0, max);
47116diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
47117index 5c3ce24..4915ccb 100644
47118--- a/drivers/misc/sgi-gru/grutables.h
47119+++ b/drivers/misc/sgi-gru/grutables.h
47120@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
47121 * GRU statistics.
47122 */
47123 struct gru_stats_s {
47124- atomic_long_t vdata_alloc;
47125- atomic_long_t vdata_free;
47126- atomic_long_t gts_alloc;
47127- atomic_long_t gts_free;
47128- atomic_long_t gms_alloc;
47129- atomic_long_t gms_free;
47130- atomic_long_t gts_double_allocate;
47131- atomic_long_t assign_context;
47132- atomic_long_t assign_context_failed;
47133- atomic_long_t free_context;
47134- atomic_long_t load_user_context;
47135- atomic_long_t load_kernel_context;
47136- atomic_long_t lock_kernel_context;
47137- atomic_long_t unlock_kernel_context;
47138- atomic_long_t steal_user_context;
47139- atomic_long_t steal_kernel_context;
47140- atomic_long_t steal_context_failed;
47141- atomic_long_t nopfn;
47142- atomic_long_t asid_new;
47143- atomic_long_t asid_next;
47144- atomic_long_t asid_wrap;
47145- atomic_long_t asid_reuse;
47146- atomic_long_t intr;
47147- atomic_long_t intr_cbr;
47148- atomic_long_t intr_tfh;
47149- atomic_long_t intr_spurious;
47150- atomic_long_t intr_mm_lock_failed;
47151- atomic_long_t call_os;
47152- atomic_long_t call_os_wait_queue;
47153- atomic_long_t user_flush_tlb;
47154- atomic_long_t user_unload_context;
47155- atomic_long_t user_exception;
47156- atomic_long_t set_context_option;
47157- atomic_long_t check_context_retarget_intr;
47158- atomic_long_t check_context_unload;
47159- atomic_long_t tlb_dropin;
47160- atomic_long_t tlb_preload_page;
47161- atomic_long_t tlb_dropin_fail_no_asid;
47162- atomic_long_t tlb_dropin_fail_upm;
47163- atomic_long_t tlb_dropin_fail_invalid;
47164- atomic_long_t tlb_dropin_fail_range_active;
47165- atomic_long_t tlb_dropin_fail_idle;
47166- atomic_long_t tlb_dropin_fail_fmm;
47167- atomic_long_t tlb_dropin_fail_no_exception;
47168- atomic_long_t tfh_stale_on_fault;
47169- atomic_long_t mmu_invalidate_range;
47170- atomic_long_t mmu_invalidate_page;
47171- atomic_long_t flush_tlb;
47172- atomic_long_t flush_tlb_gru;
47173- atomic_long_t flush_tlb_gru_tgh;
47174- atomic_long_t flush_tlb_gru_zero_asid;
47175+ atomic_long_unchecked_t vdata_alloc;
47176+ atomic_long_unchecked_t vdata_free;
47177+ atomic_long_unchecked_t gts_alloc;
47178+ atomic_long_unchecked_t gts_free;
47179+ atomic_long_unchecked_t gms_alloc;
47180+ atomic_long_unchecked_t gms_free;
47181+ atomic_long_unchecked_t gts_double_allocate;
47182+ atomic_long_unchecked_t assign_context;
47183+ atomic_long_unchecked_t assign_context_failed;
47184+ atomic_long_unchecked_t free_context;
47185+ atomic_long_unchecked_t load_user_context;
47186+ atomic_long_unchecked_t load_kernel_context;
47187+ atomic_long_unchecked_t lock_kernel_context;
47188+ atomic_long_unchecked_t unlock_kernel_context;
47189+ atomic_long_unchecked_t steal_user_context;
47190+ atomic_long_unchecked_t steal_kernel_context;
47191+ atomic_long_unchecked_t steal_context_failed;
47192+ atomic_long_unchecked_t nopfn;
47193+ atomic_long_unchecked_t asid_new;
47194+ atomic_long_unchecked_t asid_next;
47195+ atomic_long_unchecked_t asid_wrap;
47196+ atomic_long_unchecked_t asid_reuse;
47197+ atomic_long_unchecked_t intr;
47198+ atomic_long_unchecked_t intr_cbr;
47199+ atomic_long_unchecked_t intr_tfh;
47200+ atomic_long_unchecked_t intr_spurious;
47201+ atomic_long_unchecked_t intr_mm_lock_failed;
47202+ atomic_long_unchecked_t call_os;
47203+ atomic_long_unchecked_t call_os_wait_queue;
47204+ atomic_long_unchecked_t user_flush_tlb;
47205+ atomic_long_unchecked_t user_unload_context;
47206+ atomic_long_unchecked_t user_exception;
47207+ atomic_long_unchecked_t set_context_option;
47208+ atomic_long_unchecked_t check_context_retarget_intr;
47209+ atomic_long_unchecked_t check_context_unload;
47210+ atomic_long_unchecked_t tlb_dropin;
47211+ atomic_long_unchecked_t tlb_preload_page;
47212+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
47213+ atomic_long_unchecked_t tlb_dropin_fail_upm;
47214+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
47215+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
47216+ atomic_long_unchecked_t tlb_dropin_fail_idle;
47217+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
47218+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
47219+ atomic_long_unchecked_t tfh_stale_on_fault;
47220+ atomic_long_unchecked_t mmu_invalidate_range;
47221+ atomic_long_unchecked_t mmu_invalidate_page;
47222+ atomic_long_unchecked_t flush_tlb;
47223+ atomic_long_unchecked_t flush_tlb_gru;
47224+ atomic_long_unchecked_t flush_tlb_gru_tgh;
47225+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
47226
47227- atomic_long_t copy_gpa;
47228- atomic_long_t read_gpa;
47229+ atomic_long_unchecked_t copy_gpa;
47230+ atomic_long_unchecked_t read_gpa;
47231
47232- atomic_long_t mesq_receive;
47233- atomic_long_t mesq_receive_none;
47234- atomic_long_t mesq_send;
47235- atomic_long_t mesq_send_failed;
47236- atomic_long_t mesq_noop;
47237- atomic_long_t mesq_send_unexpected_error;
47238- atomic_long_t mesq_send_lb_overflow;
47239- atomic_long_t mesq_send_qlimit_reached;
47240- atomic_long_t mesq_send_amo_nacked;
47241- atomic_long_t mesq_send_put_nacked;
47242- atomic_long_t mesq_page_overflow;
47243- atomic_long_t mesq_qf_locked;
47244- atomic_long_t mesq_qf_noop_not_full;
47245- atomic_long_t mesq_qf_switch_head_failed;
47246- atomic_long_t mesq_qf_unexpected_error;
47247- atomic_long_t mesq_noop_unexpected_error;
47248- atomic_long_t mesq_noop_lb_overflow;
47249- atomic_long_t mesq_noop_qlimit_reached;
47250- atomic_long_t mesq_noop_amo_nacked;
47251- atomic_long_t mesq_noop_put_nacked;
47252- atomic_long_t mesq_noop_page_overflow;
47253+ atomic_long_unchecked_t mesq_receive;
47254+ atomic_long_unchecked_t mesq_receive_none;
47255+ atomic_long_unchecked_t mesq_send;
47256+ atomic_long_unchecked_t mesq_send_failed;
47257+ atomic_long_unchecked_t mesq_noop;
47258+ atomic_long_unchecked_t mesq_send_unexpected_error;
47259+ atomic_long_unchecked_t mesq_send_lb_overflow;
47260+ atomic_long_unchecked_t mesq_send_qlimit_reached;
47261+ atomic_long_unchecked_t mesq_send_amo_nacked;
47262+ atomic_long_unchecked_t mesq_send_put_nacked;
47263+ atomic_long_unchecked_t mesq_page_overflow;
47264+ atomic_long_unchecked_t mesq_qf_locked;
47265+ atomic_long_unchecked_t mesq_qf_noop_not_full;
47266+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
47267+ atomic_long_unchecked_t mesq_qf_unexpected_error;
47268+ atomic_long_unchecked_t mesq_noop_unexpected_error;
47269+ atomic_long_unchecked_t mesq_noop_lb_overflow;
47270+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
47271+ atomic_long_unchecked_t mesq_noop_amo_nacked;
47272+ atomic_long_unchecked_t mesq_noop_put_nacked;
47273+ atomic_long_unchecked_t mesq_noop_page_overflow;
47274
47275 };
47276
47277@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
47278 tghop_invalidate, mcsop_last};
47279
47280 struct mcs_op_statistic {
47281- atomic_long_t count;
47282- atomic_long_t total;
47283+ atomic_long_unchecked_t count;
47284+ atomic_long_unchecked_t total;
47285 unsigned long max;
47286 };
47287
47288@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
47289
47290 #define STAT(id) do { \
47291 if (gru_options & OPT_STATS) \
47292- atomic_long_inc(&gru_stats.id); \
47293+ atomic_long_inc_unchecked(&gru_stats.id); \
47294 } while (0)
47295
47296 #ifdef CONFIG_SGI_GRU_DEBUG
47297diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
47298index c862cd4..0d176fe 100644
47299--- a/drivers/misc/sgi-xp/xp.h
47300+++ b/drivers/misc/sgi-xp/xp.h
47301@@ -288,7 +288,7 @@ struct xpc_interface {
47302 xpc_notify_func, void *);
47303 void (*received) (short, int, void *);
47304 enum xp_retval (*partid_to_nasids) (short, void *);
47305-};
47306+} __no_const;
47307
47308 extern struct xpc_interface xpc_interface;
47309
47310diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
47311index 01be66d..e3a0c7e 100644
47312--- a/drivers/misc/sgi-xp/xp_main.c
47313+++ b/drivers/misc/sgi-xp/xp_main.c
47314@@ -78,13 +78,13 @@ xpc_notloaded(void)
47315 }
47316
47317 struct xpc_interface xpc_interface = {
47318- (void (*)(int))xpc_notloaded,
47319- (void (*)(int))xpc_notloaded,
47320- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
47321- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
47322+ .connect = (void (*)(int))xpc_notloaded,
47323+ .disconnect = (void (*)(int))xpc_notloaded,
47324+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
47325+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
47326 void *))xpc_notloaded,
47327- (void (*)(short, int, void *))xpc_notloaded,
47328- (enum xp_retval(*)(short, void *))xpc_notloaded
47329+ .received = (void (*)(short, int, void *))xpc_notloaded,
47330+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
47331 };
47332 EXPORT_SYMBOL_GPL(xpc_interface);
47333
47334diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
47335index b94d5f7..7f494c5 100644
47336--- a/drivers/misc/sgi-xp/xpc.h
47337+++ b/drivers/misc/sgi-xp/xpc.h
47338@@ -835,6 +835,7 @@ struct xpc_arch_operations {
47339 void (*received_payload) (struct xpc_channel *, void *);
47340 void (*notify_senders_of_disconnect) (struct xpc_channel *);
47341 };
47342+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
47343
47344 /* struct xpc_partition act_state values (for XPC HB) */
47345
47346@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
47347 /* found in xpc_main.c */
47348 extern struct device *xpc_part;
47349 extern struct device *xpc_chan;
47350-extern struct xpc_arch_operations xpc_arch_ops;
47351+extern xpc_arch_operations_no_const xpc_arch_ops;
47352 extern int xpc_disengage_timelimit;
47353 extern int xpc_disengage_timedout;
47354 extern int xpc_activate_IRQ_rcvd;
47355diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
47356index 82dc574..8539ab2 100644
47357--- a/drivers/misc/sgi-xp/xpc_main.c
47358+++ b/drivers/misc/sgi-xp/xpc_main.c
47359@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
47360 .notifier_call = xpc_system_die,
47361 };
47362
47363-struct xpc_arch_operations xpc_arch_ops;
47364+xpc_arch_operations_no_const xpc_arch_ops;
47365
47366 /*
47367 * Timer function to enforce the timelimit on the partition disengage.
47368@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
47369
47370 if (((die_args->trapnr == X86_TRAP_MF) ||
47371 (die_args->trapnr == X86_TRAP_XF)) &&
47372- !user_mode_vm(die_args->regs))
47373+ !user_mode(die_args->regs))
47374 xpc_die_deactivate();
47375
47376 break;
47377diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
47378index ede41f0..744fbd9 100644
47379--- a/drivers/mmc/card/block.c
47380+++ b/drivers/mmc/card/block.c
47381@@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
47382 if (idata->ic.postsleep_min_us)
47383 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
47384
47385- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
47386+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
47387 err = -EFAULT;
47388 goto cmd_rel_host;
47389 }
47390diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
47391index f51b5ba..86614a7 100644
47392--- a/drivers/mmc/core/mmc_ops.c
47393+++ b/drivers/mmc/core/mmc_ops.c
47394@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
47395 void *data_buf;
47396 int is_on_stack;
47397
47398- is_on_stack = object_is_on_stack(buf);
47399+ is_on_stack = object_starts_on_stack(buf);
47400 if (is_on_stack) {
47401 /*
47402 * dma onto stack is unsafe/nonportable, but callers to this
47403diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
47404index 08fd956..370487a 100644
47405--- a/drivers/mmc/host/dw_mmc.h
47406+++ b/drivers/mmc/host/dw_mmc.h
47407@@ -262,5 +262,5 @@ struct dw_mci_drv_data {
47408 int (*parse_dt)(struct dw_mci *host);
47409 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
47410 struct dw_mci_tuning_data *tuning_data);
47411-};
47412+} __do_const;
47413 #endif /* _DW_MMC_H_ */
47414diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
47415index e4d4707..28262a3 100644
47416--- a/drivers/mmc/host/mmci.c
47417+++ b/drivers/mmc/host/mmci.c
47418@@ -1612,7 +1612,9 @@ static int mmci_probe(struct amba_device *dev,
47419 mmc->caps |= MMC_CAP_CMD23;
47420
47421 if (variant->busy_detect) {
47422- mmci_ops.card_busy = mmci_card_busy;
47423+ pax_open_kernel();
47424+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
47425+ pax_close_kernel();
47426 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
47427 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
47428 mmc->max_busy_timeout = 0;
47429diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
47430index ccec0e3..199f9ce 100644
47431--- a/drivers/mmc/host/sdhci-esdhc-imx.c
47432+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
47433@@ -1034,9 +1034,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
47434 host->mmc->caps |= MMC_CAP_1_8V_DDR;
47435 }
47436
47437- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
47438- sdhci_esdhc_ops.platform_execute_tuning =
47439+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
47440+ pax_open_kernel();
47441+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
47442 esdhc_executing_tuning;
47443+ pax_close_kernel();
47444+ }
47445
47446 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
47447 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
47448diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
47449index 1e47903..7683916 100644
47450--- a/drivers/mmc/host/sdhci-s3c.c
47451+++ b/drivers/mmc/host/sdhci-s3c.c
47452@@ -584,9 +584,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
47453 * we can use overriding functions instead of default.
47454 */
47455 if (sc->no_divider) {
47456- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47457- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47458- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47459+ pax_open_kernel();
47460+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
47461+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
47462+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
47463+ pax_close_kernel();
47464 }
47465
47466 /* It supports additional host capabilities if needed */
47467diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
47468index 423666b..81ff5eb 100644
47469--- a/drivers/mtd/chips/cfi_cmdset_0020.c
47470+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
47471@@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
47472 size_t totlen = 0, thislen;
47473 int ret = 0;
47474 size_t buflen = 0;
47475- static char *buffer;
47476+ char *buffer;
47477
47478 if (!ECCBUF_SIZE) {
47479 /* We should fall back to a general writev implementation.
47480diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
47481index 0b071a3..8ec3d5b 100644
47482--- a/drivers/mtd/nand/denali.c
47483+++ b/drivers/mtd/nand/denali.c
47484@@ -24,6 +24,7 @@
47485 #include <linux/slab.h>
47486 #include <linux/mtd/mtd.h>
47487 #include <linux/module.h>
47488+#include <linux/slab.h>
47489
47490 #include "denali.h"
47491
47492diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47493index 959cb9b..8520fe5 100644
47494--- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47495+++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
47496@@ -386,7 +386,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
47497
47498 /* first try to map the upper buffer directly */
47499 if (virt_addr_valid(this->upper_buf) &&
47500- !object_is_on_stack(this->upper_buf)) {
47501+ !object_starts_on_stack(this->upper_buf)) {
47502 sg_init_one(sgl, this->upper_buf, this->upper_len);
47503 ret = dma_map_sg(this->dev, sgl, 1, dr);
47504 if (ret == 0)
47505diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
47506index 51b9d6a..52af9a7 100644
47507--- a/drivers/mtd/nftlmount.c
47508+++ b/drivers/mtd/nftlmount.c
47509@@ -24,6 +24,7 @@
47510 #include <asm/errno.h>
47511 #include <linux/delay.h>
47512 #include <linux/slab.h>
47513+#include <linux/sched.h>
47514 #include <linux/mtd/mtd.h>
47515 #include <linux/mtd/nand.h>
47516 #include <linux/mtd/nftl.h>
47517diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
47518index cf49c22..971b133 100644
47519--- a/drivers/mtd/sm_ftl.c
47520+++ b/drivers/mtd/sm_ftl.c
47521@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
47522 #define SM_CIS_VENDOR_OFFSET 0x59
47523 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
47524 {
47525- struct attribute_group *attr_group;
47526+ attribute_group_no_const *attr_group;
47527 struct attribute **attributes;
47528 struct sm_sysfs_attribute *vendor_attribute;
47529 char *vendor;
47530diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
47531index d163e11..f517018 100644
47532--- a/drivers/net/bonding/bond_netlink.c
47533+++ b/drivers/net/bonding/bond_netlink.c
47534@@ -548,7 +548,7 @@ nla_put_failure:
47535 return -EMSGSIZE;
47536 }
47537
47538-struct rtnl_link_ops bond_link_ops __read_mostly = {
47539+struct rtnl_link_ops bond_link_ops = {
47540 .kind = "bond",
47541 .priv_size = sizeof(struct bonding),
47542 .setup = bond_setup,
47543diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
47544index 4168822..f38eeddf 100644
47545--- a/drivers/net/can/Kconfig
47546+++ b/drivers/net/can/Kconfig
47547@@ -98,7 +98,7 @@ config CAN_JANZ_ICAN3
47548
47549 config CAN_FLEXCAN
47550 tristate "Support for Freescale FLEXCAN based chips"
47551- depends on ARM || PPC
47552+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
47553 ---help---
47554 Say Y here if you want to support for Freescale FlexCAN.
47555
47556diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
47557index 1d162cc..b546a75 100644
47558--- a/drivers/net/ethernet/8390/ax88796.c
47559+++ b/drivers/net/ethernet/8390/ax88796.c
47560@@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
47561 if (ax->plat->reg_offsets)
47562 ei_local->reg_offset = ax->plat->reg_offsets;
47563 else {
47564+ resource_size_t _mem_size = mem_size;
47565+ do_div(_mem_size, 0x18);
47566 ei_local->reg_offset = ax->reg_offsets;
47567 for (ret = 0; ret < 0x18; ret++)
47568- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
47569+ ax->reg_offsets[ret] = _mem_size * ret;
47570 }
47571
47572 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
47573diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
47574index 7330681..7e9e463 100644
47575--- a/drivers/net/ethernet/altera/altera_tse_main.c
47576+++ b/drivers/net/ethernet/altera/altera_tse_main.c
47577@@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
47578 return 0;
47579 }
47580
47581-static struct net_device_ops altera_tse_netdev_ops = {
47582+static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
47583 .ndo_open = tse_open,
47584 .ndo_stop = tse_shutdown,
47585 .ndo_start_xmit = tse_start_xmit,
47586@@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
47587 ndev->netdev_ops = &altera_tse_netdev_ops;
47588 altera_tse_set_ethtool_ops(ndev);
47589
47590+ pax_open_kernel();
47591 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
47592
47593 if (priv->hash_filter)
47594 altera_tse_netdev_ops.ndo_set_rx_mode =
47595 tse_set_rx_mode_hashfilter;
47596+ pax_close_kernel();
47597
47598 /* Scatter/gather IO is not supported,
47599 * so it is turned off
47600diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-common.h b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47601index cc25a3a..c8d72d3 100644
47602--- a/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47603+++ b/drivers/net/ethernet/amd/xgbe/xgbe-common.h
47604@@ -1083,14 +1083,14 @@ do { \
47605 * operations, everything works on mask values.
47606 */
47607 #define XMDIO_READ(_pdata, _mmd, _reg) \
47608- ((_pdata)->hw_if.read_mmd_regs((_pdata), 0, \
47609+ ((_pdata)->hw_if->read_mmd_regs((_pdata), 0, \
47610 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff)))
47611
47612 #define XMDIO_READ_BITS(_pdata, _mmd, _reg, _mask) \
47613 (XMDIO_READ((_pdata), _mmd, _reg) & _mask)
47614
47615 #define XMDIO_WRITE(_pdata, _mmd, _reg, _val) \
47616- ((_pdata)->hw_if.write_mmd_regs((_pdata), 0, \
47617+ ((_pdata)->hw_if->write_mmd_regs((_pdata), 0, \
47618 MII_ADDR_C45 | (_mmd << 16) | ((_reg) & 0xffff), (_val)))
47619
47620 #define XMDIO_WRITE_BITS(_pdata, _mmd, _reg, _mask, _val) \
47621diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47622index 7d6a49b..e6d403b 100644
47623--- a/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47624+++ b/drivers/net/ethernet/amd/xgbe/xgbe-dcb.c
47625@@ -188,7 +188,7 @@ static int xgbe_dcb_ieee_setets(struct net_device *netdev,
47626
47627 memcpy(pdata->ets, ets, sizeof(*pdata->ets));
47628
47629- pdata->hw_if.config_dcb_tc(pdata);
47630+ pdata->hw_if->config_dcb_tc(pdata);
47631
47632 return 0;
47633 }
47634@@ -227,7 +227,7 @@ static int xgbe_dcb_ieee_setpfc(struct net_device *netdev,
47635
47636 memcpy(pdata->pfc, pfc, sizeof(*pdata->pfc));
47637
47638- pdata->hw_if.config_dcb_pfc(pdata);
47639+ pdata->hw_if->config_dcb_pfc(pdata);
47640
47641 return 0;
47642 }
47643diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47644index 1c5d62e..8e14d54 100644
47645--- a/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47646+++ b/drivers/net/ethernet/amd/xgbe/xgbe-desc.c
47647@@ -236,7 +236,7 @@ err_ring:
47648
47649 static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47650 {
47651- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47652+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47653 struct xgbe_channel *channel;
47654 struct xgbe_ring *ring;
47655 struct xgbe_ring_data *rdata;
47656@@ -277,7 +277,7 @@ static void xgbe_wrapper_tx_descriptor_init(struct xgbe_prv_data *pdata)
47657
47658 static void xgbe_wrapper_rx_descriptor_init(struct xgbe_prv_data *pdata)
47659 {
47660- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47661+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47662 struct xgbe_channel *channel;
47663 struct xgbe_ring *ring;
47664 struct xgbe_ring_desc *rdesc;
47665@@ -506,7 +506,7 @@ err_out:
47666 static void xgbe_realloc_skb(struct xgbe_channel *channel)
47667 {
47668 struct xgbe_prv_data *pdata = channel->pdata;
47669- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47670+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47671 struct xgbe_ring *ring = channel->rx_ring;
47672 struct xgbe_ring_data *rdata;
47673 struct sk_buff *skb = NULL;
47674@@ -550,17 +550,12 @@ static void xgbe_realloc_skb(struct xgbe_channel *channel)
47675 DBGPR("<--xgbe_realloc_skb\n");
47676 }
47677
47678-void xgbe_init_function_ptrs_desc(struct xgbe_desc_if *desc_if)
47679-{
47680- DBGPR("-->xgbe_init_function_ptrs_desc\n");
47681-
47682- desc_if->alloc_ring_resources = xgbe_alloc_ring_resources;
47683- desc_if->free_ring_resources = xgbe_free_ring_resources;
47684- desc_if->map_tx_skb = xgbe_map_tx_skb;
47685- desc_if->realloc_skb = xgbe_realloc_skb;
47686- desc_if->unmap_skb = xgbe_unmap_skb;
47687- desc_if->wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init;
47688- desc_if->wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init;
47689-
47690- DBGPR("<--xgbe_init_function_ptrs_desc\n");
47691-}
47692+const struct xgbe_desc_if default_xgbe_desc_if = {
47693+ .alloc_ring_resources = xgbe_alloc_ring_resources,
47694+ .free_ring_resources = xgbe_free_ring_resources,
47695+ .map_tx_skb = xgbe_map_tx_skb,
47696+ .realloc_skb = xgbe_realloc_skb,
47697+ .unmap_skb = xgbe_unmap_skb,
47698+ .wrapper_tx_desc_init = xgbe_wrapper_tx_descriptor_init,
47699+ .wrapper_rx_desc_init = xgbe_wrapper_rx_descriptor_init,
47700+};
47701diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47702index ea27383..faa8936 100644
47703--- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47704+++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
47705@@ -2463,7 +2463,7 @@ static void xgbe_powerdown_rx(struct xgbe_prv_data *pdata)
47706
47707 static int xgbe_init(struct xgbe_prv_data *pdata)
47708 {
47709- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47710+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47711 int ret;
47712
47713 DBGPR("-->xgbe_init\n");
47714@@ -2525,101 +2525,96 @@ static int xgbe_init(struct xgbe_prv_data *pdata)
47715 return 0;
47716 }
47717
47718-void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *hw_if)
47719-{
47720- DBGPR("-->xgbe_init_function_ptrs\n");
47721-
47722- hw_if->tx_complete = xgbe_tx_complete;
47723-
47724- hw_if->set_promiscuous_mode = xgbe_set_promiscuous_mode;
47725- hw_if->set_all_multicast_mode = xgbe_set_all_multicast_mode;
47726- hw_if->add_mac_addresses = xgbe_add_mac_addresses;
47727- hw_if->set_mac_address = xgbe_set_mac_address;
47728-
47729- hw_if->enable_rx_csum = xgbe_enable_rx_csum;
47730- hw_if->disable_rx_csum = xgbe_disable_rx_csum;
47731-
47732- hw_if->enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping;
47733- hw_if->disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping;
47734- hw_if->enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering;
47735- hw_if->disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering;
47736- hw_if->update_vlan_hash_table = xgbe_update_vlan_hash_table;
47737-
47738- hw_if->read_mmd_regs = xgbe_read_mmd_regs;
47739- hw_if->write_mmd_regs = xgbe_write_mmd_regs;
47740-
47741- hw_if->set_gmii_speed = xgbe_set_gmii_speed;
47742- hw_if->set_gmii_2500_speed = xgbe_set_gmii_2500_speed;
47743- hw_if->set_xgmii_speed = xgbe_set_xgmii_speed;
47744-
47745- hw_if->enable_tx = xgbe_enable_tx;
47746- hw_if->disable_tx = xgbe_disable_tx;
47747- hw_if->enable_rx = xgbe_enable_rx;
47748- hw_if->disable_rx = xgbe_disable_rx;
47749-
47750- hw_if->powerup_tx = xgbe_powerup_tx;
47751- hw_if->powerdown_tx = xgbe_powerdown_tx;
47752- hw_if->powerup_rx = xgbe_powerup_rx;
47753- hw_if->powerdown_rx = xgbe_powerdown_rx;
47754-
47755- hw_if->pre_xmit = xgbe_pre_xmit;
47756- hw_if->dev_read = xgbe_dev_read;
47757- hw_if->enable_int = xgbe_enable_int;
47758- hw_if->disable_int = xgbe_disable_int;
47759- hw_if->init = xgbe_init;
47760- hw_if->exit = xgbe_exit;
47761+const struct xgbe_hw_if default_xgbe_hw_if = {
47762+ .tx_complete = xgbe_tx_complete,
47763+
47764+ .set_promiscuous_mode = xgbe_set_promiscuous_mode,
47765+ .set_all_multicast_mode = xgbe_set_all_multicast_mode,
47766+ .add_mac_addresses = xgbe_add_mac_addresses,
47767+ .set_mac_address = xgbe_set_mac_address,
47768+
47769+ .enable_rx_csum = xgbe_enable_rx_csum,
47770+ .disable_rx_csum = xgbe_disable_rx_csum,
47771+
47772+ .enable_rx_vlan_stripping = xgbe_enable_rx_vlan_stripping,
47773+ .disable_rx_vlan_stripping = xgbe_disable_rx_vlan_stripping,
47774+ .enable_rx_vlan_filtering = xgbe_enable_rx_vlan_filtering,
47775+ .disable_rx_vlan_filtering = xgbe_disable_rx_vlan_filtering,
47776+ .update_vlan_hash_table = xgbe_update_vlan_hash_table,
47777+
47778+ .read_mmd_regs = xgbe_read_mmd_regs,
47779+ .write_mmd_regs = xgbe_write_mmd_regs,
47780+
47781+ .set_gmii_speed = xgbe_set_gmii_speed,
47782+ .set_gmii_2500_speed = xgbe_set_gmii_2500_speed,
47783+ .set_xgmii_speed = xgbe_set_xgmii_speed,
47784+
47785+ .enable_tx = xgbe_enable_tx,
47786+ .disable_tx = xgbe_disable_tx,
47787+ .enable_rx = xgbe_enable_rx,
47788+ .disable_rx = xgbe_disable_rx,
47789+
47790+ .powerup_tx = xgbe_powerup_tx,
47791+ .powerdown_tx = xgbe_powerdown_tx,
47792+ .powerup_rx = xgbe_powerup_rx,
47793+ .powerdown_rx = xgbe_powerdown_rx,
47794+
47795+ .pre_xmit = xgbe_pre_xmit,
47796+ .dev_read = xgbe_dev_read,
47797+ .enable_int = xgbe_enable_int,
47798+ .disable_int = xgbe_disable_int,
47799+ .init = xgbe_init,
47800+ .exit = xgbe_exit,
47801
47802 /* Descriptor related Sequences have to be initialized here */
47803- hw_if->tx_desc_init = xgbe_tx_desc_init;
47804- hw_if->rx_desc_init = xgbe_rx_desc_init;
47805- hw_if->tx_desc_reset = xgbe_tx_desc_reset;
47806- hw_if->rx_desc_reset = xgbe_rx_desc_reset;
47807- hw_if->is_last_desc = xgbe_is_last_desc;
47808- hw_if->is_context_desc = xgbe_is_context_desc;
47809+ .tx_desc_init = xgbe_tx_desc_init,
47810+ .rx_desc_init = xgbe_rx_desc_init,
47811+ .tx_desc_reset = xgbe_tx_desc_reset,
47812+ .rx_desc_reset = xgbe_rx_desc_reset,
47813+ .is_last_desc = xgbe_is_last_desc,
47814+ .is_context_desc = xgbe_is_context_desc,
47815
47816 /* For FLOW ctrl */
47817- hw_if->config_tx_flow_control = xgbe_config_tx_flow_control;
47818- hw_if->config_rx_flow_control = xgbe_config_rx_flow_control;
47819+ .config_tx_flow_control = xgbe_config_tx_flow_control,
47820+ .config_rx_flow_control = xgbe_config_rx_flow_control,
47821
47822 /* For RX coalescing */
47823- hw_if->config_rx_coalesce = xgbe_config_rx_coalesce;
47824- hw_if->config_tx_coalesce = xgbe_config_tx_coalesce;
47825- hw_if->usec_to_riwt = xgbe_usec_to_riwt;
47826- hw_if->riwt_to_usec = xgbe_riwt_to_usec;
47827+ .config_rx_coalesce = xgbe_config_rx_coalesce,
47828+ .config_tx_coalesce = xgbe_config_tx_coalesce,
47829+ .usec_to_riwt = xgbe_usec_to_riwt,
47830+ .riwt_to_usec = xgbe_riwt_to_usec,
47831
47832 /* For RX and TX threshold config */
47833- hw_if->config_rx_threshold = xgbe_config_rx_threshold;
47834- hw_if->config_tx_threshold = xgbe_config_tx_threshold;
47835+ .config_rx_threshold = xgbe_config_rx_threshold,
47836+ .config_tx_threshold = xgbe_config_tx_threshold,
47837
47838 /* For RX and TX Store and Forward Mode config */
47839- hw_if->config_rsf_mode = xgbe_config_rsf_mode;
47840- hw_if->config_tsf_mode = xgbe_config_tsf_mode;
47841+ .config_rsf_mode = xgbe_config_rsf_mode,
47842+ .config_tsf_mode = xgbe_config_tsf_mode,
47843
47844 /* For TX DMA Operating on Second Frame config */
47845- hw_if->config_osp_mode = xgbe_config_osp_mode;
47846+ .config_osp_mode = xgbe_config_osp_mode,
47847
47848 /* For RX and TX PBL config */
47849- hw_if->config_rx_pbl_val = xgbe_config_rx_pbl_val;
47850- hw_if->get_rx_pbl_val = xgbe_get_rx_pbl_val;
47851- hw_if->config_tx_pbl_val = xgbe_config_tx_pbl_val;
47852- hw_if->get_tx_pbl_val = xgbe_get_tx_pbl_val;
47853- hw_if->config_pblx8 = xgbe_config_pblx8;
47854+ .config_rx_pbl_val = xgbe_config_rx_pbl_val,
47855+ .get_rx_pbl_val = xgbe_get_rx_pbl_val,
47856+ .config_tx_pbl_val = xgbe_config_tx_pbl_val,
47857+ .get_tx_pbl_val = xgbe_get_tx_pbl_val,
47858+ .config_pblx8 = xgbe_config_pblx8,
47859
47860 /* For MMC statistics support */
47861- hw_if->tx_mmc_int = xgbe_tx_mmc_int;
47862- hw_if->rx_mmc_int = xgbe_rx_mmc_int;
47863- hw_if->read_mmc_stats = xgbe_read_mmc_stats;
47864+ .tx_mmc_int = xgbe_tx_mmc_int,
47865+ .rx_mmc_int = xgbe_rx_mmc_int,
47866+ .read_mmc_stats = xgbe_read_mmc_stats,
47867
47868 /* For PTP config */
47869- hw_if->config_tstamp = xgbe_config_tstamp;
47870- hw_if->update_tstamp_addend = xgbe_update_tstamp_addend;
47871- hw_if->set_tstamp_time = xgbe_set_tstamp_time;
47872- hw_if->get_tstamp_time = xgbe_get_tstamp_time;
47873- hw_if->get_tx_tstamp = xgbe_get_tx_tstamp;
47874+ .config_tstamp = xgbe_config_tstamp,
47875+ .update_tstamp_addend = xgbe_update_tstamp_addend,
47876+ .set_tstamp_time = xgbe_set_tstamp_time,
47877+ .get_tstamp_time = xgbe_get_tstamp_time,
47878+ .get_tx_tstamp = xgbe_get_tx_tstamp,
47879
47880 /* For Data Center Bridging config */
47881- hw_if->config_dcb_tc = xgbe_config_dcb_tc;
47882- hw_if->config_dcb_pfc = xgbe_config_dcb_pfc;
47883-
47884- DBGPR("<--xgbe_init_function_ptrs\n");
47885-}
47886+ .config_dcb_tc = xgbe_config_dcb_tc,
47887+ .config_dcb_pfc = xgbe_config_dcb_pfc,
47888+};
47889diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47890index b26d758..b0d1c3b 100644
47891--- a/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47892+++ b/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
47893@@ -155,7 +155,7 @@ static int xgbe_calc_rx_buf_size(struct net_device *netdev, unsigned int mtu)
47894
47895 static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47896 {
47897- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47898+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47899 struct xgbe_channel *channel;
47900 enum xgbe_int int_id;
47901 unsigned int i;
47902@@ -177,7 +177,7 @@ static void xgbe_enable_rx_tx_ints(struct xgbe_prv_data *pdata)
47903
47904 static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47905 {
47906- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47907+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47908 struct xgbe_channel *channel;
47909 enum xgbe_int int_id;
47910 unsigned int i;
47911@@ -200,7 +200,7 @@ static void xgbe_disable_rx_tx_ints(struct xgbe_prv_data *pdata)
47912 static irqreturn_t xgbe_isr(int irq, void *data)
47913 {
47914 struct xgbe_prv_data *pdata = data;
47915- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47916+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47917 struct xgbe_channel *channel;
47918 unsigned int dma_isr, dma_ch_isr;
47919 unsigned int mac_isr, mac_tssr;
47920@@ -447,7 +447,7 @@ static void xgbe_napi_disable(struct xgbe_prv_data *pdata, unsigned int del)
47921
47922 void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47923 {
47924- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47925+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47926
47927 DBGPR("-->xgbe_init_tx_coalesce\n");
47928
47929@@ -461,7 +461,7 @@ void xgbe_init_tx_coalesce(struct xgbe_prv_data *pdata)
47930
47931 void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47932 {
47933- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47934+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47935
47936 DBGPR("-->xgbe_init_rx_coalesce\n");
47937
47938@@ -475,7 +475,7 @@ void xgbe_init_rx_coalesce(struct xgbe_prv_data *pdata)
47939
47940 static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47941 {
47942- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47943+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47944 struct xgbe_channel *channel;
47945 struct xgbe_ring *ring;
47946 struct xgbe_ring_data *rdata;
47947@@ -500,7 +500,7 @@ static void xgbe_free_tx_skbuff(struct xgbe_prv_data *pdata)
47948
47949 static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47950 {
47951- struct xgbe_desc_if *desc_if = &pdata->desc_if;
47952+ struct xgbe_desc_if *desc_if = pdata->desc_if;
47953 struct xgbe_channel *channel;
47954 struct xgbe_ring *ring;
47955 struct xgbe_ring_data *rdata;
47956@@ -526,7 +526,7 @@ static void xgbe_free_rx_skbuff(struct xgbe_prv_data *pdata)
47957 static void xgbe_adjust_link(struct net_device *netdev)
47958 {
47959 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47960- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47961+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47962 struct phy_device *phydev = pdata->phydev;
47963 int new_state = 0;
47964
47965@@ -634,7 +634,7 @@ static void xgbe_phy_exit(struct xgbe_prv_data *pdata)
47966 int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47967 {
47968 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47969- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47970+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47971 unsigned long flags;
47972
47973 DBGPR("-->xgbe_powerdown\n");
47974@@ -672,7 +672,7 @@ int xgbe_powerdown(struct net_device *netdev, unsigned int caller)
47975 int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47976 {
47977 struct xgbe_prv_data *pdata = netdev_priv(netdev);
47978- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47979+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47980 unsigned long flags;
47981
47982 DBGPR("-->xgbe_powerup\n");
47983@@ -709,7 +709,7 @@ int xgbe_powerup(struct net_device *netdev, unsigned int caller)
47984
47985 static int xgbe_start(struct xgbe_prv_data *pdata)
47986 {
47987- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47988+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47989 struct net_device *netdev = pdata->netdev;
47990
47991 DBGPR("-->xgbe_start\n");
47992@@ -735,7 +735,7 @@ static int xgbe_start(struct xgbe_prv_data *pdata)
47993
47994 static void xgbe_stop(struct xgbe_prv_data *pdata)
47995 {
47996- struct xgbe_hw_if *hw_if = &pdata->hw_if;
47997+ struct xgbe_hw_if *hw_if = pdata->hw_if;
47998 struct net_device *netdev = pdata->netdev;
47999
48000 DBGPR("-->xgbe_stop\n");
48001@@ -755,7 +755,7 @@ static void xgbe_stop(struct xgbe_prv_data *pdata)
48002
48003 static void xgbe_restart_dev(struct xgbe_prv_data *pdata, unsigned int reset)
48004 {
48005- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48006+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48007
48008 DBGPR("-->xgbe_restart_dev\n");
48009
48010@@ -952,7 +952,7 @@ static int xgbe_set_hwtstamp_settings(struct xgbe_prv_data *pdata,
48011 return -ERANGE;
48012 }
48013
48014- pdata->hw_if.config_tstamp(pdata, mac_tscr);
48015+ pdata->hw_if->config_tstamp(pdata, mac_tscr);
48016
48017 memcpy(&pdata->tstamp_config, &config, sizeof(config));
48018
48019@@ -1090,8 +1090,8 @@ static void xgbe_packet_info(struct xgbe_prv_data *pdata,
48020 static int xgbe_open(struct net_device *netdev)
48021 {
48022 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48023- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48024- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48025+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48026+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48027 int ret;
48028
48029 DBGPR("-->xgbe_open\n");
48030@@ -1171,8 +1171,8 @@ err_phy_init:
48031 static int xgbe_close(struct net_device *netdev)
48032 {
48033 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48034- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48035- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48036+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48037+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48038
48039 DBGPR("-->xgbe_close\n");
48040
48041@@ -1206,8 +1206,8 @@ static int xgbe_close(struct net_device *netdev)
48042 static int xgbe_xmit(struct sk_buff *skb, struct net_device *netdev)
48043 {
48044 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48045- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48046- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48047+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48048+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48049 struct xgbe_channel *channel;
48050 struct xgbe_ring *ring;
48051 struct xgbe_packet_data *packet;
48052@@ -1276,7 +1276,7 @@ tx_netdev_return:
48053 static void xgbe_set_rx_mode(struct net_device *netdev)
48054 {
48055 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48056- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48057+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48058 unsigned int pr_mode, am_mode;
48059
48060 DBGPR("-->xgbe_set_rx_mode\n");
48061@@ -1295,7 +1295,7 @@ static void xgbe_set_rx_mode(struct net_device *netdev)
48062 static int xgbe_set_mac_address(struct net_device *netdev, void *addr)
48063 {
48064 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48065- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48066+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48067 struct sockaddr *saddr = addr;
48068
48069 DBGPR("-->xgbe_set_mac_address\n");
48070@@ -1362,7 +1362,7 @@ static struct rtnl_link_stats64 *xgbe_get_stats64(struct net_device *netdev,
48071
48072 DBGPR("-->%s\n", __func__);
48073
48074- pdata->hw_if.read_mmc_stats(pdata);
48075+ pdata->hw_if->read_mmc_stats(pdata);
48076
48077 s->rx_packets = pstats->rxframecount_gb;
48078 s->rx_bytes = pstats->rxoctetcount_gb;
48079@@ -1389,7 +1389,7 @@ static int xgbe_vlan_rx_add_vid(struct net_device *netdev, __be16 proto,
48080 u16 vid)
48081 {
48082 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48083- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48084+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48085
48086 DBGPR("-->%s\n", __func__);
48087
48088@@ -1405,7 +1405,7 @@ static int xgbe_vlan_rx_kill_vid(struct net_device *netdev, __be16 proto,
48089 u16 vid)
48090 {
48091 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48092- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48093+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48094
48095 DBGPR("-->%s\n", __func__);
48096
48097@@ -1465,7 +1465,7 @@ static int xgbe_set_features(struct net_device *netdev,
48098 netdev_features_t features)
48099 {
48100 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48101- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48102+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48103 unsigned int rxcsum, rxvlan, rxvlan_filter;
48104
48105 rxcsum = pdata->netdev_features & NETIF_F_RXCSUM;
48106@@ -1521,7 +1521,7 @@ struct net_device_ops *xgbe_get_netdev_ops(void)
48107 static void xgbe_rx_refresh(struct xgbe_channel *channel)
48108 {
48109 struct xgbe_prv_data *pdata = channel->pdata;
48110- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48111+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48112 struct xgbe_ring *ring = channel->rx_ring;
48113 struct xgbe_ring_data *rdata;
48114
48115@@ -1537,8 +1537,8 @@ static void xgbe_rx_refresh(struct xgbe_channel *channel)
48116 static int xgbe_tx_poll(struct xgbe_channel *channel)
48117 {
48118 struct xgbe_prv_data *pdata = channel->pdata;
48119- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48120- struct xgbe_desc_if *desc_if = &pdata->desc_if;
48121+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48122+ struct xgbe_desc_if *desc_if = pdata->desc_if;
48123 struct xgbe_ring *ring = channel->tx_ring;
48124 struct xgbe_ring_data *rdata;
48125 struct xgbe_ring_desc *rdesc;
48126@@ -1590,7 +1590,7 @@ static int xgbe_tx_poll(struct xgbe_channel *channel)
48127 static int xgbe_rx_poll(struct xgbe_channel *channel, int budget)
48128 {
48129 struct xgbe_prv_data *pdata = channel->pdata;
48130- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48131+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48132 struct xgbe_ring *ring = channel->rx_ring;
48133 struct xgbe_ring_data *rdata;
48134 struct xgbe_packet_data *packet;
48135diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48136index 46f6130..f37dde3 100644
48137--- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48138+++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
48139@@ -203,7 +203,7 @@ static void xgbe_get_ethtool_stats(struct net_device *netdev,
48140
48141 DBGPR("-->%s\n", __func__);
48142
48143- pdata->hw_if.read_mmc_stats(pdata);
48144+ pdata->hw_if->read_mmc_stats(pdata);
48145 for (i = 0; i < XGBE_STATS_COUNT; i++) {
48146 stat = (u8 *)pdata + xgbe_gstring_stats[i].stat_offset;
48147 *data++ = *(u64 *)stat;
48148@@ -378,7 +378,7 @@ static int xgbe_get_coalesce(struct net_device *netdev,
48149 struct ethtool_coalesce *ec)
48150 {
48151 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48152- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48153+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48154 unsigned int riwt;
48155
48156 DBGPR("-->xgbe_get_coalesce\n");
48157@@ -401,7 +401,7 @@ static int xgbe_set_coalesce(struct net_device *netdev,
48158 struct ethtool_coalesce *ec)
48159 {
48160 struct xgbe_prv_data *pdata = netdev_priv(netdev);
48161- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48162+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48163 unsigned int rx_frames, rx_riwt, rx_usecs;
48164 unsigned int tx_frames, tx_usecs;
48165
48166diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48167index bdf9cfa..340aea1 100644
48168--- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48169+++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
48170@@ -210,12 +210,6 @@ static void xgbe_default_config(struct xgbe_prv_data *pdata)
48171 DBGPR("<--xgbe_default_config\n");
48172 }
48173
48174-static void xgbe_init_all_fptrs(struct xgbe_prv_data *pdata)
48175-{
48176- xgbe_init_function_ptrs_dev(&pdata->hw_if);
48177- xgbe_init_function_ptrs_desc(&pdata->desc_if);
48178-}
48179-
48180 static int xgbe_probe(struct platform_device *pdev)
48181 {
48182 struct xgbe_prv_data *pdata;
48183@@ -328,9 +322,8 @@ static int xgbe_probe(struct platform_device *pdev)
48184 netdev->base_addr = (unsigned long)pdata->xgmac_regs;
48185
48186 /* Set all the function pointers */
48187- xgbe_init_all_fptrs(pdata);
48188- hw_if = &pdata->hw_if;
48189- desc_if = &pdata->desc_if;
48190+ hw_if = pdata->hw_if = &default_xgbe_hw_if;
48191+ desc_if = pdata->desc_if = &default_xgbe_desc_if;
48192
48193 /* Issue software reset to device */
48194 hw_if->exit(pdata);
48195diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48196index 6d2221e..47d1325 100644
48197--- a/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48198+++ b/drivers/net/ethernet/amd/xgbe/xgbe-mdio.c
48199@@ -127,7 +127,7 @@
48200 static int xgbe_mdio_read(struct mii_bus *mii, int prtad, int mmd_reg)
48201 {
48202 struct xgbe_prv_data *pdata = mii->priv;
48203- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48204+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48205 int mmd_data;
48206
48207 DBGPR_MDIO("-->xgbe_mdio_read: prtad=%#x mmd_reg=%#x\n",
48208@@ -144,7 +144,7 @@ static int xgbe_mdio_write(struct mii_bus *mii, int prtad, int mmd_reg,
48209 u16 mmd_val)
48210 {
48211 struct xgbe_prv_data *pdata = mii->priv;
48212- struct xgbe_hw_if *hw_if = &pdata->hw_if;
48213+ struct xgbe_hw_if *hw_if = pdata->hw_if;
48214 int mmd_data = mmd_val;
48215
48216 DBGPR_MDIO("-->xgbe_mdio_write: prtad=%#x mmd_reg=%#x mmd_data=%#x\n",
48217diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48218index 37e64cf..c3b61cf 100644
48219--- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48220+++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
48221@@ -130,7 +130,7 @@ static cycle_t xgbe_cc_read(const struct cyclecounter *cc)
48222 tstamp_cc);
48223 u64 nsec;
48224
48225- nsec = pdata->hw_if.get_tstamp_time(pdata);
48226+ nsec = pdata->hw_if->get_tstamp_time(pdata);
48227
48228 return nsec;
48229 }
48230@@ -159,7 +159,7 @@ static int xgbe_adjfreq(struct ptp_clock_info *info, s32 delta)
48231
48232 spin_lock_irqsave(&pdata->tstamp_lock, flags);
48233
48234- pdata->hw_if.update_tstamp_addend(pdata, addend);
48235+ pdata->hw_if->update_tstamp_addend(pdata, addend);
48236
48237 spin_unlock_irqrestore(&pdata->tstamp_lock, flags);
48238
48239diff --git a/drivers/net/ethernet/amd/xgbe/xgbe.h b/drivers/net/ethernet/amd/xgbe/xgbe.h
48240index e9fe6e6..875fbaf 100644
48241--- a/drivers/net/ethernet/amd/xgbe/xgbe.h
48242+++ b/drivers/net/ethernet/amd/xgbe/xgbe.h
48243@@ -585,8 +585,8 @@ struct xgbe_prv_data {
48244
48245 int irq_number;
48246
48247- struct xgbe_hw_if hw_if;
48248- struct xgbe_desc_if desc_if;
48249+ const struct xgbe_hw_if *hw_if;
48250+ const struct xgbe_desc_if *desc_if;
48251
48252 /* AXI DMA settings */
48253 unsigned int axdomain;
48254@@ -699,6 +699,9 @@ struct xgbe_prv_data {
48255 #endif
48256 };
48257
48258+extern const struct xgbe_hw_if default_xgbe_hw_if;
48259+extern const struct xgbe_desc_if default_xgbe_desc_if;
48260+
48261 /* Function prototypes*/
48262
48263 void xgbe_init_function_ptrs_dev(struct xgbe_hw_if *);
48264diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48265index 571427c..e9fe9e7 100644
48266--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48267+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
48268@@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
48269 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
48270 {
48271 /* RX_MODE controlling object */
48272- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
48273+ bnx2x_init_rx_mode_obj(bp);
48274
48275 /* multicast configuration controlling object */
48276 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
48277diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48278index b193604..8873bfd 100644
48279--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48280+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
48281@@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
48282 return rc;
48283 }
48284
48285-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48286- struct bnx2x_rx_mode_obj *o)
48287+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
48288 {
48289 if (CHIP_IS_E1x(bp)) {
48290- o->wait_comp = bnx2x_empty_rx_mode_wait;
48291- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
48292+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
48293+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
48294 } else {
48295- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
48296- o->config_rx_mode = bnx2x_set_rx_mode_e2;
48297+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
48298+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
48299 }
48300 }
48301
48302diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48303index 718ecd2..2183b2f 100644
48304--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48305+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
48306@@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
48307
48308 /********************* RX MODE ****************/
48309
48310-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
48311- struct bnx2x_rx_mode_obj *o);
48312+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
48313
48314 /**
48315 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
48316diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
48317index 31c9f82..e65e986 100644
48318--- a/drivers/net/ethernet/broadcom/tg3.h
48319+++ b/drivers/net/ethernet/broadcom/tg3.h
48320@@ -150,6 +150,7 @@
48321 #define CHIPREV_ID_5750_A0 0x4000
48322 #define CHIPREV_ID_5750_A1 0x4001
48323 #define CHIPREV_ID_5750_A3 0x4003
48324+#define CHIPREV_ID_5750_C1 0x4201
48325 #define CHIPREV_ID_5750_C2 0x4202
48326 #define CHIPREV_ID_5752_A0_HW 0x5000
48327 #define CHIPREV_ID_5752_A0 0x6000
48328diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
48329index 13f9636..228040f 100644
48330--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
48331+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
48332@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
48333 }
48334
48335 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
48336- bna_cb_ioceth_enable,
48337- bna_cb_ioceth_disable,
48338- bna_cb_ioceth_hbfail,
48339- bna_cb_ioceth_reset
48340+ .enable_cbfn = bna_cb_ioceth_enable,
48341+ .disable_cbfn = bna_cb_ioceth_disable,
48342+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
48343+ .reset_cbfn = bna_cb_ioceth_reset
48344 };
48345
48346 static void bna_attr_init(struct bna_ioceth *ioceth)
48347diff --git a/drivers/net/ethernet/brocade/bna/bnad.c b/drivers/net/ethernet/brocade/bna/bnad.c
48348index ffc92a4..40edc77 100644
48349--- a/drivers/net/ethernet/brocade/bna/bnad.c
48350+++ b/drivers/net/ethernet/brocade/bna/bnad.c
48351@@ -552,6 +552,7 @@ bnad_cq_setup_skb_frags(struct bna_rcb *rcb, struct sk_buff *skb,
48352
48353 len = (vec == nvecs) ?
48354 last_fraglen : unmap->vector.len;
48355+ skb->truesize += unmap->vector.len;
48356 totlen += len;
48357
48358 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
48359@@ -563,7 +564,6 @@ bnad_cq_setup_skb_frags(struct bna_rcb *rcb, struct sk_buff *skb,
48360
48361 skb->len += totlen;
48362 skb->data_len += totlen;
48363- skb->truesize += totlen;
48364 }
48365
48366 static inline void
48367diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48368index 8cffcdf..aadf043 100644
48369--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48370+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
48371@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
48372 */
48373 struct l2t_skb_cb {
48374 arp_failure_handler_func arp_failure_handler;
48375-};
48376+} __no_const;
48377
48378 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
48379
48380diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48381index fac3821..52c1a04 100644
48382--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48383+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
48384@@ -2355,7 +2355,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
48385
48386 int i;
48387 struct adapter *ap = netdev2adap(dev);
48388- static const unsigned int *reg_ranges;
48389+ const unsigned int *reg_ranges;
48390 int arr_size = 0, buf_size = 0;
48391
48392 if (is_t4(ap->params.chip)) {
48393diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
48394index cf8b6ff..274271e 100644
48395--- a/drivers/net/ethernet/dec/tulip/de4x5.c
48396+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
48397@@ -5387,7 +5387,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48398 for (i=0; i<ETH_ALEN; i++) {
48399 tmp.addr[i] = dev->dev_addr[i];
48400 }
48401- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48402+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
48403 break;
48404
48405 case DE4X5_SET_HWADDR: /* Set the hardware address */
48406@@ -5427,7 +5427,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
48407 spin_lock_irqsave(&lp->lock, flags);
48408 memcpy(&statbuf, &lp->pktStats, ioc->len);
48409 spin_unlock_irqrestore(&lp->lock, flags);
48410- if (copy_to_user(ioc->data, &statbuf, ioc->len))
48411+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
48412 return -EFAULT;
48413 break;
48414 }
48415diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
48416index 93ff8ef..01e0537 100644
48417--- a/drivers/net/ethernet/emulex/benet/be_main.c
48418+++ b/drivers/net/ethernet/emulex/benet/be_main.c
48419@@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
48420
48421 if (wrapped)
48422 newacc += 65536;
48423- ACCESS_ONCE(*acc) = newacc;
48424+ ACCESS_ONCE_RW(*acc) = newacc;
48425 }
48426
48427 static void populate_erx_stats(struct be_adapter *adapter,
48428diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
48429index c77fa4a..7fd42fc 100644
48430--- a/drivers/net/ethernet/faraday/ftgmac100.c
48431+++ b/drivers/net/ethernet/faraday/ftgmac100.c
48432@@ -30,6 +30,8 @@
48433 #include <linux/netdevice.h>
48434 #include <linux/phy.h>
48435 #include <linux/platform_device.h>
48436+#include <linux/interrupt.h>
48437+#include <linux/irqreturn.h>
48438 #include <net/ip.h>
48439
48440 #include "ftgmac100.h"
48441diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
48442index 4ff1adc..0ea6bf4 100644
48443--- a/drivers/net/ethernet/faraday/ftmac100.c
48444+++ b/drivers/net/ethernet/faraday/ftmac100.c
48445@@ -31,6 +31,8 @@
48446 #include <linux/module.h>
48447 #include <linux/netdevice.h>
48448 #include <linux/platform_device.h>
48449+#include <linux/interrupt.h>
48450+#include <linux/irqreturn.h>
48451
48452 #include "ftmac100.h"
48453
48454diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48455index 537b621..07f87ce 100644
48456--- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48457+++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
48458@@ -401,7 +401,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
48459 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
48460
48461 /* Update the base adjustement value. */
48462- ACCESS_ONCE(pf->ptp_base_adj) = incval;
48463+ ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
48464 smp_mb(); /* Force the above update. */
48465 }
48466
48467diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48468index 5fd4b52..87aa34b 100644
48469--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48470+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
48471@@ -794,7 +794,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
48472 }
48473
48474 /* update the base incval used to calculate frequency adjustment */
48475- ACCESS_ONCE(adapter->base_incval) = incval;
48476+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
48477 smp_mb();
48478
48479 /* need lock to prevent incorrect read while modifying cyclecounter */
48480diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
48481index c14d4d8..66da603 100644
48482--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
48483+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_sriov.c
48484@@ -1259,6 +1259,9 @@ int ixgbe_ndo_set_vf_spoofchk(struct net_device *netdev, int vf, bool setting)
48485 struct ixgbe_hw *hw = &adapter->hw;
48486 u32 regval;
48487
48488+ if (vf >= adapter->num_vfs)
48489+ return -EINVAL;
48490+
48491 adapter->vfinfo[vf].spoofchk_enabled = setting;
48492
48493 regval = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
48494diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48495index 2bbd01f..e8baa64 100644
48496--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
48497+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
48498@@ -3457,7 +3457,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48499 struct __vxge_hw_fifo *fifo;
48500 struct vxge_hw_fifo_config *config;
48501 u32 txdl_size, txdl_per_memblock;
48502- struct vxge_hw_mempool_cbs fifo_mp_callback;
48503+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
48504+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
48505+ };
48506+
48507 struct __vxge_hw_virtualpath *vpath;
48508
48509 if ((vp == NULL) || (attr == NULL)) {
48510@@ -3540,8 +3543,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
48511 goto exit;
48512 }
48513
48514- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
48515-
48516 fifo->mempool =
48517 __vxge_hw_mempool_create(vpath->hldev,
48518 fifo->config->memblock_size,
48519diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48520index 3172cdf..d01ab34 100644
48521--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48522+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
48523@@ -2190,7 +2190,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
48524 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
48525 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
48526 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
48527- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48528+ pax_open_kernel();
48529+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
48530+ pax_close_kernel();
48531 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48532 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
48533 max_tx_rings = QLCNIC_MAX_TX_RINGS;
48534diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48535index be7d7a6..a8983f8 100644
48536--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48537+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
48538@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
48539 case QLCNIC_NON_PRIV_FUNC:
48540 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
48541 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48542- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48543+ pax_open_kernel();
48544+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
48545+ pax_close_kernel();
48546 break;
48547 case QLCNIC_PRIV_FUNC:
48548 ahw->op_mode = QLCNIC_PRIV_FUNC;
48549 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
48550- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48551+ pax_open_kernel();
48552+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
48553+ pax_close_kernel();
48554 break;
48555 case QLCNIC_MGMT_FUNC:
48556 ahw->op_mode = QLCNIC_MGMT_FUNC;
48557 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
48558- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48559+ pax_open_kernel();
48560+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
48561+ pax_close_kernel();
48562 break;
48563 default:
48564 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
48565diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48566index c9f57fb..208bdc1 100644
48567--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48568+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
48569@@ -1285,7 +1285,7 @@ flash_temp:
48570 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
48571 {
48572 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
48573- static const struct qlcnic_dump_operations *fw_dump_ops;
48574+ const struct qlcnic_dump_operations *fw_dump_ops;
48575 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
48576 u32 entry_offset, dump, no_entries, buf_offset = 0;
48577 int i, k, ops_cnt, ops_index, dump_size = 0;
48578diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
48579index 0921302..927f761 100644
48580--- a/drivers/net/ethernet/realtek/r8169.c
48581+++ b/drivers/net/ethernet/realtek/r8169.c
48582@@ -744,22 +744,22 @@ struct rtl8169_private {
48583 struct mdio_ops {
48584 void (*write)(struct rtl8169_private *, int, int);
48585 int (*read)(struct rtl8169_private *, int);
48586- } mdio_ops;
48587+ } __no_const mdio_ops;
48588
48589 struct pll_power_ops {
48590 void (*down)(struct rtl8169_private *);
48591 void (*up)(struct rtl8169_private *);
48592- } pll_power_ops;
48593+ } __no_const pll_power_ops;
48594
48595 struct jumbo_ops {
48596 void (*enable)(struct rtl8169_private *);
48597 void (*disable)(struct rtl8169_private *);
48598- } jumbo_ops;
48599+ } __no_const jumbo_ops;
48600
48601 struct csi_ops {
48602 void (*write)(struct rtl8169_private *, int, int);
48603 u32 (*read)(struct rtl8169_private *, int);
48604- } csi_ops;
48605+ } __no_const csi_ops;
48606
48607 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
48608 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
48609diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
48610index 6b861e3..204ac86 100644
48611--- a/drivers/net/ethernet/sfc/ptp.c
48612+++ b/drivers/net/ethernet/sfc/ptp.c
48613@@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
48614 ptp->start.dma_addr);
48615
48616 /* Clear flag that signals MC ready */
48617- ACCESS_ONCE(*start) = 0;
48618+ ACCESS_ONCE_RW(*start) = 0;
48619 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
48620 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
48621 EFX_BUG_ON_PARANOID(rc);
48622diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48623index 08c483b..2c4a553 100644
48624--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48625+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
48626@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
48627
48628 writel(value, ioaddr + MMC_CNTRL);
48629
48630- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48631- MMC_CNTRL, value);
48632+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
48633+// MMC_CNTRL, value);
48634 }
48635
48636 /* To mask all all interrupts.*/
48637diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
48638index d5e07de..e3bf20a 100644
48639--- a/drivers/net/hyperv/hyperv_net.h
48640+++ b/drivers/net/hyperv/hyperv_net.h
48641@@ -171,7 +171,7 @@ struct rndis_device {
48642 enum rndis_device_state state;
48643 bool link_state;
48644 bool link_change;
48645- atomic_t new_req_id;
48646+ atomic_unchecked_t new_req_id;
48647
48648 spinlock_t request_lock;
48649 struct list_head req_list;
48650diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
48651index 2b86f0b..ecc996f 100644
48652--- a/drivers/net/hyperv/rndis_filter.c
48653+++ b/drivers/net/hyperv/rndis_filter.c
48654@@ -102,7 +102,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
48655 * template
48656 */
48657 set = &rndis_msg->msg.set_req;
48658- set->req_id = atomic_inc_return(&dev->new_req_id);
48659+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48660
48661 /* Add to the request list */
48662 spin_lock_irqsave(&dev->request_lock, flags);
48663@@ -911,7 +911,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
48664
48665 /* Setup the rndis set */
48666 halt = &request->request_msg.msg.halt_req;
48667- halt->req_id = atomic_inc_return(&dev->new_req_id);
48668+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
48669
48670 /* Ignore return since this msg is optional. */
48671 rndis_filter_send_request(dev, request);
48672diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
48673index 9ce854f..e43fa17 100644
48674--- a/drivers/net/ieee802154/fakehard.c
48675+++ b/drivers/net/ieee802154/fakehard.c
48676@@ -365,7 +365,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
48677 phy->transmit_power = 0xbf;
48678
48679 dev->netdev_ops = &fake_ops;
48680- dev->ml_priv = &fake_mlme;
48681+ dev->ml_priv = (void *)&fake_mlme;
48682
48683 priv = netdev_priv(dev);
48684 priv->phy = phy;
48685diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
48686index 5f17ad0..e0463c8 100644
48687--- a/drivers/net/macvlan.c
48688+++ b/drivers/net/macvlan.c
48689@@ -264,7 +264,7 @@ static void macvlan_broadcast_enqueue(struct macvlan_port *port,
48690 free_nskb:
48691 kfree_skb(nskb);
48692 err:
48693- atomic_long_inc(&skb->dev->rx_dropped);
48694+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
48695 }
48696
48697 /* called under rcu_read_lock() from netif_receive_skb */
48698@@ -1150,13 +1150,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
48699 int macvlan_link_register(struct rtnl_link_ops *ops)
48700 {
48701 /* common fields */
48702- ops->priv_size = sizeof(struct macvlan_dev);
48703- ops->validate = macvlan_validate;
48704- ops->maxtype = IFLA_MACVLAN_MAX;
48705- ops->policy = macvlan_policy;
48706- ops->changelink = macvlan_changelink;
48707- ops->get_size = macvlan_get_size;
48708- ops->fill_info = macvlan_fill_info;
48709+ pax_open_kernel();
48710+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
48711+ *(void **)&ops->validate = macvlan_validate;
48712+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
48713+ *(const void **)&ops->policy = macvlan_policy;
48714+ *(void **)&ops->changelink = macvlan_changelink;
48715+ *(void **)&ops->get_size = macvlan_get_size;
48716+ *(void **)&ops->fill_info = macvlan_fill_info;
48717+ pax_close_kernel();
48718
48719 return rtnl_link_register(ops);
48720 };
48721@@ -1236,7 +1238,7 @@ static int macvlan_device_event(struct notifier_block *unused,
48722 return NOTIFY_DONE;
48723 }
48724
48725-static struct notifier_block macvlan_notifier_block __read_mostly = {
48726+static struct notifier_block macvlan_notifier_block = {
48727 .notifier_call = macvlan_device_event,
48728 };
48729
48730diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
48731index 9b5481c..eb32d45 100644
48732--- a/drivers/net/macvtap.c
48733+++ b/drivers/net/macvtap.c
48734@@ -1021,7 +1021,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
48735 }
48736
48737 ret = 0;
48738- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48739+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
48740 put_user(q->flags, &ifr->ifr_flags))
48741 ret = -EFAULT;
48742 macvtap_put_vlan(vlan);
48743@@ -1191,7 +1191,7 @@ static int macvtap_device_event(struct notifier_block *unused,
48744 return NOTIFY_DONE;
48745 }
48746
48747-static struct notifier_block macvtap_notifier_block __read_mostly = {
48748+static struct notifier_block macvtap_notifier_block = {
48749 .notifier_call = macvtap_device_event,
48750 };
48751
48752diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
48753index 90c639b..bab8c01 100644
48754--- a/drivers/net/ppp/ppp_generic.c
48755+++ b/drivers/net/ppp/ppp_generic.c
48756@@ -1020,7 +1020,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48757 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
48758 struct ppp_stats stats;
48759 struct ppp_comp_stats cstats;
48760- char *vers;
48761
48762 switch (cmd) {
48763 case SIOCGPPPSTATS:
48764@@ -1042,8 +1041,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
48765 break;
48766
48767 case SIOCGPPPVER:
48768- vers = PPP_VERSION;
48769- if (copy_to_user(addr, vers, strlen(vers) + 1))
48770+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
48771 break;
48772 err = 0;
48773 break;
48774diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
48775index 079f7ad..b2a2bfa7 100644
48776--- a/drivers/net/slip/slhc.c
48777+++ b/drivers/net/slip/slhc.c
48778@@ -487,7 +487,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
48779 register struct tcphdr *thp;
48780 register struct iphdr *ip;
48781 register struct cstate *cs;
48782- int len, hdrlen;
48783+ long len, hdrlen;
48784 unsigned char *cp = icp;
48785
48786 /* We've got a compressed packet; read the change byte */
48787diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
48788index 1f76c2ea..9681171 100644
48789--- a/drivers/net/team/team.c
48790+++ b/drivers/net/team/team.c
48791@@ -2862,7 +2862,7 @@ static int team_device_event(struct notifier_block *unused,
48792 return NOTIFY_DONE;
48793 }
48794
48795-static struct notifier_block team_notifier_block __read_mostly = {
48796+static struct notifier_block team_notifier_block = {
48797 .notifier_call = team_device_event,
48798 };
48799
48800diff --git a/drivers/net/tun.c b/drivers/net/tun.c
48801index 610d166..a3cc744 100644
48802--- a/drivers/net/tun.c
48803+++ b/drivers/net/tun.c
48804@@ -1859,7 +1859,7 @@ unlock:
48805 }
48806
48807 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48808- unsigned long arg, int ifreq_len)
48809+ unsigned long arg, size_t ifreq_len)
48810 {
48811 struct tun_file *tfile = file->private_data;
48812 struct tun_struct *tun;
48813@@ -1872,6 +1872,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
48814 unsigned int ifindex;
48815 int ret;
48816
48817+ if (ifreq_len > sizeof ifr)
48818+ return -EFAULT;
48819+
48820 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
48821 if (copy_from_user(&ifr, argp, ifreq_len))
48822 return -EFAULT;
48823diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
48824index babda7d..e40c90a 100644
48825--- a/drivers/net/usb/hso.c
48826+++ b/drivers/net/usb/hso.c
48827@@ -71,7 +71,7 @@
48828 #include <asm/byteorder.h>
48829 #include <linux/serial_core.h>
48830 #include <linux/serial.h>
48831-
48832+#include <asm/local.h>
48833
48834 #define MOD_AUTHOR "Option Wireless"
48835 #define MOD_DESCRIPTION "USB High Speed Option driver"
48836@@ -1178,7 +1178,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
48837 struct urb *urb;
48838
48839 urb = serial->rx_urb[0];
48840- if (serial->port.count > 0) {
48841+ if (atomic_read(&serial->port.count) > 0) {
48842 count = put_rxbuf_data(urb, serial);
48843 if (count == -1)
48844 return;
48845@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
48846 DUMP1(urb->transfer_buffer, urb->actual_length);
48847
48848 /* Anyone listening? */
48849- if (serial->port.count == 0)
48850+ if (atomic_read(&serial->port.count) == 0)
48851 return;
48852
48853 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
48854@@ -1278,8 +1278,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48855 tty_port_tty_set(&serial->port, tty);
48856
48857 /* check for port already opened, if not set the termios */
48858- serial->port.count++;
48859- if (serial->port.count == 1) {
48860+ if (atomic_inc_return(&serial->port.count) == 1) {
48861 serial->rx_state = RX_IDLE;
48862 /* Force default termio settings */
48863 _hso_serial_set_termios(tty, NULL);
48864@@ -1289,7 +1288,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
48865 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
48866 if (result) {
48867 hso_stop_serial_device(serial->parent);
48868- serial->port.count--;
48869+ atomic_dec(&serial->port.count);
48870 kref_put(&serial->parent->ref, hso_serial_ref_free);
48871 }
48872 } else {
48873@@ -1326,10 +1325,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
48874
48875 /* reset the rts and dtr */
48876 /* do the actual close */
48877- serial->port.count--;
48878+ atomic_dec(&serial->port.count);
48879
48880- if (serial->port.count <= 0) {
48881- serial->port.count = 0;
48882+ if (atomic_read(&serial->port.count) <= 0) {
48883+ atomic_set(&serial->port.count, 0);
48884 tty_port_tty_set(&serial->port, NULL);
48885 if (!usb_gone)
48886 hso_stop_serial_device(serial->parent);
48887@@ -1404,7 +1403,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
48888
48889 /* the actual setup */
48890 spin_lock_irqsave(&serial->serial_lock, flags);
48891- if (serial->port.count)
48892+ if (atomic_read(&serial->port.count))
48893 _hso_serial_set_termios(tty, old);
48894 else
48895 tty->termios = *old;
48896@@ -1873,7 +1872,7 @@ static void intr_callback(struct urb *urb)
48897 D1("Pending read interrupt on port %d\n", i);
48898 spin_lock(&serial->serial_lock);
48899 if (serial->rx_state == RX_IDLE &&
48900- serial->port.count > 0) {
48901+ atomic_read(&serial->port.count) > 0) {
48902 /* Setup and send a ctrl req read on
48903 * port i */
48904 if (!serial->rx_urb_filled[0]) {
48905@@ -3047,7 +3046,7 @@ static int hso_resume(struct usb_interface *iface)
48906 /* Start all serial ports */
48907 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
48908 if (serial_table[i] && (serial_table[i]->interface == iface)) {
48909- if (dev2ser(serial_table[i])->port.count) {
48910+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
48911 result =
48912 hso_start_serial_device(serial_table[i], GFP_NOIO);
48913 hso_kick_transmit(dev2ser(serial_table[i]));
48914diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
48915index 604ef21..d1f49a1 100644
48916--- a/drivers/net/usb/r8152.c
48917+++ b/drivers/net/usb/r8152.c
48918@@ -575,7 +575,7 @@ struct r8152 {
48919 void (*up)(struct r8152 *);
48920 void (*down)(struct r8152 *);
48921 void (*unload)(struct r8152 *);
48922- } rtl_ops;
48923+ } __no_const rtl_ops;
48924
48925 int intr_interval;
48926 u32 saved_wolopts;
48927diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
48928index a2515887..6d13233 100644
48929--- a/drivers/net/usb/sierra_net.c
48930+++ b/drivers/net/usb/sierra_net.c
48931@@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
48932 /* atomic counter partially included in MAC address to make sure 2 devices
48933 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
48934 */
48935-static atomic_t iface_counter = ATOMIC_INIT(0);
48936+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
48937
48938 /*
48939 * SYNC Timer Delay definition used to set the expiry time
48940@@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
48941 dev->net->netdev_ops = &sierra_net_device_ops;
48942
48943 /* change MAC addr to include, ifacenum, and to be unique */
48944- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
48945+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
48946 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
48947
48948 /* we will have to manufacture ethernet headers, prepare template */
48949diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
48950index 59caa06..de191b3 100644
48951--- a/drivers/net/virtio_net.c
48952+++ b/drivers/net/virtio_net.c
48953@@ -48,7 +48,7 @@ module_param(gso, bool, 0444);
48954 #define RECEIVE_AVG_WEIGHT 64
48955
48956 /* Minimum alignment for mergeable packet buffers. */
48957-#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
48958+#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
48959
48960 #define VIRTNET_DRIVER_VERSION "1.0.0"
48961
48962diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
48963index b483127..69aa8ff 100644
48964--- a/drivers/net/vxlan.c
48965+++ b/drivers/net/vxlan.c
48966@@ -274,13 +274,15 @@ static inline struct vxlan_rdst *first_remote_rtnl(struct vxlan_fdb *fdb)
48967 return list_first_entry(&fdb->remotes, struct vxlan_rdst, list);
48968 }
48969
48970-/* Find VXLAN socket based on network namespace and UDP port */
48971-static struct vxlan_sock *vxlan_find_sock(struct net *net, __be16 port)
48972+/* Find VXLAN socket based on network namespace, address family and UDP port */
48973+static struct vxlan_sock *vxlan_find_sock(struct net *net,
48974+ sa_family_t family, __be16 port)
48975 {
48976 struct vxlan_sock *vs;
48977
48978 hlist_for_each_entry_rcu(vs, vs_head(net, port), hlist) {
48979- if (inet_sk(vs->sock->sk)->inet_sport == port)
48980+ if (inet_sk(vs->sock->sk)->inet_sport == port &&
48981+ inet_sk(vs->sock->sk)->sk.sk_family == family)
48982 return vs;
48983 }
48984 return NULL;
48985@@ -299,11 +301,12 @@ static struct vxlan_dev *vxlan_vs_find_vni(struct vxlan_sock *vs, u32 id)
48986 }
48987
48988 /* Look up VNI in a per net namespace table */
48989-static struct vxlan_dev *vxlan_find_vni(struct net *net, u32 id, __be16 port)
48990+static struct vxlan_dev *vxlan_find_vni(struct net *net, u32 id,
48991+ sa_family_t family, __be16 port)
48992 {
48993 struct vxlan_sock *vs;
48994
48995- vs = vxlan_find_sock(net, port);
48996+ vs = vxlan_find_sock(net, family, port);
48997 if (!vs)
48998 return NULL;
48999
49000@@ -1820,7 +1823,8 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
49001 struct vxlan_dev *dst_vxlan;
49002
49003 ip_rt_put(rt);
49004- dst_vxlan = vxlan_find_vni(vxlan->net, vni, dst_port);
49005+ dst_vxlan = vxlan_find_vni(vxlan->net, vni,
49006+ dst->sa.sa_family, dst_port);
49007 if (!dst_vxlan)
49008 goto tx_error;
49009 vxlan_encap_bypass(skb, vxlan, dst_vxlan);
49010@@ -1874,7 +1878,8 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
49011 struct vxlan_dev *dst_vxlan;
49012
49013 dst_release(ndst);
49014- dst_vxlan = vxlan_find_vni(vxlan->net, vni, dst_port);
49015+ dst_vxlan = vxlan_find_vni(vxlan->net, vni,
49016+ dst->sa.sa_family, dst_port);
49017 if (!dst_vxlan)
49018 goto tx_error;
49019 vxlan_encap_bypass(skb, vxlan, dst_vxlan);
49020@@ -2034,13 +2039,15 @@ static int vxlan_init(struct net_device *dev)
49021 struct vxlan_dev *vxlan = netdev_priv(dev);
49022 struct vxlan_net *vn = net_generic(vxlan->net, vxlan_net_id);
49023 struct vxlan_sock *vs;
49024+ bool ipv6 = vxlan->flags & VXLAN_F_IPV6;
49025
49026 dev->tstats = netdev_alloc_pcpu_stats(struct pcpu_sw_netstats);
49027 if (!dev->tstats)
49028 return -ENOMEM;
49029
49030 spin_lock(&vn->sock_lock);
49031- vs = vxlan_find_sock(vxlan->net, vxlan->dst_port);
49032+ vs = vxlan_find_sock(vxlan->net, ipv6 ? AF_INET6 : AF_INET,
49033+ vxlan->dst_port);
49034 if (vs) {
49035 /* If we have a socket with same port already, reuse it */
49036 atomic_inc(&vs->refcnt);
49037@@ -2439,6 +2446,7 @@ struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port,
49038 {
49039 struct vxlan_net *vn = net_generic(net, vxlan_net_id);
49040 struct vxlan_sock *vs;
49041+ bool ipv6 = flags & VXLAN_F_IPV6;
49042
49043 vs = vxlan_socket_create(net, port, rcv, data, flags);
49044 if (!IS_ERR(vs))
49045@@ -2448,7 +2456,7 @@ struct vxlan_sock *vxlan_sock_add(struct net *net, __be16 port,
49046 return vs;
49047
49048 spin_lock(&vn->sock_lock);
49049- vs = vxlan_find_sock(net, port);
49050+ vs = vxlan_find_sock(net, ipv6 ? AF_INET6 : AF_INET, port);
49051 if (vs) {
49052 if (vs->rcv == rcv)
49053 atomic_inc(&vs->refcnt);
49054@@ -2607,7 +2615,8 @@ static int vxlan_newlink(struct net *net, struct net_device *dev,
49055 nla_get_u8(data[IFLA_VXLAN_UDP_ZERO_CSUM6_RX]))
49056 vxlan->flags |= VXLAN_F_UDP_ZERO_CSUM6_RX;
49057
49058- if (vxlan_find_vni(net, vni, vxlan->dst_port)) {
49059+ if (vxlan_find_vni(net, vni, use_ipv6 ? AF_INET6 : AF_INET,
49060+ vxlan->dst_port)) {
49061 pr_info("duplicate VNI %u\n", vni);
49062 return -EEXIST;
49063 }
49064@@ -2751,7 +2760,7 @@ nla_put_failure:
49065 return -EMSGSIZE;
49066 }
49067
49068-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
49069+static struct rtnl_link_ops vxlan_link_ops = {
49070 .kind = "vxlan",
49071 .maxtype = IFLA_VXLAN_MAX,
49072 .policy = vxlan_policy,
49073@@ -2798,7 +2807,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
49074 return NOTIFY_DONE;
49075 }
49076
49077-static struct notifier_block vxlan_notifier_block __read_mostly = {
49078+static struct notifier_block vxlan_notifier_block = {
49079 .notifier_call = vxlan_lowerdev_event,
49080 };
49081
49082diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
49083index 5920c99..ff2e4a5 100644
49084--- a/drivers/net/wan/lmc/lmc_media.c
49085+++ b/drivers/net/wan/lmc/lmc_media.c
49086@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
49087 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
49088
49089 lmc_media_t lmc_ds3_media = {
49090- lmc_ds3_init, /* special media init stuff */
49091- lmc_ds3_default, /* reset to default state */
49092- lmc_ds3_set_status, /* reset status to state provided */
49093- lmc_dummy_set_1, /* set clock source */
49094- lmc_dummy_set2_1, /* set line speed */
49095- lmc_ds3_set_100ft, /* set cable length */
49096- lmc_ds3_set_scram, /* set scrambler */
49097- lmc_ds3_get_link_status, /* get link status */
49098- lmc_dummy_set_1, /* set link status */
49099- lmc_ds3_set_crc_length, /* set CRC length */
49100- lmc_dummy_set_1, /* set T1 or E1 circuit type */
49101- lmc_ds3_watchdog
49102+ .init = lmc_ds3_init, /* special media init stuff */
49103+ .defaults = lmc_ds3_default, /* reset to default state */
49104+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
49105+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
49106+ .set_speed = lmc_dummy_set2_1, /* set line speed */
49107+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
49108+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
49109+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
49110+ .set_link_status = lmc_dummy_set_1, /* set link status */
49111+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
49112+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49113+ .watchdog = lmc_ds3_watchdog
49114 };
49115
49116 lmc_media_t lmc_hssi_media = {
49117- lmc_hssi_init, /* special media init stuff */
49118- lmc_hssi_default, /* reset to default state */
49119- lmc_hssi_set_status, /* reset status to state provided */
49120- lmc_hssi_set_clock, /* set clock source */
49121- lmc_dummy_set2_1, /* set line speed */
49122- lmc_dummy_set_1, /* set cable length */
49123- lmc_dummy_set_1, /* set scrambler */
49124- lmc_hssi_get_link_status, /* get link status */
49125- lmc_hssi_set_link_status, /* set link status */
49126- lmc_hssi_set_crc_length, /* set CRC length */
49127- lmc_dummy_set_1, /* set T1 or E1 circuit type */
49128- lmc_hssi_watchdog
49129+ .init = lmc_hssi_init, /* special media init stuff */
49130+ .defaults = lmc_hssi_default, /* reset to default state */
49131+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
49132+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
49133+ .set_speed = lmc_dummy_set2_1, /* set line speed */
49134+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
49135+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49136+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
49137+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
49138+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
49139+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49140+ .watchdog = lmc_hssi_watchdog
49141 };
49142
49143-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
49144- lmc_ssi_default, /* reset to default state */
49145- lmc_ssi_set_status, /* reset status to state provided */
49146- lmc_ssi_set_clock, /* set clock source */
49147- lmc_ssi_set_speed, /* set line speed */
49148- lmc_dummy_set_1, /* set cable length */
49149- lmc_dummy_set_1, /* set scrambler */
49150- lmc_ssi_get_link_status, /* get link status */
49151- lmc_ssi_set_link_status, /* set link status */
49152- lmc_ssi_set_crc_length, /* set CRC length */
49153- lmc_dummy_set_1, /* set T1 or E1 circuit type */
49154- lmc_ssi_watchdog
49155+lmc_media_t lmc_ssi_media = {
49156+ .init = lmc_ssi_init, /* special media init stuff */
49157+ .defaults = lmc_ssi_default, /* reset to default state */
49158+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
49159+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
49160+ .set_speed = lmc_ssi_set_speed, /* set line speed */
49161+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
49162+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49163+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
49164+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
49165+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
49166+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
49167+ .watchdog = lmc_ssi_watchdog
49168 };
49169
49170 lmc_media_t lmc_t1_media = {
49171- lmc_t1_init, /* special media init stuff */
49172- lmc_t1_default, /* reset to default state */
49173- lmc_t1_set_status, /* reset status to state provided */
49174- lmc_t1_set_clock, /* set clock source */
49175- lmc_dummy_set2_1, /* set line speed */
49176- lmc_dummy_set_1, /* set cable length */
49177- lmc_dummy_set_1, /* set scrambler */
49178- lmc_t1_get_link_status, /* get link status */
49179- lmc_dummy_set_1, /* set link status */
49180- lmc_t1_set_crc_length, /* set CRC length */
49181- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
49182- lmc_t1_watchdog
49183+ .init = lmc_t1_init, /* special media init stuff */
49184+ .defaults = lmc_t1_default, /* reset to default state */
49185+ .set_status = lmc_t1_set_status, /* reset status to state provided */
49186+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
49187+ .set_speed = lmc_dummy_set2_1, /* set line speed */
49188+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
49189+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
49190+ .get_link_status = lmc_t1_get_link_status, /* get link status */
49191+ .set_link_status = lmc_dummy_set_1, /* set link status */
49192+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
49193+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
49194+ .watchdog = lmc_t1_watchdog
49195 };
49196
49197 static void
49198diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
49199index feacc3b..5bac0de 100644
49200--- a/drivers/net/wan/z85230.c
49201+++ b/drivers/net/wan/z85230.c
49202@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
49203
49204 struct z8530_irqhandler z8530_sync =
49205 {
49206- z8530_rx,
49207- z8530_tx,
49208- z8530_status
49209+ .rx = z8530_rx,
49210+ .tx = z8530_tx,
49211+ .status = z8530_status
49212 };
49213
49214 EXPORT_SYMBOL(z8530_sync);
49215@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
49216 }
49217
49218 static struct z8530_irqhandler z8530_dma_sync = {
49219- z8530_dma_rx,
49220- z8530_dma_tx,
49221- z8530_dma_status
49222+ .rx = z8530_dma_rx,
49223+ .tx = z8530_dma_tx,
49224+ .status = z8530_dma_status
49225 };
49226
49227 static struct z8530_irqhandler z8530_txdma_sync = {
49228- z8530_rx,
49229- z8530_dma_tx,
49230- z8530_dma_status
49231+ .rx = z8530_rx,
49232+ .tx = z8530_dma_tx,
49233+ .status = z8530_dma_status
49234 };
49235
49236 /**
49237@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
49238
49239 struct z8530_irqhandler z8530_nop=
49240 {
49241- z8530_rx_clear,
49242- z8530_tx_clear,
49243- z8530_status_clear
49244+ .rx = z8530_rx_clear,
49245+ .tx = z8530_tx_clear,
49246+ .status = z8530_status_clear
49247 };
49248
49249
49250diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
49251index 0b60295..b8bfa5b 100644
49252--- a/drivers/net/wimax/i2400m/rx.c
49253+++ b/drivers/net/wimax/i2400m/rx.c
49254@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
49255 if (i2400m->rx_roq == NULL)
49256 goto error_roq_alloc;
49257
49258- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
49259+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
49260 GFP_KERNEL);
49261 if (rd == NULL) {
49262 result = -ENOMEM;
49263diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
49264index e71a2ce..2268d61 100644
49265--- a/drivers/net/wireless/airo.c
49266+++ b/drivers/net/wireless/airo.c
49267@@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
49268 struct airo_info *ai = dev->ml_priv;
49269 int ridcode;
49270 int enabled;
49271- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49272+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
49273 unsigned char *iobuf;
49274
49275 /* Only super-user can write RIDs */
49276diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
49277index da92bfa..5a9001a 100644
49278--- a/drivers/net/wireless/at76c50x-usb.c
49279+++ b/drivers/net/wireless/at76c50x-usb.c
49280@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
49281 }
49282
49283 /* Convert timeout from the DFU status to jiffies */
49284-static inline unsigned long at76_get_timeout(struct dfu_status *s)
49285+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
49286 {
49287 return msecs_to_jiffies((s->poll_timeout[2] << 16)
49288 | (s->poll_timeout[1] << 8)
49289diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
49290index 5fdc40d..3975205 100644
49291--- a/drivers/net/wireless/ath/ath10k/htc.c
49292+++ b/drivers/net/wireless/ath/ath10k/htc.c
49293@@ -856,7 +856,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
49294 /* registered target arrival callback from the HIF layer */
49295 int ath10k_htc_init(struct ath10k *ar)
49296 {
49297- struct ath10k_hif_cb htc_callbacks;
49298+ static struct ath10k_hif_cb htc_callbacks = {
49299+ .rx_completion = ath10k_htc_rx_completion_handler,
49300+ .tx_completion = ath10k_htc_tx_completion_handler,
49301+ };
49302 struct ath10k_htc_ep *ep = NULL;
49303 struct ath10k_htc *htc = &ar->htc;
49304
49305@@ -866,8 +869,6 @@ int ath10k_htc_init(struct ath10k *ar)
49306 ath10k_htc_reset_endpoint_states(htc);
49307
49308 /* setup HIF layer callbacks */
49309- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
49310- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
49311 htc->ar = ar;
49312
49313 /* Get HIF default pipe for HTC message exchange */
49314diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
49315index 4716d33..a688310 100644
49316--- a/drivers/net/wireless/ath/ath10k/htc.h
49317+++ b/drivers/net/wireless/ath/ath10k/htc.h
49318@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
49319
49320 struct ath10k_htc_ops {
49321 void (*target_send_suspend_complete)(struct ath10k *ar);
49322-};
49323+} __no_const;
49324
49325 struct ath10k_htc_ep_ops {
49326 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
49327 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
49328 void (*ep_tx_credits)(struct ath10k *);
49329-};
49330+} __no_const;
49331
49332 /* service connection information */
49333 struct ath10k_htc_svc_conn_req {
49334diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49335index 59af9f9..5f3564f 100644
49336--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49337+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
49338@@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49339 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
49340 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
49341
49342- ACCESS_ONCE(ads->ds_link) = i->link;
49343- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
49344+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
49345+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
49346
49347 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
49348 ctl6 = SM(i->keytype, AR_EncrType);
49349@@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49350
49351 if ((i->is_first || i->is_last) &&
49352 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
49353- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
49354+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
49355 | set11nTries(i->rates, 1)
49356 | set11nTries(i->rates, 2)
49357 | set11nTries(i->rates, 3)
49358 | (i->dur_update ? AR_DurUpdateEna : 0)
49359 | SM(0, AR_BurstDur);
49360
49361- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
49362+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
49363 | set11nRate(i->rates, 1)
49364 | set11nRate(i->rates, 2)
49365 | set11nRate(i->rates, 3);
49366 } else {
49367- ACCESS_ONCE(ads->ds_ctl2) = 0;
49368- ACCESS_ONCE(ads->ds_ctl3) = 0;
49369+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
49370+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
49371 }
49372
49373 if (!i->is_first) {
49374- ACCESS_ONCE(ads->ds_ctl0) = 0;
49375- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49376- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49377+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
49378+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49379+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49380 return;
49381 }
49382
49383@@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49384 break;
49385 }
49386
49387- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49388+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
49389 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49390 | SM(i->txpower, AR_XmitPower0)
49391 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49392@@ -289,27 +289,27 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49393 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
49394 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
49395
49396- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
49397- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
49398+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
49399+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
49400
49401 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
49402 return;
49403
49404- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49405+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
49406 | set11nPktDurRTSCTS(i->rates, 1);
49407
49408- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49409+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
49410 | set11nPktDurRTSCTS(i->rates, 3);
49411
49412- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49413+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
49414 | set11nRateFlags(i->rates, 1)
49415 | set11nRateFlags(i->rates, 2)
49416 | set11nRateFlags(i->rates, 3)
49417 | SM(i->rtscts_rate, AR_RTSCTSRate);
49418
49419- ACCESS_ONCE(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49420- ACCESS_ONCE(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49421- ACCESS_ONCE(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49422+ ACCESS_ONCE_RW(ads->ds_ctl9) = SM(i->txpower, AR_XmitPower1);
49423+ ACCESS_ONCE_RW(ads->ds_ctl10) = SM(i->txpower, AR_XmitPower2);
49424+ ACCESS_ONCE_RW(ads->ds_ctl11) = SM(i->txpower, AR_XmitPower3);
49425 }
49426
49427 static int ar9002_hw_proc_txdesc(struct ath_hw *ah, void *ds,
49428diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49429index 71e38e8..5ac96ca 100644
49430--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49431+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
49432@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49433 (i->qcu << AR_TxQcuNum_S) | desc_len;
49434
49435 checksum += val;
49436- ACCESS_ONCE(ads->info) = val;
49437+ ACCESS_ONCE_RW(ads->info) = val;
49438
49439 checksum += i->link;
49440- ACCESS_ONCE(ads->link) = i->link;
49441+ ACCESS_ONCE_RW(ads->link) = i->link;
49442
49443 checksum += i->buf_addr[0];
49444- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
49445+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
49446 checksum += i->buf_addr[1];
49447- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
49448+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
49449 checksum += i->buf_addr[2];
49450- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
49451+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
49452 checksum += i->buf_addr[3];
49453- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
49454+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
49455
49456 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
49457- ACCESS_ONCE(ads->ctl3) = val;
49458+ ACCESS_ONCE_RW(ads->ctl3) = val;
49459 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
49460- ACCESS_ONCE(ads->ctl5) = val;
49461+ ACCESS_ONCE_RW(ads->ctl5) = val;
49462 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
49463- ACCESS_ONCE(ads->ctl7) = val;
49464+ ACCESS_ONCE_RW(ads->ctl7) = val;
49465 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
49466- ACCESS_ONCE(ads->ctl9) = val;
49467+ ACCESS_ONCE_RW(ads->ctl9) = val;
49468
49469 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
49470- ACCESS_ONCE(ads->ctl10) = checksum;
49471+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
49472
49473 if (i->is_first || i->is_last) {
49474- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
49475+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
49476 | set11nTries(i->rates, 1)
49477 | set11nTries(i->rates, 2)
49478 | set11nTries(i->rates, 3)
49479 | (i->dur_update ? AR_DurUpdateEna : 0)
49480 | SM(0, AR_BurstDur);
49481
49482- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
49483+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
49484 | set11nRate(i->rates, 1)
49485 | set11nRate(i->rates, 2)
49486 | set11nRate(i->rates, 3);
49487 } else {
49488- ACCESS_ONCE(ads->ctl13) = 0;
49489- ACCESS_ONCE(ads->ctl14) = 0;
49490+ ACCESS_ONCE_RW(ads->ctl13) = 0;
49491+ ACCESS_ONCE_RW(ads->ctl14) = 0;
49492 }
49493
49494 ads->ctl20 = 0;
49495@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49496
49497 ctl17 = SM(i->keytype, AR_EncrType);
49498 if (!i->is_first) {
49499- ACCESS_ONCE(ads->ctl11) = 0;
49500- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49501- ACCESS_ONCE(ads->ctl15) = 0;
49502- ACCESS_ONCE(ads->ctl16) = 0;
49503- ACCESS_ONCE(ads->ctl17) = ctl17;
49504- ACCESS_ONCE(ads->ctl18) = 0;
49505- ACCESS_ONCE(ads->ctl19) = 0;
49506+ ACCESS_ONCE_RW(ads->ctl11) = 0;
49507+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
49508+ ACCESS_ONCE_RW(ads->ctl15) = 0;
49509+ ACCESS_ONCE_RW(ads->ctl16) = 0;
49510+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49511+ ACCESS_ONCE_RW(ads->ctl18) = 0;
49512+ ACCESS_ONCE_RW(ads->ctl19) = 0;
49513 return;
49514 }
49515
49516- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49517+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
49518 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
49519 | SM(i->txpower, AR_XmitPower0)
49520 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
49521@@ -135,26 +135,26 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
49522 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
49523 ctl12 |= SM(val, AR_PAPRDChainMask);
49524
49525- ACCESS_ONCE(ads->ctl12) = ctl12;
49526- ACCESS_ONCE(ads->ctl17) = ctl17;
49527+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
49528+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
49529
49530- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49531+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
49532 | set11nPktDurRTSCTS(i->rates, 1);
49533
49534- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49535+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
49536 | set11nPktDurRTSCTS(i->rates, 3);
49537
49538- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
49539+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
49540 | set11nRateFlags(i->rates, 1)
49541 | set11nRateFlags(i->rates, 2)
49542 | set11nRateFlags(i->rates, 3)
49543 | SM(i->rtscts_rate, AR_RTSCTSRate);
49544
49545- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
49546+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
49547
49548- ACCESS_ONCE(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49549- ACCESS_ONCE(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49550- ACCESS_ONCE(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49551+ ACCESS_ONCE_RW(ads->ctl20) = SM(i->txpower, AR_XmitPower1);
49552+ ACCESS_ONCE_RW(ads->ctl21) = SM(i->txpower, AR_XmitPower2);
49553+ ACCESS_ONCE_RW(ads->ctl22) = SM(i->txpower, AR_XmitPower3);
49554 }
49555
49556 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
49557diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
49558index 51b4ebe..d1929dd 100644
49559--- a/drivers/net/wireless/ath/ath9k/hw.h
49560+++ b/drivers/net/wireless/ath/ath9k/hw.h
49561@@ -629,7 +629,7 @@ struct ath_hw_private_ops {
49562
49563 /* ANI */
49564 void (*ani_cache_ini_regs)(struct ath_hw *ah);
49565-};
49566+} __no_const;
49567
49568 /**
49569 * struct ath_spec_scan - parameters for Atheros spectral scan
49570@@ -706,7 +706,7 @@ struct ath_hw_ops {
49571 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
49572 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
49573 #endif
49574-};
49575+} __no_const;
49576
49577 struct ath_nf_limits {
49578 s16 max;
49579diff --git a/drivers/net/wireless/ath/ath9k/main.c b/drivers/net/wireless/ath/ath9k/main.c
49580index 4b148bb..ac738fa 100644
49581--- a/drivers/net/wireless/ath/ath9k/main.c
49582+++ b/drivers/net/wireless/ath/ath9k/main.c
49583@@ -2592,16 +2592,18 @@ void ath9k_fill_chanctx_ops(void)
49584 if (!ath9k_use_chanctx)
49585 return;
49586
49587- ath9k_ops.hw_scan = ath9k_hw_scan;
49588- ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49589- ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49590- ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49591- ath9k_ops.add_chanctx = ath9k_add_chanctx;
49592- ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49593- ath9k_ops.change_chanctx = ath9k_change_chanctx;
49594- ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49595- ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49596- ath9k_ops.mgd_prepare_tx = ath9k_chanctx_force_active;
49597+ pax_open_kernel();
49598+ *(void **)&ath9k_ops.hw_scan = ath9k_hw_scan;
49599+ *(void **)&ath9k_ops.cancel_hw_scan = ath9k_cancel_hw_scan;
49600+ *(void **)&ath9k_ops.remain_on_channel = ath9k_remain_on_channel;
49601+ *(void **)&ath9k_ops.cancel_remain_on_channel = ath9k_cancel_remain_on_channel;
49602+ *(void **)&ath9k_ops.add_chanctx = ath9k_add_chanctx;
49603+ *(void **)&ath9k_ops.remove_chanctx = ath9k_remove_chanctx;
49604+ *(void **)&ath9k_ops.change_chanctx = ath9k_change_chanctx;
49605+ *(void **)&ath9k_ops.assign_vif_chanctx = ath9k_assign_vif_chanctx;
49606+ *(void **)&ath9k_ops.unassign_vif_chanctx = ath9k_unassign_vif_chanctx;
49607+ *(void **)&ath9k_ops.mgd_prepare_tx = ath9k_chanctx_force_active;
49608+ pax_close_kernel();
49609 }
49610
49611 struct ieee80211_ops ath9k_ops = {
49612diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
49613index 92190da..f3a4c4c 100644
49614--- a/drivers/net/wireless/b43/phy_lp.c
49615+++ b/drivers/net/wireless/b43/phy_lp.c
49616@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
49617 {
49618 struct ssb_bus *bus = dev->dev->sdev->bus;
49619
49620- static const struct b206x_channel *chandata = NULL;
49621+ const struct b206x_channel *chandata = NULL;
49622 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
49623 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
49624 u16 old_comm15, scale;
49625diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
49626index dc1d20c..f7a4f06 100644
49627--- a/drivers/net/wireless/iwlegacy/3945-mac.c
49628+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
49629@@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
49630 */
49631 if (il3945_mod_params.disable_hw_scan) {
49632 D_INFO("Disabling hw_scan\n");
49633- il3945_mac_ops.hw_scan = NULL;
49634+ pax_open_kernel();
49635+ *(void **)&il3945_mac_ops.hw_scan = NULL;
49636+ pax_close_kernel();
49637 }
49638
49639 D_INFO("*** LOAD DRIVER ***\n");
49640diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49641index 0ffb6ff..c0b7f0e 100644
49642--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49643+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
49644@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
49645 {
49646 struct iwl_priv *priv = file->private_data;
49647 char buf[64];
49648- int buf_size;
49649+ size_t buf_size;
49650 u32 offset, len;
49651
49652 memset(buf, 0, sizeof(buf));
49653@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
49654 struct iwl_priv *priv = file->private_data;
49655
49656 char buf[8];
49657- int buf_size;
49658+ size_t buf_size;
49659 u32 reset_flag;
49660
49661 memset(buf, 0, sizeof(buf));
49662@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
49663 {
49664 struct iwl_priv *priv = file->private_data;
49665 char buf[8];
49666- int buf_size;
49667+ size_t buf_size;
49668 int ht40;
49669
49670 memset(buf, 0, sizeof(buf));
49671@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
49672 {
49673 struct iwl_priv *priv = file->private_data;
49674 char buf[8];
49675- int buf_size;
49676+ size_t buf_size;
49677 int value;
49678
49679 memset(buf, 0, sizeof(buf));
49680@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
49681 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
49682 DEBUGFS_READ_FILE_OPS(current_sleep_command);
49683
49684-static const char *fmt_value = " %-30s %10u\n";
49685-static const char *fmt_hex = " %-30s 0x%02X\n";
49686-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
49687-static const char *fmt_header =
49688+static const char fmt_value[] = " %-30s %10u\n";
49689+static const char fmt_hex[] = " %-30s 0x%02X\n";
49690+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
49691+static const char fmt_header[] =
49692 "%-32s current cumulative delta max\n";
49693
49694 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
49695@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
49696 {
49697 struct iwl_priv *priv = file->private_data;
49698 char buf[8];
49699- int buf_size;
49700+ size_t buf_size;
49701 int clear;
49702
49703 memset(buf, 0, sizeof(buf));
49704@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
49705 {
49706 struct iwl_priv *priv = file->private_data;
49707 char buf[8];
49708- int buf_size;
49709+ size_t buf_size;
49710 int trace;
49711
49712 memset(buf, 0, sizeof(buf));
49713@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
49714 {
49715 struct iwl_priv *priv = file->private_data;
49716 char buf[8];
49717- int buf_size;
49718+ size_t buf_size;
49719 int missed;
49720
49721 memset(buf, 0, sizeof(buf));
49722@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
49723
49724 struct iwl_priv *priv = file->private_data;
49725 char buf[8];
49726- int buf_size;
49727+ size_t buf_size;
49728 int plcp;
49729
49730 memset(buf, 0, sizeof(buf));
49731@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
49732
49733 struct iwl_priv *priv = file->private_data;
49734 char buf[8];
49735- int buf_size;
49736+ size_t buf_size;
49737 int flush;
49738
49739 memset(buf, 0, sizeof(buf));
49740@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
49741
49742 struct iwl_priv *priv = file->private_data;
49743 char buf[8];
49744- int buf_size;
49745+ size_t buf_size;
49746 int rts;
49747
49748 if (!priv->cfg->ht_params)
49749@@ -2204,7 +2204,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
49750 {
49751 struct iwl_priv *priv = file->private_data;
49752 char buf[8];
49753- int buf_size;
49754+ size_t buf_size;
49755
49756 memset(buf, 0, sizeof(buf));
49757 buf_size = min(count, sizeof(buf) - 1);
49758@@ -2238,7 +2238,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
49759 struct iwl_priv *priv = file->private_data;
49760 u32 event_log_flag;
49761 char buf[8];
49762- int buf_size;
49763+ size_t buf_size;
49764
49765 /* check that the interface is up */
49766 if (!iwl_is_ready(priv))
49767@@ -2292,7 +2292,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
49768 struct iwl_priv *priv = file->private_data;
49769 char buf[8];
49770 u32 calib_disabled;
49771- int buf_size;
49772+ size_t buf_size;
49773
49774 memset(buf, 0, sizeof(buf));
49775 buf_size = min(count, sizeof(buf) - 1);
49776diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
49777index d7231a8..80df8ba 100644
49778--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
49779+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
49780@@ -1686,7 +1686,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
49781 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
49782
49783 char buf[8];
49784- int buf_size;
49785+ size_t buf_size;
49786 u32 reset_flag;
49787
49788 memset(buf, 0, sizeof(buf));
49789@@ -1707,7 +1707,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
49790 {
49791 struct iwl_trans *trans = file->private_data;
49792 char buf[8];
49793- int buf_size;
49794+ size_t buf_size;
49795 int csr;
49796
49797 memset(buf, 0, sizeof(buf));
49798diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
49799index 1326f61..9e56010f 100644
49800--- a/drivers/net/wireless/mac80211_hwsim.c
49801+++ b/drivers/net/wireless/mac80211_hwsim.c
49802@@ -2575,20 +2575,20 @@ static int __init init_mac80211_hwsim(void)
49803 if (channels < 1)
49804 return -EINVAL;
49805
49806- mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
49807- mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49808- mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49809- mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49810- mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49811- mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49812- mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49813- mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49814- mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49815- mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49816- mac80211_hwsim_mchan_ops.assign_vif_chanctx =
49817- mac80211_hwsim_assign_vif_chanctx;
49818- mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
49819- mac80211_hwsim_unassign_vif_chanctx;
49820+ pax_open_kernel();
49821+ memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
49822+ *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
49823+ *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
49824+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
49825+ *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
49826+ *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
49827+ *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
49828+ *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
49829+ *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
49830+ *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
49831+ *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
49832+ *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
49833+ pax_close_kernel();
49834
49835 spin_lock_init(&hwsim_radio_lock);
49836 INIT_LIST_HEAD(&hwsim_radios);
49837diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
49838index d2a9a08..0cb175d 100644
49839--- a/drivers/net/wireless/rndis_wlan.c
49840+++ b/drivers/net/wireless/rndis_wlan.c
49841@@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
49842
49843 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
49844
49845- if (rts_threshold < 0 || rts_threshold > 2347)
49846+ if (rts_threshold > 2347)
49847 rts_threshold = 2347;
49848
49849 tmp = cpu_to_le32(rts_threshold);
49850diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
49851index d13f25c..2573994 100644
49852--- a/drivers/net/wireless/rt2x00/rt2x00.h
49853+++ b/drivers/net/wireless/rt2x00/rt2x00.h
49854@@ -375,7 +375,7 @@ struct rt2x00_intf {
49855 * for hardware which doesn't support hardware
49856 * sequence counting.
49857 */
49858- atomic_t seqno;
49859+ atomic_unchecked_t seqno;
49860 };
49861
49862 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
49863diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
49864index 8e68f87..c35ba29 100644
49865--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
49866+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
49867@@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
49868 * sequence counter given by mac80211.
49869 */
49870 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
49871- seqno = atomic_add_return(0x10, &intf->seqno);
49872+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
49873 else
49874- seqno = atomic_read(&intf->seqno);
49875+ seqno = atomic_read_unchecked(&intf->seqno);
49876
49877 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
49878 hdr->seq_ctrl |= cpu_to_le16(seqno);
49879diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
49880index b661f896..ddf7d2b 100644
49881--- a/drivers/net/wireless/ti/wl1251/sdio.c
49882+++ b/drivers/net/wireless/ti/wl1251/sdio.c
49883@@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
49884
49885 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
49886
49887- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49888- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49889+ pax_open_kernel();
49890+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
49891+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
49892+ pax_close_kernel();
49893
49894 wl1251_info("using dedicated interrupt line");
49895 } else {
49896- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49897- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49898+ pax_open_kernel();
49899+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
49900+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
49901+ pax_close_kernel();
49902
49903 wl1251_info("using SDIO interrupt");
49904 }
49905diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
49906index 0bccf12..3d95068 100644
49907--- a/drivers/net/wireless/ti/wl12xx/main.c
49908+++ b/drivers/net/wireless/ti/wl12xx/main.c
49909@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49910 sizeof(wl->conf.mem));
49911
49912 /* read data preparation is only needed by wl127x */
49913- wl->ops->prepare_read = wl127x_prepare_read;
49914+ pax_open_kernel();
49915+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49916+ pax_close_kernel();
49917
49918 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49919 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49920@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
49921 sizeof(wl->conf.mem));
49922
49923 /* read data preparation is only needed by wl127x */
49924- wl->ops->prepare_read = wl127x_prepare_read;
49925+ pax_open_kernel();
49926+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
49927+ pax_close_kernel();
49928
49929 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
49930 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
49931diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
49932index 7af1936..128bb35 100644
49933--- a/drivers/net/wireless/ti/wl18xx/main.c
49934+++ b/drivers/net/wireless/ti/wl18xx/main.c
49935@@ -1916,8 +1916,10 @@ static int wl18xx_setup(struct wl1271 *wl)
49936 }
49937
49938 if (!checksum_param) {
49939- wl18xx_ops.set_rx_csum = NULL;
49940- wl18xx_ops.init_vif = NULL;
49941+ pax_open_kernel();
49942+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
49943+ *(void **)&wl18xx_ops.init_vif = NULL;
49944+ pax_close_kernel();
49945 }
49946
49947 /* Enable 11a Band only if we have 5G antennas */
49948diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
49949index a912dc0..a8225ba 100644
49950--- a/drivers/net/wireless/zd1211rw/zd_usb.c
49951+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
49952@@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
49953 {
49954 struct zd_usb *usb = urb->context;
49955 struct zd_usb_interrupt *intr = &usb->intr;
49956- int len;
49957+ unsigned int len;
49958 u16 int_num;
49959
49960 ZD_ASSERT(in_interrupt());
49961diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
49962index 683671a..4519fc2 100644
49963--- a/drivers/nfc/nfcwilink.c
49964+++ b/drivers/nfc/nfcwilink.c
49965@@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
49966
49967 static int nfcwilink_probe(struct platform_device *pdev)
49968 {
49969- static struct nfcwilink *drv;
49970+ struct nfcwilink *drv;
49971 int rc;
49972 __u32 protocols;
49973
49974diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
49975index d93b2b6..ae50401 100644
49976--- a/drivers/oprofile/buffer_sync.c
49977+++ b/drivers/oprofile/buffer_sync.c
49978@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
49979 if (cookie == NO_COOKIE)
49980 offset = pc;
49981 if (cookie == INVALID_COOKIE) {
49982- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
49983+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
49984 offset = pc;
49985 }
49986 if (cookie != last_cookie) {
49987@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
49988 /* add userspace sample */
49989
49990 if (!mm) {
49991- atomic_inc(&oprofile_stats.sample_lost_no_mm);
49992+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
49993 return 0;
49994 }
49995
49996 cookie = lookup_dcookie(mm, s->eip, &offset);
49997
49998 if (cookie == INVALID_COOKIE) {
49999- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
50000+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
50001 return 0;
50002 }
50003
50004@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
50005 /* ignore backtraces if failed to add a sample */
50006 if (state == sb_bt_start) {
50007 state = sb_bt_ignore;
50008- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
50009+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
50010 }
50011 }
50012 release_mm(mm);
50013diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
50014index c0cc4e7..44d4e54 100644
50015--- a/drivers/oprofile/event_buffer.c
50016+++ b/drivers/oprofile/event_buffer.c
50017@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
50018 }
50019
50020 if (buffer_pos == buffer_size) {
50021- atomic_inc(&oprofile_stats.event_lost_overflow);
50022+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
50023 return;
50024 }
50025
50026diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
50027index ed2c3ec..deda85a 100644
50028--- a/drivers/oprofile/oprof.c
50029+++ b/drivers/oprofile/oprof.c
50030@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
50031 if (oprofile_ops.switch_events())
50032 return;
50033
50034- atomic_inc(&oprofile_stats.multiplex_counter);
50035+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
50036 start_switch_worker();
50037 }
50038
50039diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
50040index ee2cfce..7f8f699 100644
50041--- a/drivers/oprofile/oprofile_files.c
50042+++ b/drivers/oprofile/oprofile_files.c
50043@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
50044
50045 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
50046
50047-static ssize_t timeout_read(struct file *file, char __user *buf,
50048+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
50049 size_t count, loff_t *offset)
50050 {
50051 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
50052diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
50053index 59659ce..6c860a0 100644
50054--- a/drivers/oprofile/oprofile_stats.c
50055+++ b/drivers/oprofile/oprofile_stats.c
50056@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
50057 cpu_buf->sample_invalid_eip = 0;
50058 }
50059
50060- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
50061- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
50062- atomic_set(&oprofile_stats.event_lost_overflow, 0);
50063- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
50064- atomic_set(&oprofile_stats.multiplex_counter, 0);
50065+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
50066+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
50067+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
50068+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
50069+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
50070 }
50071
50072
50073diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
50074index 1fc622b..8c48fc3 100644
50075--- a/drivers/oprofile/oprofile_stats.h
50076+++ b/drivers/oprofile/oprofile_stats.h
50077@@ -13,11 +13,11 @@
50078 #include <linux/atomic.h>
50079
50080 struct oprofile_stat_struct {
50081- atomic_t sample_lost_no_mm;
50082- atomic_t sample_lost_no_mapping;
50083- atomic_t bt_lost_no_mapping;
50084- atomic_t event_lost_overflow;
50085- atomic_t multiplex_counter;
50086+ atomic_unchecked_t sample_lost_no_mm;
50087+ atomic_unchecked_t sample_lost_no_mapping;
50088+ atomic_unchecked_t bt_lost_no_mapping;
50089+ atomic_unchecked_t event_lost_overflow;
50090+ atomic_unchecked_t multiplex_counter;
50091 };
50092
50093 extern struct oprofile_stat_struct oprofile_stats;
50094diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
50095index 3f49345..c750d0b 100644
50096--- a/drivers/oprofile/oprofilefs.c
50097+++ b/drivers/oprofile/oprofilefs.c
50098@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
50099
50100 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
50101 {
50102- atomic_t *val = file->private_data;
50103- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
50104+ atomic_unchecked_t *val = file->private_data;
50105+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
50106 }
50107
50108
50109@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
50110
50111
50112 int oprofilefs_create_ro_atomic(struct dentry *root,
50113- char const *name, atomic_t *val)
50114+ char const *name, atomic_unchecked_t *val)
50115 {
50116 return __oprofilefs_create_file(root, name,
50117 &atomic_ro_fops, 0444, val);
50118diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
50119index 61be1d9..dec05d7 100644
50120--- a/drivers/oprofile/timer_int.c
50121+++ b/drivers/oprofile/timer_int.c
50122@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
50123 return NOTIFY_OK;
50124 }
50125
50126-static struct notifier_block __refdata oprofile_cpu_notifier = {
50127+static struct notifier_block oprofile_cpu_notifier = {
50128 .notifier_call = oprofile_cpu_notify,
50129 };
50130
50131diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
50132index 3b47080..6cd05dd 100644
50133--- a/drivers/parport/procfs.c
50134+++ b/drivers/parport/procfs.c
50135@@ -64,7 +64,7 @@ static int do_active_device(struct ctl_table *table, int write,
50136
50137 *ppos += len;
50138
50139- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
50140+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
50141 }
50142
50143 #ifdef CONFIG_PARPORT_1284
50144@@ -106,7 +106,7 @@ static int do_autoprobe(struct ctl_table *table, int write,
50145
50146 *ppos += len;
50147
50148- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
50149+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
50150 }
50151 #endif /* IEEE1284.3 support. */
50152
50153diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
50154index 8dcccff..35d701d 100644
50155--- a/drivers/pci/hotplug/acpiphp_ibm.c
50156+++ b/drivers/pci/hotplug/acpiphp_ibm.c
50157@@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
50158 goto init_cleanup;
50159 }
50160
50161- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50162+ pax_open_kernel();
50163+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
50164+ pax_close_kernel();
50165 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
50166
50167 return retval;
50168diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
50169index 04fcd78..39e83f1 100644
50170--- a/drivers/pci/hotplug/cpcihp_generic.c
50171+++ b/drivers/pci/hotplug/cpcihp_generic.c
50172@@ -73,7 +73,6 @@ static u16 port;
50173 static unsigned int enum_bit;
50174 static u8 enum_mask;
50175
50176-static struct cpci_hp_controller_ops generic_hpc_ops;
50177 static struct cpci_hp_controller generic_hpc;
50178
50179 static int __init validate_parameters(void)
50180@@ -139,6 +138,10 @@ static int query_enum(void)
50181 return ((value & enum_mask) == enum_mask);
50182 }
50183
50184+static struct cpci_hp_controller_ops generic_hpc_ops = {
50185+ .query_enum = query_enum,
50186+};
50187+
50188 static int __init cpcihp_generic_init(void)
50189 {
50190 int status;
50191@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
50192 pci_dev_put(dev);
50193
50194 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
50195- generic_hpc_ops.query_enum = query_enum;
50196 generic_hpc.ops = &generic_hpc_ops;
50197
50198 status = cpci_hp_register_controller(&generic_hpc);
50199diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
50200index 6757b3e..d3bad62 100644
50201--- a/drivers/pci/hotplug/cpcihp_zt5550.c
50202+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
50203@@ -59,7 +59,6 @@
50204 /* local variables */
50205 static bool debug;
50206 static bool poll;
50207-static struct cpci_hp_controller_ops zt5550_hpc_ops;
50208 static struct cpci_hp_controller zt5550_hpc;
50209
50210 /* Primary cPCI bus bridge device */
50211@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
50212 return 0;
50213 }
50214
50215+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
50216+ .query_enum = zt5550_hc_query_enum,
50217+};
50218+
50219 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
50220 {
50221 int status;
50222@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
50223 dbg("returned from zt5550_hc_config");
50224
50225 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
50226- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
50227 zt5550_hpc.ops = &zt5550_hpc_ops;
50228 if(!poll) {
50229 zt5550_hpc.irq = hc_dev->irq;
50230 zt5550_hpc.irq_flags = IRQF_SHARED;
50231 zt5550_hpc.dev_id = hc_dev;
50232
50233- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50234- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50235- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50236+ pax_open_kernel();
50237+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
50238+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
50239+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
50240+ pax_open_kernel();
50241 } else {
50242 info("using ENUM# polling mode");
50243 }
50244diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
50245index 0968a9b..5a00edf 100644
50246--- a/drivers/pci/hotplug/cpqphp_nvram.c
50247+++ b/drivers/pci/hotplug/cpqphp_nvram.c
50248@@ -427,9 +427,13 @@ static u32 store_HRT (void __iomem *rom_start)
50249
50250 void compaq_nvram_init (void __iomem *rom_start)
50251 {
50252+
50253+#ifndef CONFIG_PAX_KERNEXEC
50254 if (rom_start) {
50255 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
50256 }
50257+#endif
50258+
50259 dbg("int15 entry = %p\n", compaq_int15_entry_point);
50260
50261 /* initialize our int15 lock */
50262diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
50263index 56d8486..f26113f 100644
50264--- a/drivers/pci/hotplug/pci_hotplug_core.c
50265+++ b/drivers/pci/hotplug/pci_hotplug_core.c
50266@@ -436,8 +436,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
50267 return -EINVAL;
50268 }
50269
50270- slot->ops->owner = owner;
50271- slot->ops->mod_name = mod_name;
50272+ pax_open_kernel();
50273+ *(struct module **)&slot->ops->owner = owner;
50274+ *(const char **)&slot->ops->mod_name = mod_name;
50275+ pax_close_kernel();
50276
50277 mutex_lock(&pci_hp_mutex);
50278 /*
50279diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
50280index 07aa722..84514b4 100644
50281--- a/drivers/pci/hotplug/pciehp_core.c
50282+++ b/drivers/pci/hotplug/pciehp_core.c
50283@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
50284 struct slot *slot = ctrl->slot;
50285 struct hotplug_slot *hotplug = NULL;
50286 struct hotplug_slot_info *info = NULL;
50287- struct hotplug_slot_ops *ops = NULL;
50288+ hotplug_slot_ops_no_const *ops = NULL;
50289 char name[SLOT_NAME_SIZE];
50290 int retval = -ENOMEM;
50291
50292diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
50293index 5a40516..136d5a7 100644
50294--- a/drivers/pci/msi.c
50295+++ b/drivers/pci/msi.c
50296@@ -507,8 +507,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
50297 {
50298 struct attribute **msi_attrs;
50299 struct attribute *msi_attr;
50300- struct device_attribute *msi_dev_attr;
50301- struct attribute_group *msi_irq_group;
50302+ device_attribute_no_const *msi_dev_attr;
50303+ attribute_group_no_const *msi_irq_group;
50304 const struct attribute_group **msi_irq_groups;
50305 struct msi_desc *entry;
50306 int ret = -ENOMEM;
50307@@ -568,7 +568,7 @@ error_attrs:
50308 count = 0;
50309 msi_attr = msi_attrs[count];
50310 while (msi_attr) {
50311- msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
50312+ msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
50313 kfree(msi_attr->name);
50314 kfree(msi_dev_attr);
50315 ++count;
50316diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
50317index 6d04771..4126004 100644
50318--- a/drivers/pci/pci-sysfs.c
50319+++ b/drivers/pci/pci-sysfs.c
50320@@ -1134,7 +1134,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
50321 {
50322 /* allocate attribute structure, piggyback attribute name */
50323 int name_len = write_combine ? 13 : 10;
50324- struct bin_attribute *res_attr;
50325+ bin_attribute_no_const *res_attr;
50326 int retval;
50327
50328 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
50329@@ -1311,7 +1311,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
50330 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
50331 {
50332 int retval;
50333- struct bin_attribute *attr;
50334+ bin_attribute_no_const *attr;
50335
50336 /* If the device has VPD, try to expose it in sysfs. */
50337 if (dev->vpd) {
50338@@ -1358,7 +1358,7 @@ int __must_check pci_create_sysfs_dev_files(struct pci_dev *pdev)
50339 {
50340 int retval;
50341 int rom_size = 0;
50342- struct bin_attribute *attr;
50343+ bin_attribute_no_const *attr;
50344
50345 if (!sysfs_initialized)
50346 return -EACCES;
50347diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
50348index 0601890..dc15007 100644
50349--- a/drivers/pci/pci.h
50350+++ b/drivers/pci/pci.h
50351@@ -91,7 +91,7 @@ struct pci_vpd_ops {
50352 struct pci_vpd {
50353 unsigned int len;
50354 const struct pci_vpd_ops *ops;
50355- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
50356+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
50357 };
50358
50359 int pci_vpd_pci22_init(struct pci_dev *dev);
50360diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
50361index e1e7026..d28dd33 100644
50362--- a/drivers/pci/pcie/aspm.c
50363+++ b/drivers/pci/pcie/aspm.c
50364@@ -27,9 +27,9 @@
50365 #define MODULE_PARAM_PREFIX "pcie_aspm."
50366
50367 /* Note: those are not register definitions */
50368-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
50369-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
50370-#define ASPM_STATE_L1 (4) /* L1 state */
50371+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
50372+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
50373+#define ASPM_STATE_L1 (4U) /* L1 state */
50374 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
50375 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
50376
50377diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
50378index 4170113..7cc5339 100644
50379--- a/drivers/pci/probe.c
50380+++ b/drivers/pci/probe.c
50381@@ -176,7 +176,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
50382 struct pci_bus_region region, inverted_region;
50383 bool bar_too_big = false, bar_too_high = false, bar_invalid = false;
50384
50385- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
50386+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
50387
50388 /* No printks while decoding is disabled! */
50389 if (!dev->mmio_always_on) {
50390diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
50391index 3f155e7..0f4b1f0 100644
50392--- a/drivers/pci/proc.c
50393+++ b/drivers/pci/proc.c
50394@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
50395 static int __init pci_proc_init(void)
50396 {
50397 struct pci_dev *dev = NULL;
50398+
50399+#ifdef CONFIG_GRKERNSEC_PROC_ADD
50400+#ifdef CONFIG_GRKERNSEC_PROC_USER
50401+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
50402+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
50403+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
50404+#endif
50405+#else
50406 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
50407+#endif
50408 proc_create("devices", 0, proc_bus_pci_dir,
50409 &proc_bus_pci_dev_operations);
50410 proc_initialized = 1;
50411diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
50412index d866db8..c827d1f 100644
50413--- a/drivers/platform/chrome/chromeos_laptop.c
50414+++ b/drivers/platform/chrome/chromeos_laptop.c
50415@@ -479,7 +479,7 @@ static struct chromeos_laptop cr48 = {
50416 .callback = chromeos_laptop_dmi_matched, \
50417 .driver_data = (void *)&board_
50418
50419-static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
50420+static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
50421 {
50422 .ident = "Samsung Series 5 550",
50423 .matches = {
50424diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
50425index c5af23b..3d62d5e 100644
50426--- a/drivers/platform/x86/alienware-wmi.c
50427+++ b/drivers/platform/x86/alienware-wmi.c
50428@@ -150,7 +150,7 @@ struct wmax_led_args {
50429 } __packed;
50430
50431 static struct platform_device *platform_device;
50432-static struct device_attribute *zone_dev_attrs;
50433+static device_attribute_no_const *zone_dev_attrs;
50434 static struct attribute **zone_attrs;
50435 static struct platform_zone *zone_data;
50436
50437@@ -161,7 +161,7 @@ static struct platform_driver platform_driver = {
50438 }
50439 };
50440
50441-static struct attribute_group zone_attribute_group = {
50442+static attribute_group_no_const zone_attribute_group = {
50443 .name = "rgb_zones",
50444 };
50445
50446diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
50447index 21fc932..ee9394a 100644
50448--- a/drivers/platform/x86/asus-wmi.c
50449+++ b/drivers/platform/x86/asus-wmi.c
50450@@ -1590,6 +1590,10 @@ static int show_dsts(struct seq_file *m, void *data)
50451 int err;
50452 u32 retval = -1;
50453
50454+#ifdef CONFIG_GRKERNSEC_KMEM
50455+ return -EPERM;
50456+#endif
50457+
50458 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
50459
50460 if (err < 0)
50461@@ -1606,6 +1610,10 @@ static int show_devs(struct seq_file *m, void *data)
50462 int err;
50463 u32 retval = -1;
50464
50465+#ifdef CONFIG_GRKERNSEC_KMEM
50466+ return -EPERM;
50467+#endif
50468+
50469 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
50470 &retval);
50471
50472@@ -1630,6 +1638,10 @@ static int show_call(struct seq_file *m, void *data)
50473 union acpi_object *obj;
50474 acpi_status status;
50475
50476+#ifdef CONFIG_GRKERNSEC_KMEM
50477+ return -EPERM;
50478+#endif
50479+
50480 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
50481 1, asus->debug.method_id,
50482 &input, &output);
50483diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
50484index 62f8030..c7f2a45 100644
50485--- a/drivers/platform/x86/msi-laptop.c
50486+++ b/drivers/platform/x86/msi-laptop.c
50487@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
50488
50489 if (!quirks->ec_read_only) {
50490 /* allow userland write sysfs file */
50491- dev_attr_bluetooth.store = store_bluetooth;
50492- dev_attr_wlan.store = store_wlan;
50493- dev_attr_threeg.store = store_threeg;
50494- dev_attr_bluetooth.attr.mode |= S_IWUSR;
50495- dev_attr_wlan.attr.mode |= S_IWUSR;
50496- dev_attr_threeg.attr.mode |= S_IWUSR;
50497+ pax_open_kernel();
50498+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
50499+ *(void **)&dev_attr_wlan.store = store_wlan;
50500+ *(void **)&dev_attr_threeg.store = store_threeg;
50501+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
50502+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
50503+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
50504+ pax_close_kernel();
50505 }
50506
50507 /* disable hardware control by fn key */
50508diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
50509index 70222f2..8c8ce66 100644
50510--- a/drivers/platform/x86/msi-wmi.c
50511+++ b/drivers/platform/x86/msi-wmi.c
50512@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
50513 static void msi_wmi_notify(u32 value, void *context)
50514 {
50515 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
50516- static struct key_entry *key;
50517+ struct key_entry *key;
50518 union acpi_object *obj;
50519 acpi_status status;
50520
50521diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
50522index 26ad9ff..7c52909 100644
50523--- a/drivers/platform/x86/sony-laptop.c
50524+++ b/drivers/platform/x86/sony-laptop.c
50525@@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
50526 }
50527
50528 /* High speed charging function */
50529-static struct device_attribute *hsc_handle;
50530+static device_attribute_no_const *hsc_handle;
50531
50532 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
50533 struct device_attribute *attr,
50534@@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
50535 }
50536
50537 /* low battery function */
50538-static struct device_attribute *lowbatt_handle;
50539+static device_attribute_no_const *lowbatt_handle;
50540
50541 static ssize_t sony_nc_lowbatt_store(struct device *dev,
50542 struct device_attribute *attr,
50543@@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
50544 }
50545
50546 /* fan speed function */
50547-static struct device_attribute *fan_handle, *hsf_handle;
50548+static device_attribute_no_const *fan_handle, *hsf_handle;
50549
50550 static ssize_t sony_nc_hsfan_store(struct device *dev,
50551 struct device_attribute *attr,
50552@@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
50553 }
50554
50555 /* USB charge function */
50556-static struct device_attribute *uc_handle;
50557+static device_attribute_no_const *uc_handle;
50558
50559 static ssize_t sony_nc_usb_charge_store(struct device *dev,
50560 struct device_attribute *attr,
50561@@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
50562 }
50563
50564 /* Panel ID function */
50565-static struct device_attribute *panel_handle;
50566+static device_attribute_no_const *panel_handle;
50567
50568 static ssize_t sony_nc_panelid_show(struct device *dev,
50569 struct device_attribute *attr, char *buffer)
50570@@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
50571 }
50572
50573 /* smart connect function */
50574-static struct device_attribute *sc_handle;
50575+static device_attribute_no_const *sc_handle;
50576
50577 static ssize_t sony_nc_smart_conn_store(struct device *dev,
50578 struct device_attribute *attr,
50579diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
50580index 3bbc6eb..7760460 100644
50581--- a/drivers/platform/x86/thinkpad_acpi.c
50582+++ b/drivers/platform/x86/thinkpad_acpi.c
50583@@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
50584 return 0;
50585 }
50586
50587-void static hotkey_mask_warn_incomplete_mask(void)
50588+static void hotkey_mask_warn_incomplete_mask(void)
50589 {
50590 /* log only what the user can fix... */
50591 const u32 wantedmask = hotkey_driver_mask &
50592@@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
50593 && !tp_features.bright_unkfw)
50594 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
50595 }
50596+}
50597
50598 #undef TPACPI_COMPARE_KEY
50599 #undef TPACPI_MAY_SEND_KEY
50600-}
50601
50602 /*
50603 * Polling driver
50604diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
50605index 438d4c7..ca8a2fb 100644
50606--- a/drivers/pnp/pnpbios/bioscalls.c
50607+++ b/drivers/pnp/pnpbios/bioscalls.c
50608@@ -59,7 +59,7 @@ do { \
50609 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
50610 } while(0)
50611
50612-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
50613+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
50614 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
50615
50616 /*
50617@@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50618
50619 cpu = get_cpu();
50620 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
50621+
50622+ pax_open_kernel();
50623 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
50624+ pax_close_kernel();
50625
50626 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
50627 spin_lock_irqsave(&pnp_bios_lock, flags);
50628@@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
50629 :"memory");
50630 spin_unlock_irqrestore(&pnp_bios_lock, flags);
50631
50632+ pax_open_kernel();
50633 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
50634+ pax_close_kernel();
50635+
50636 put_cpu();
50637
50638 /* If we get here and this is set then the PnP BIOS faulted on us. */
50639@@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
50640 return status;
50641 }
50642
50643-void pnpbios_calls_init(union pnp_bios_install_struct *header)
50644+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
50645 {
50646 int i;
50647
50648@@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50649 pnp_bios_callpoint.offset = header->fields.pm16offset;
50650 pnp_bios_callpoint.segment = PNP_CS16;
50651
50652+ pax_open_kernel();
50653+
50654 for_each_possible_cpu(i) {
50655 struct desc_struct *gdt = get_cpu_gdt_table(i);
50656 if (!gdt)
50657@@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
50658 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
50659 (unsigned long)__va(header->fields.pm16dseg));
50660 }
50661+
50662+ pax_close_kernel();
50663 }
50664diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
50665index 0c52e2a..3421ab7 100644
50666--- a/drivers/power/pda_power.c
50667+++ b/drivers/power/pda_power.c
50668@@ -37,7 +37,11 @@ static int polling;
50669
50670 #if IS_ENABLED(CONFIG_USB_PHY)
50671 static struct usb_phy *transceiver;
50672-static struct notifier_block otg_nb;
50673+static int otg_handle_notification(struct notifier_block *nb,
50674+ unsigned long event, void *unused);
50675+static struct notifier_block otg_nb = {
50676+ .notifier_call = otg_handle_notification
50677+};
50678 #endif
50679
50680 static struct regulator *ac_draw;
50681@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
50682
50683 #if IS_ENABLED(CONFIG_USB_PHY)
50684 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
50685- otg_nb.notifier_call = otg_handle_notification;
50686 ret = usb_register_notifier(transceiver, &otg_nb);
50687 if (ret) {
50688 dev_err(dev, "failure to register otg notifier\n");
50689diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
50690index cc439fd..8fa30df 100644
50691--- a/drivers/power/power_supply.h
50692+++ b/drivers/power/power_supply.h
50693@@ -16,12 +16,12 @@ struct power_supply;
50694
50695 #ifdef CONFIG_SYSFS
50696
50697-extern void power_supply_init_attrs(struct device_type *dev_type);
50698+extern void power_supply_init_attrs(void);
50699 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
50700
50701 #else
50702
50703-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
50704+static inline void power_supply_init_attrs(void) {}
50705 #define power_supply_uevent NULL
50706
50707 #endif /* CONFIG_SYSFS */
50708diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
50709index 078afd6..fbac9da 100644
50710--- a/drivers/power/power_supply_core.c
50711+++ b/drivers/power/power_supply_core.c
50712@@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
50713 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
50714 EXPORT_SYMBOL_GPL(power_supply_notifier);
50715
50716-static struct device_type power_supply_dev_type;
50717+extern const struct attribute_group *power_supply_attr_groups[];
50718+static struct device_type power_supply_dev_type = {
50719+ .groups = power_supply_attr_groups,
50720+};
50721
50722 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
50723 struct power_supply *supply)
50724@@ -640,7 +643,7 @@ static int __init power_supply_class_init(void)
50725 return PTR_ERR(power_supply_class);
50726
50727 power_supply_class->dev_uevent = power_supply_uevent;
50728- power_supply_init_attrs(&power_supply_dev_type);
50729+ power_supply_init_attrs();
50730
50731 return 0;
50732 }
50733diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
50734index 750a202..99c8f4b 100644
50735--- a/drivers/power/power_supply_sysfs.c
50736+++ b/drivers/power/power_supply_sysfs.c
50737@@ -234,17 +234,15 @@ static struct attribute_group power_supply_attr_group = {
50738 .is_visible = power_supply_attr_is_visible,
50739 };
50740
50741-static const struct attribute_group *power_supply_attr_groups[] = {
50742+const struct attribute_group *power_supply_attr_groups[] = {
50743 &power_supply_attr_group,
50744 NULL,
50745 };
50746
50747-void power_supply_init_attrs(struct device_type *dev_type)
50748+void power_supply_init_attrs(void)
50749 {
50750 int i;
50751
50752- dev_type->groups = power_supply_attr_groups;
50753-
50754 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
50755 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
50756 }
50757diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
50758index 84419af..268ede8 100644
50759--- a/drivers/powercap/powercap_sys.c
50760+++ b/drivers/powercap/powercap_sys.c
50761@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
50762 struct device_attribute name_attr;
50763 };
50764
50765+static ssize_t show_constraint_name(struct device *dev,
50766+ struct device_attribute *dev_attr,
50767+ char *buf);
50768+
50769 static struct powercap_constraint_attr
50770- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
50771+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
50772+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
50773+ .power_limit_attr = {
50774+ .attr = {
50775+ .name = NULL,
50776+ .mode = S_IWUSR | S_IRUGO
50777+ },
50778+ .show = show_constraint_power_limit_uw,
50779+ .store = store_constraint_power_limit_uw
50780+ },
50781+
50782+ .time_window_attr = {
50783+ .attr = {
50784+ .name = NULL,
50785+ .mode = S_IWUSR | S_IRUGO
50786+ },
50787+ .show = show_constraint_time_window_us,
50788+ .store = store_constraint_time_window_us
50789+ },
50790+
50791+ .max_power_attr = {
50792+ .attr = {
50793+ .name = NULL,
50794+ .mode = S_IRUGO
50795+ },
50796+ .show = show_constraint_max_power_uw,
50797+ .store = NULL
50798+ },
50799+
50800+ .min_power_attr = {
50801+ .attr = {
50802+ .name = NULL,
50803+ .mode = S_IRUGO
50804+ },
50805+ .show = show_constraint_min_power_uw,
50806+ .store = NULL
50807+ },
50808+
50809+ .max_time_window_attr = {
50810+ .attr = {
50811+ .name = NULL,
50812+ .mode = S_IRUGO
50813+ },
50814+ .show = show_constraint_max_time_window_us,
50815+ .store = NULL
50816+ },
50817+
50818+ .min_time_window_attr = {
50819+ .attr = {
50820+ .name = NULL,
50821+ .mode = S_IRUGO
50822+ },
50823+ .show = show_constraint_min_time_window_us,
50824+ .store = NULL
50825+ },
50826+
50827+ .name_attr = {
50828+ .attr = {
50829+ .name = NULL,
50830+ .mode = S_IRUGO
50831+ },
50832+ .show = show_constraint_name,
50833+ .store = NULL
50834+ }
50835+ }
50836+};
50837
50838 /* A list of powercap control_types */
50839 static LIST_HEAD(powercap_cntrl_list);
50840@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
50841 }
50842
50843 static int create_constraint_attribute(int id, const char *name,
50844- int mode,
50845- struct device_attribute *dev_attr,
50846- ssize_t (*show)(struct device *,
50847- struct device_attribute *, char *),
50848- ssize_t (*store)(struct device *,
50849- struct device_attribute *,
50850- const char *, size_t)
50851- )
50852+ struct device_attribute *dev_attr)
50853 {
50854+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
50855
50856- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
50857- id, name);
50858- if (!dev_attr->attr.name)
50859+ if (!name)
50860 return -ENOMEM;
50861- dev_attr->attr.mode = mode;
50862- dev_attr->show = show;
50863- dev_attr->store = store;
50864+
50865+ pax_open_kernel();
50866+ *(const char **)&dev_attr->attr.name = name;
50867+ pax_close_kernel();
50868
50869 return 0;
50870 }
50871@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
50872
50873 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
50874 ret = create_constraint_attribute(i, "power_limit_uw",
50875- S_IWUSR | S_IRUGO,
50876- &constraint_attrs[i].power_limit_attr,
50877- show_constraint_power_limit_uw,
50878- store_constraint_power_limit_uw);
50879+ &constraint_attrs[i].power_limit_attr);
50880 if (ret)
50881 goto err_alloc;
50882 ret = create_constraint_attribute(i, "time_window_us",
50883- S_IWUSR | S_IRUGO,
50884- &constraint_attrs[i].time_window_attr,
50885- show_constraint_time_window_us,
50886- store_constraint_time_window_us);
50887+ &constraint_attrs[i].time_window_attr);
50888 if (ret)
50889 goto err_alloc;
50890- ret = create_constraint_attribute(i, "name", S_IRUGO,
50891- &constraint_attrs[i].name_attr,
50892- show_constraint_name,
50893- NULL);
50894+ ret = create_constraint_attribute(i, "name",
50895+ &constraint_attrs[i].name_attr);
50896 if (ret)
50897 goto err_alloc;
50898- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
50899- &constraint_attrs[i].max_power_attr,
50900- show_constraint_max_power_uw,
50901- NULL);
50902+ ret = create_constraint_attribute(i, "max_power_uw",
50903+ &constraint_attrs[i].max_power_attr);
50904 if (ret)
50905 goto err_alloc;
50906- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
50907- &constraint_attrs[i].min_power_attr,
50908- show_constraint_min_power_uw,
50909- NULL);
50910+ ret = create_constraint_attribute(i, "min_power_uw",
50911+ &constraint_attrs[i].min_power_attr);
50912 if (ret)
50913 goto err_alloc;
50914 ret = create_constraint_attribute(i, "max_time_window_us",
50915- S_IRUGO,
50916- &constraint_attrs[i].max_time_window_attr,
50917- show_constraint_max_time_window_us,
50918- NULL);
50919+ &constraint_attrs[i].max_time_window_attr);
50920 if (ret)
50921 goto err_alloc;
50922 ret = create_constraint_attribute(i, "min_time_window_us",
50923- S_IRUGO,
50924- &constraint_attrs[i].min_time_window_attr,
50925- show_constraint_min_time_window_us,
50926- NULL);
50927+ &constraint_attrs[i].min_time_window_attr);
50928 if (ret)
50929 goto err_alloc;
50930
50931@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
50932 power_zone->zone_dev_attrs[count++] =
50933 &dev_attr_max_energy_range_uj.attr;
50934 if (power_zone->ops->get_energy_uj) {
50935+ pax_open_kernel();
50936 if (power_zone->ops->reset_energy_uj)
50937- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50938+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
50939 else
50940- dev_attr_energy_uj.attr.mode = S_IRUGO;
50941+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
50942+ pax_close_kernel();
50943 power_zone->zone_dev_attrs[count++] =
50944 &dev_attr_energy_uj.attr;
50945 }
50946diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
50947index 9c5d414..c7900ce 100644
50948--- a/drivers/ptp/ptp_private.h
50949+++ b/drivers/ptp/ptp_private.h
50950@@ -51,7 +51,7 @@ struct ptp_clock {
50951 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
50952 wait_queue_head_t tsev_wq;
50953 int defunct; /* tells readers to go away when clock is being removed */
50954- struct device_attribute *pin_dev_attr;
50955+ device_attribute_no_const *pin_dev_attr;
50956 struct attribute **pin_attr;
50957 struct attribute_group pin_attr_group;
50958 };
50959diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
50960index 302e626..12579af 100644
50961--- a/drivers/ptp/ptp_sysfs.c
50962+++ b/drivers/ptp/ptp_sysfs.c
50963@@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
50964 goto no_pin_attr;
50965
50966 for (i = 0; i < n_pins; i++) {
50967- struct device_attribute *da = &ptp->pin_dev_attr[i];
50968+ device_attribute_no_const *da = &ptp->pin_dev_attr[i];
50969 sysfs_attr_init(&da->attr);
50970 da->attr.name = info->pin_config[i].name;
50971 da->attr.mode = 0644;
50972diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
50973index a3c3785..c901e3a 100644
50974--- a/drivers/regulator/core.c
50975+++ b/drivers/regulator/core.c
50976@@ -3481,7 +3481,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50977 {
50978 const struct regulation_constraints *constraints = NULL;
50979 const struct regulator_init_data *init_data;
50980- static atomic_t regulator_no = ATOMIC_INIT(0);
50981+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
50982 struct regulator_dev *rdev;
50983 struct device *dev;
50984 int ret, i;
50985@@ -3551,7 +3551,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
50986 rdev->dev.of_node = of_node_get(config->of_node);
50987 rdev->dev.parent = dev;
50988 dev_set_name(&rdev->dev, "regulator.%d",
50989- atomic_inc_return(&regulator_no) - 1);
50990+ atomic_inc_return_unchecked(&regulator_no) - 1);
50991 ret = device_register(&rdev->dev);
50992 if (ret != 0) {
50993 put_device(&rdev->dev);
50994diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
50995index 2fc4111..6aa88ca 100644
50996--- a/drivers/regulator/max8660.c
50997+++ b/drivers/regulator/max8660.c
50998@@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
50999 max8660->shadow_regs[MAX8660_OVER1] = 5;
51000 } else {
51001 /* Otherwise devices can be toggled via software */
51002- max8660_dcdc_ops.enable = max8660_dcdc_enable;
51003- max8660_dcdc_ops.disable = max8660_dcdc_disable;
51004+ pax_open_kernel();
51005+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
51006+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
51007+ pax_close_kernel();
51008 }
51009
51010 /*
51011diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
51012index dbedf17..18ff6b7 100644
51013--- a/drivers/regulator/max8973-regulator.c
51014+++ b/drivers/regulator/max8973-regulator.c
51015@@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
51016 if (!pdata || !pdata->enable_ext_control) {
51017 max->desc.enable_reg = MAX8973_VOUT;
51018 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
51019- max->ops.enable = regulator_enable_regmap;
51020- max->ops.disable = regulator_disable_regmap;
51021- max->ops.is_enabled = regulator_is_enabled_regmap;
51022+ pax_open_kernel();
51023+ *(void **)&max->ops.enable = regulator_enable_regmap;
51024+ *(void **)&max->ops.disable = regulator_disable_regmap;
51025+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
51026+ pax_close_kernel();
51027 }
51028
51029 if (pdata) {
51030diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
51031index f374fa5..26f0683 100644
51032--- a/drivers/regulator/mc13892-regulator.c
51033+++ b/drivers/regulator/mc13892-regulator.c
51034@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
51035 }
51036 mc13xxx_unlock(mc13892);
51037
51038- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
51039+ pax_open_kernel();
51040+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
51041 = mc13892_vcam_set_mode;
51042- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
51043+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
51044 = mc13892_vcam_get_mode;
51045+ pax_close_kernel();
51046
51047 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
51048 ARRAY_SIZE(mc13892_regulators));
51049diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
51050index 5b2e761..c8c8a4a 100644
51051--- a/drivers/rtc/rtc-cmos.c
51052+++ b/drivers/rtc/rtc-cmos.c
51053@@ -789,7 +789,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
51054 hpet_rtc_timer_init();
51055
51056 /* export at least the first block of NVRAM */
51057- nvram.size = address_space - NVRAM_OFFSET;
51058+ pax_open_kernel();
51059+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
51060+ pax_close_kernel();
51061 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
51062 if (retval < 0) {
51063 dev_dbg(dev, "can't create nvram file? %d\n", retval);
51064diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
51065index d049393..bb20be0 100644
51066--- a/drivers/rtc/rtc-dev.c
51067+++ b/drivers/rtc/rtc-dev.c
51068@@ -16,6 +16,7 @@
51069 #include <linux/module.h>
51070 #include <linux/rtc.h>
51071 #include <linux/sched.h>
51072+#include <linux/grsecurity.h>
51073 #include "rtc-core.h"
51074
51075 static dev_t rtc_devt;
51076@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
51077 if (copy_from_user(&tm, uarg, sizeof(tm)))
51078 return -EFAULT;
51079
51080+ gr_log_timechange();
51081+
51082 return rtc_set_time(rtc, &tm);
51083
51084 case RTC_PIE_ON:
51085diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
51086index f03d5ba..8325bf6 100644
51087--- a/drivers/rtc/rtc-ds1307.c
51088+++ b/drivers/rtc/rtc-ds1307.c
51089@@ -107,7 +107,7 @@ struct ds1307 {
51090 u8 offset; /* register's offset */
51091 u8 regs[11];
51092 u16 nvram_offset;
51093- struct bin_attribute *nvram;
51094+ bin_attribute_no_const *nvram;
51095 enum ds_type type;
51096 unsigned long flags;
51097 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
51098diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
51099index 11880c1..b823aa4 100644
51100--- a/drivers/rtc/rtc-m48t59.c
51101+++ b/drivers/rtc/rtc-m48t59.c
51102@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
51103 if (IS_ERR(m48t59->rtc))
51104 return PTR_ERR(m48t59->rtc);
51105
51106- m48t59_nvram_attr.size = pdata->offset;
51107+ pax_open_kernel();
51108+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
51109+ pax_close_kernel();
51110
51111 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
51112 if (ret)
51113diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
51114index e693af6..2e525b6 100644
51115--- a/drivers/scsi/bfa/bfa_fcpim.h
51116+++ b/drivers/scsi/bfa/bfa_fcpim.h
51117@@ -36,7 +36,7 @@ struct bfa_iotag_s {
51118
51119 struct bfa_itn_s {
51120 bfa_isr_func_t isr;
51121-};
51122+} __no_const;
51123
51124 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
51125 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
51126diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
51127index 0f19455..ef7adb5 100644
51128--- a/drivers/scsi/bfa/bfa_fcs.c
51129+++ b/drivers/scsi/bfa/bfa_fcs.c
51130@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
51131 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
51132
51133 static struct bfa_fcs_mod_s fcs_modules[] = {
51134- { bfa_fcs_port_attach, NULL, NULL },
51135- { bfa_fcs_uf_attach, NULL, NULL },
51136- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
51137- bfa_fcs_fabric_modexit },
51138+ {
51139+ .attach = bfa_fcs_port_attach,
51140+ .modinit = NULL,
51141+ .modexit = NULL
51142+ },
51143+ {
51144+ .attach = bfa_fcs_uf_attach,
51145+ .modinit = NULL,
51146+ .modexit = NULL
51147+ },
51148+ {
51149+ .attach = bfa_fcs_fabric_attach,
51150+ .modinit = bfa_fcs_fabric_modinit,
51151+ .modexit = bfa_fcs_fabric_modexit
51152+ },
51153 };
51154
51155 /*
51156diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
51157index ff75ef8..2dfe00a 100644
51158--- a/drivers/scsi/bfa/bfa_fcs_lport.c
51159+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
51160@@ -89,15 +89,26 @@ static struct {
51161 void (*offline) (struct bfa_fcs_lport_s *port);
51162 } __port_action[] = {
51163 {
51164- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
51165- bfa_fcs_lport_unknown_offline}, {
51166- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
51167- bfa_fcs_lport_fab_offline}, {
51168- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
51169- bfa_fcs_lport_n2n_offline}, {
51170- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
51171- bfa_fcs_lport_loop_offline},
51172- };
51173+ .init = bfa_fcs_lport_unknown_init,
51174+ .online = bfa_fcs_lport_unknown_online,
51175+ .offline = bfa_fcs_lport_unknown_offline
51176+ },
51177+ {
51178+ .init = bfa_fcs_lport_fab_init,
51179+ .online = bfa_fcs_lport_fab_online,
51180+ .offline = bfa_fcs_lport_fab_offline
51181+ },
51182+ {
51183+ .init = bfa_fcs_lport_n2n_init,
51184+ .online = bfa_fcs_lport_n2n_online,
51185+ .offline = bfa_fcs_lport_n2n_offline
51186+ },
51187+ {
51188+ .init = bfa_fcs_lport_loop_init,
51189+ .online = bfa_fcs_lport_loop_online,
51190+ .offline = bfa_fcs_lport_loop_offline
51191+ },
51192+};
51193
51194 /*
51195 * fcs_port_sm FCS logical port state machine
51196diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
51197index a38aafa0..fe8f03b 100644
51198--- a/drivers/scsi/bfa/bfa_ioc.h
51199+++ b/drivers/scsi/bfa/bfa_ioc.h
51200@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
51201 bfa_ioc_disable_cbfn_t disable_cbfn;
51202 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
51203 bfa_ioc_reset_cbfn_t reset_cbfn;
51204-};
51205+} __no_const;
51206
51207 /*
51208 * IOC event notification mechanism.
51209@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
51210 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
51211 enum bfi_ioc_state fwstate);
51212 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
51213-};
51214+} __no_const;
51215
51216 /*
51217 * Queue element to wait for room in request queue. FIFO order is
51218diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
51219index a14c784..6de6790 100644
51220--- a/drivers/scsi/bfa/bfa_modules.h
51221+++ b/drivers/scsi/bfa/bfa_modules.h
51222@@ -78,12 +78,12 @@ enum {
51223 \
51224 extern struct bfa_module_s hal_mod_ ## __mod; \
51225 struct bfa_module_s hal_mod_ ## __mod = { \
51226- bfa_ ## __mod ## _meminfo, \
51227- bfa_ ## __mod ## _attach, \
51228- bfa_ ## __mod ## _detach, \
51229- bfa_ ## __mod ## _start, \
51230- bfa_ ## __mod ## _stop, \
51231- bfa_ ## __mod ## _iocdisable, \
51232+ .meminfo = bfa_ ## __mod ## _meminfo, \
51233+ .attach = bfa_ ## __mod ## _attach, \
51234+ .detach = bfa_ ## __mod ## _detach, \
51235+ .start = bfa_ ## __mod ## _start, \
51236+ .stop = bfa_ ## __mod ## _stop, \
51237+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
51238 }
51239
51240 #define BFA_CACHELINE_SZ (256)
51241diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
51242index 045c4e1..13de803 100644
51243--- a/drivers/scsi/fcoe/fcoe_sysfs.c
51244+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
51245@@ -33,8 +33,8 @@
51246 */
51247 #include "libfcoe.h"
51248
51249-static atomic_t ctlr_num;
51250-static atomic_t fcf_num;
51251+static atomic_unchecked_t ctlr_num;
51252+static atomic_unchecked_t fcf_num;
51253
51254 /*
51255 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
51256@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
51257 if (!ctlr)
51258 goto out;
51259
51260- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
51261+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
51262 ctlr->f = f;
51263 ctlr->mode = FIP_CONN_TYPE_FABRIC;
51264 INIT_LIST_HEAD(&ctlr->fcfs);
51265@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
51266 fcf->dev.parent = &ctlr->dev;
51267 fcf->dev.bus = &fcoe_bus_type;
51268 fcf->dev.type = &fcoe_fcf_device_type;
51269- fcf->id = atomic_inc_return(&fcf_num) - 1;
51270+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
51271 fcf->state = FCOE_FCF_STATE_UNKNOWN;
51272
51273 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
51274@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
51275 {
51276 int error;
51277
51278- atomic_set(&ctlr_num, 0);
51279- atomic_set(&fcf_num, 0);
51280+ atomic_set_unchecked(&ctlr_num, 0);
51281+ atomic_set_unchecked(&fcf_num, 0);
51282
51283 error = bus_register(&fcoe_bus_type);
51284 if (error)
51285diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
51286index 6de80e3..a11e0ac 100644
51287--- a/drivers/scsi/hosts.c
51288+++ b/drivers/scsi/hosts.c
51289@@ -42,7 +42,7 @@
51290 #include "scsi_logging.h"
51291
51292
51293-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51294+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
51295
51296
51297 static void scsi_host_cls_release(struct device *dev)
51298@@ -392,7 +392,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
51299 * subtract one because we increment first then return, but we need to
51300 * know what the next host number was before increment
51301 */
51302- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
51303+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
51304 shost->dma_channel = 0xff;
51305
51306 /* These three are default values which can be overridden */
51307diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
51308index 6b35d0d..2880305 100644
51309--- a/drivers/scsi/hpsa.c
51310+++ b/drivers/scsi/hpsa.c
51311@@ -701,10 +701,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
51312 unsigned long flags;
51313
51314 if (h->transMethod & CFGTBL_Trans_io_accel1)
51315- return h->access.command_completed(h, q);
51316+ return h->access->command_completed(h, q);
51317
51318 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
51319- return h->access.command_completed(h, q);
51320+ return h->access->command_completed(h, q);
51321
51322 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
51323 a = rq->head[rq->current_entry];
51324@@ -5454,7 +5454,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51325 while (!list_empty(&h->reqQ)) {
51326 c = list_entry(h->reqQ.next, struct CommandList, list);
51327 /* can't do anything if fifo is full */
51328- if ((h->access.fifo_full(h))) {
51329+ if ((h->access->fifo_full(h))) {
51330 h->fifo_recently_full = 1;
51331 dev_warn(&h->pdev->dev, "fifo full\n");
51332 break;
51333@@ -5476,7 +5476,7 @@ static void start_io(struct ctlr_info *h, unsigned long *flags)
51334
51335 /* Tell the controller execute command */
51336 spin_unlock_irqrestore(&h->lock, *flags);
51337- h->access.submit_command(h, c);
51338+ h->access->submit_command(h, c);
51339 spin_lock_irqsave(&h->lock, *flags);
51340 }
51341 }
51342@@ -5492,17 +5492,17 @@ static void lock_and_start_io(struct ctlr_info *h)
51343
51344 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
51345 {
51346- return h->access.command_completed(h, q);
51347+ return h->access->command_completed(h, q);
51348 }
51349
51350 static inline bool interrupt_pending(struct ctlr_info *h)
51351 {
51352- return h->access.intr_pending(h);
51353+ return h->access->intr_pending(h);
51354 }
51355
51356 static inline long interrupt_not_for_us(struct ctlr_info *h)
51357 {
51358- return (h->access.intr_pending(h) == 0) ||
51359+ return (h->access->intr_pending(h) == 0) ||
51360 (h->interrupts_enabled == 0);
51361 }
51362
51363@@ -6458,7 +6458,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
51364 if (prod_index < 0)
51365 return -ENODEV;
51366 h->product_name = products[prod_index].product_name;
51367- h->access = *(products[prod_index].access);
51368+ h->access = products[prod_index].access;
51369
51370 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
51371 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
51372@@ -6780,7 +6780,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
51373 unsigned long flags;
51374 u32 lockup_detected;
51375
51376- h->access.set_intr_mask(h, HPSA_INTR_OFF);
51377+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
51378 spin_lock_irqsave(&h->lock, flags);
51379 lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
51380 if (!lockup_detected) {
51381@@ -7027,7 +7027,7 @@ reinit_after_soft_reset:
51382 }
51383
51384 /* make sure the board interrupts are off */
51385- h->access.set_intr_mask(h, HPSA_INTR_OFF);
51386+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
51387
51388 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
51389 goto clean2;
51390@@ -7062,7 +7062,7 @@ reinit_after_soft_reset:
51391 * fake ones to scoop up any residual completions.
51392 */
51393 spin_lock_irqsave(&h->lock, flags);
51394- h->access.set_intr_mask(h, HPSA_INTR_OFF);
51395+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
51396 spin_unlock_irqrestore(&h->lock, flags);
51397 free_irqs(h);
51398 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
51399@@ -7081,9 +7081,9 @@ reinit_after_soft_reset:
51400 dev_info(&h->pdev->dev, "Board READY.\n");
51401 dev_info(&h->pdev->dev,
51402 "Waiting for stale completions to drain.\n");
51403- h->access.set_intr_mask(h, HPSA_INTR_ON);
51404+ h->access->set_intr_mask(h, HPSA_INTR_ON);
51405 msleep(10000);
51406- h->access.set_intr_mask(h, HPSA_INTR_OFF);
51407+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
51408
51409 rc = controller_reset_failed(h->cfgtable);
51410 if (rc)
51411@@ -7109,7 +7109,7 @@ reinit_after_soft_reset:
51412 h->drv_req_rescan = 0;
51413
51414 /* Turn the interrupts on so we can service requests */
51415- h->access.set_intr_mask(h, HPSA_INTR_ON);
51416+ h->access->set_intr_mask(h, HPSA_INTR_ON);
51417
51418 hpsa_hba_inquiry(h);
51419 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
51420@@ -7174,7 +7174,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
51421 * To write all data in the battery backed cache to disks
51422 */
51423 hpsa_flush_cache(h);
51424- h->access.set_intr_mask(h, HPSA_INTR_OFF);
51425+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
51426 hpsa_free_irqs_and_disable_msix(h);
51427 }
51428
51429@@ -7292,7 +7292,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51430 CFGTBL_Trans_enable_directed_msix |
51431 (trans_support & (CFGTBL_Trans_io_accel1 |
51432 CFGTBL_Trans_io_accel2));
51433- struct access_method access = SA5_performant_access;
51434+ struct access_method *access = &SA5_performant_access;
51435
51436 /* This is a bit complicated. There are 8 registers on
51437 * the controller which we write to to tell it 8 different
51438@@ -7334,7 +7334,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51439 * perform the superfluous readl() after each command submission.
51440 */
51441 if (trans_support & (CFGTBL_Trans_io_accel1 | CFGTBL_Trans_io_accel2))
51442- access = SA5_performant_access_no_read;
51443+ access = &SA5_performant_access_no_read;
51444
51445 /* Controller spec: zero out this buffer. */
51446 for (i = 0; i < h->nreply_queues; i++)
51447@@ -7364,12 +7364,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
51448 * enable outbound interrupt coalescing in accelerator mode;
51449 */
51450 if (trans_support & CFGTBL_Trans_io_accel1) {
51451- access = SA5_ioaccel_mode1_access;
51452+ access = &SA5_ioaccel_mode1_access;
51453 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51454 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51455 } else {
51456 if (trans_support & CFGTBL_Trans_io_accel2) {
51457- access = SA5_ioaccel_mode2_access;
51458+ access = &SA5_ioaccel_mode2_access;
51459 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
51460 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
51461 }
51462diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
51463index 24472ce..8782caf 100644
51464--- a/drivers/scsi/hpsa.h
51465+++ b/drivers/scsi/hpsa.h
51466@@ -127,7 +127,7 @@ struct ctlr_info {
51467 unsigned int msix_vector;
51468 unsigned int msi_vector;
51469 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
51470- struct access_method access;
51471+ struct access_method *access;
51472 char hba_mode_enabled;
51473
51474 /* queue and queue Info */
51475@@ -536,43 +536,43 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
51476 }
51477
51478 static struct access_method SA5_access = {
51479- SA5_submit_command,
51480- SA5_intr_mask,
51481- SA5_fifo_full,
51482- SA5_intr_pending,
51483- SA5_completed,
51484+ .submit_command = SA5_submit_command,
51485+ .set_intr_mask = SA5_intr_mask,
51486+ .fifo_full = SA5_fifo_full,
51487+ .intr_pending = SA5_intr_pending,
51488+ .command_completed = SA5_completed,
51489 };
51490
51491 static struct access_method SA5_ioaccel_mode1_access = {
51492- SA5_submit_command,
51493- SA5_performant_intr_mask,
51494- SA5_fifo_full,
51495- SA5_ioaccel_mode1_intr_pending,
51496- SA5_ioaccel_mode1_completed,
51497+ .submit_command = SA5_submit_command,
51498+ .set_intr_mask = SA5_performant_intr_mask,
51499+ .fifo_full = SA5_fifo_full,
51500+ .intr_pending = SA5_ioaccel_mode1_intr_pending,
51501+ .command_completed = SA5_ioaccel_mode1_completed,
51502 };
51503
51504 static struct access_method SA5_ioaccel_mode2_access = {
51505- SA5_submit_command_ioaccel2,
51506- SA5_performant_intr_mask,
51507- SA5_fifo_full,
51508- SA5_performant_intr_pending,
51509- SA5_performant_completed,
51510+ .submit_command = SA5_submit_command_ioaccel2,
51511+ .set_intr_mask = SA5_performant_intr_mask,
51512+ .fifo_full = SA5_fifo_full,
51513+ .intr_pending = SA5_performant_intr_pending,
51514+ .command_completed = SA5_performant_completed,
51515 };
51516
51517 static struct access_method SA5_performant_access = {
51518- SA5_submit_command,
51519- SA5_performant_intr_mask,
51520- SA5_fifo_full,
51521- SA5_performant_intr_pending,
51522- SA5_performant_completed,
51523+ .submit_command = SA5_submit_command,
51524+ .set_intr_mask = SA5_performant_intr_mask,
51525+ .fifo_full = SA5_fifo_full,
51526+ .intr_pending = SA5_performant_intr_pending,
51527+ .command_completed = SA5_performant_completed,
51528 };
51529
51530 static struct access_method SA5_performant_access_no_read = {
51531- SA5_submit_command_no_read,
51532- SA5_performant_intr_mask,
51533- SA5_fifo_full,
51534- SA5_performant_intr_pending,
51535- SA5_performant_completed,
51536+ .submit_command = SA5_submit_command_no_read,
51537+ .set_intr_mask = SA5_performant_intr_mask,
51538+ .fifo_full = SA5_fifo_full,
51539+ .intr_pending = SA5_performant_intr_pending,
51540+ .command_completed = SA5_performant_completed,
51541 };
51542
51543 struct board_type {
51544diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
51545index 1b3a094..068e683 100644
51546--- a/drivers/scsi/libfc/fc_exch.c
51547+++ b/drivers/scsi/libfc/fc_exch.c
51548@@ -101,12 +101,12 @@ struct fc_exch_mgr {
51549 u16 pool_max_index;
51550
51551 struct {
51552- atomic_t no_free_exch;
51553- atomic_t no_free_exch_xid;
51554- atomic_t xid_not_found;
51555- atomic_t xid_busy;
51556- atomic_t seq_not_found;
51557- atomic_t non_bls_resp;
51558+ atomic_unchecked_t no_free_exch;
51559+ atomic_unchecked_t no_free_exch_xid;
51560+ atomic_unchecked_t xid_not_found;
51561+ atomic_unchecked_t xid_busy;
51562+ atomic_unchecked_t seq_not_found;
51563+ atomic_unchecked_t non_bls_resp;
51564 } stats;
51565 };
51566
51567@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
51568 /* allocate memory for exchange */
51569 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
51570 if (!ep) {
51571- atomic_inc(&mp->stats.no_free_exch);
51572+ atomic_inc_unchecked(&mp->stats.no_free_exch);
51573 goto out;
51574 }
51575 memset(ep, 0, sizeof(*ep));
51576@@ -874,7 +874,7 @@ out:
51577 return ep;
51578 err:
51579 spin_unlock_bh(&pool->lock);
51580- atomic_inc(&mp->stats.no_free_exch_xid);
51581+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
51582 mempool_free(ep, mp->ep_pool);
51583 return NULL;
51584 }
51585@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51586 xid = ntohs(fh->fh_ox_id); /* we originated exch */
51587 ep = fc_exch_find(mp, xid);
51588 if (!ep) {
51589- atomic_inc(&mp->stats.xid_not_found);
51590+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51591 reject = FC_RJT_OX_ID;
51592 goto out;
51593 }
51594@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51595 ep = fc_exch_find(mp, xid);
51596 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
51597 if (ep) {
51598- atomic_inc(&mp->stats.xid_busy);
51599+ atomic_inc_unchecked(&mp->stats.xid_busy);
51600 reject = FC_RJT_RX_ID;
51601 goto rel;
51602 }
51603@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51604 }
51605 xid = ep->xid; /* get our XID */
51606 } else if (!ep) {
51607- atomic_inc(&mp->stats.xid_not_found);
51608+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51609 reject = FC_RJT_RX_ID; /* XID not found */
51610 goto out;
51611 }
51612@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
51613 } else {
51614 sp = &ep->seq;
51615 if (sp->id != fh->fh_seq_id) {
51616- atomic_inc(&mp->stats.seq_not_found);
51617+ atomic_inc_unchecked(&mp->stats.seq_not_found);
51618 if (f_ctl & FC_FC_END_SEQ) {
51619 /*
51620 * Update sequence_id based on incoming last
51621@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51622
51623 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
51624 if (!ep) {
51625- atomic_inc(&mp->stats.xid_not_found);
51626+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51627 goto out;
51628 }
51629 if (ep->esb_stat & ESB_ST_COMPLETE) {
51630- atomic_inc(&mp->stats.xid_not_found);
51631+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51632 goto rel;
51633 }
51634 if (ep->rxid == FC_XID_UNKNOWN)
51635 ep->rxid = ntohs(fh->fh_rx_id);
51636 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
51637- atomic_inc(&mp->stats.xid_not_found);
51638+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51639 goto rel;
51640 }
51641 if (ep->did != ntoh24(fh->fh_s_id) &&
51642 ep->did != FC_FID_FLOGI) {
51643- atomic_inc(&mp->stats.xid_not_found);
51644+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51645 goto rel;
51646 }
51647 sof = fr_sof(fp);
51648@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51649 sp->ssb_stat |= SSB_ST_RESP;
51650 sp->id = fh->fh_seq_id;
51651 } else if (sp->id != fh->fh_seq_id) {
51652- atomic_inc(&mp->stats.seq_not_found);
51653+ atomic_inc_unchecked(&mp->stats.seq_not_found);
51654 goto rel;
51655 }
51656
51657@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
51658 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
51659
51660 if (!sp)
51661- atomic_inc(&mp->stats.xid_not_found);
51662+ atomic_inc_unchecked(&mp->stats.xid_not_found);
51663 else
51664- atomic_inc(&mp->stats.non_bls_resp);
51665+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
51666
51667 fc_frame_free(fp);
51668 }
51669@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
51670
51671 list_for_each_entry(ema, &lport->ema_list, ema_list) {
51672 mp = ema->mp;
51673- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
51674+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
51675 st->fc_no_free_exch_xid +=
51676- atomic_read(&mp->stats.no_free_exch_xid);
51677- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
51678- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
51679- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
51680- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
51681+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
51682+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
51683+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
51684+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
51685+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
51686 }
51687 }
51688 EXPORT_SYMBOL(fc_exch_update_stats);
51689diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
51690index 766098a..1c6c971 100644
51691--- a/drivers/scsi/libsas/sas_ata.c
51692+++ b/drivers/scsi/libsas/sas_ata.c
51693@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
51694 .postreset = ata_std_postreset,
51695 .error_handler = ata_std_error_handler,
51696 .post_internal_cmd = sas_ata_post_internal,
51697- .qc_defer = ata_std_qc_defer,
51698+ .qc_defer = ata_std_qc_defer,
51699 .qc_prep = ata_noop_qc_prep,
51700 .qc_issue = sas_ata_qc_issue,
51701 .qc_fill_rtf = sas_ata_qc_fill_rtf,
51702diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
51703index 434e903..5a4a79b 100644
51704--- a/drivers/scsi/lpfc/lpfc.h
51705+++ b/drivers/scsi/lpfc/lpfc.h
51706@@ -430,7 +430,7 @@ struct lpfc_vport {
51707 struct dentry *debug_nodelist;
51708 struct dentry *vport_debugfs_root;
51709 struct lpfc_debugfs_trc *disc_trc;
51710- atomic_t disc_trc_cnt;
51711+ atomic_unchecked_t disc_trc_cnt;
51712 #endif
51713 uint8_t stat_data_enabled;
51714 uint8_t stat_data_blocked;
51715@@ -880,8 +880,8 @@ struct lpfc_hba {
51716 struct timer_list fabric_block_timer;
51717 unsigned long bit_flags;
51718 #define FABRIC_COMANDS_BLOCKED 0
51719- atomic_t num_rsrc_err;
51720- atomic_t num_cmd_success;
51721+ atomic_unchecked_t num_rsrc_err;
51722+ atomic_unchecked_t num_cmd_success;
51723 unsigned long last_rsrc_error_time;
51724 unsigned long last_ramp_down_time;
51725 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
51726@@ -916,7 +916,7 @@ struct lpfc_hba {
51727
51728 struct dentry *debug_slow_ring_trc;
51729 struct lpfc_debugfs_trc *slow_ring_trc;
51730- atomic_t slow_ring_trc_cnt;
51731+ atomic_unchecked_t slow_ring_trc_cnt;
51732 /* iDiag debugfs sub-directory */
51733 struct dentry *idiag_root;
51734 struct dentry *idiag_pci_cfg;
51735diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
51736index b0aedce..89c6ca6 100644
51737--- a/drivers/scsi/lpfc/lpfc_debugfs.c
51738+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
51739@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
51740
51741 #include <linux/debugfs.h>
51742
51743-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51744+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
51745 static unsigned long lpfc_debugfs_start_time = 0L;
51746
51747 /* iDiag */
51748@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
51749 lpfc_debugfs_enable = 0;
51750
51751 len = 0;
51752- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
51753+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
51754 (lpfc_debugfs_max_disc_trc - 1);
51755 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
51756 dtp = vport->disc_trc + i;
51757@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
51758 lpfc_debugfs_enable = 0;
51759
51760 len = 0;
51761- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
51762+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
51763 (lpfc_debugfs_max_slow_ring_trc - 1);
51764 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
51765 dtp = phba->slow_ring_trc + i;
51766@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
51767 !vport || !vport->disc_trc)
51768 return;
51769
51770- index = atomic_inc_return(&vport->disc_trc_cnt) &
51771+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
51772 (lpfc_debugfs_max_disc_trc - 1);
51773 dtp = vport->disc_trc + index;
51774 dtp->fmt = fmt;
51775 dtp->data1 = data1;
51776 dtp->data2 = data2;
51777 dtp->data3 = data3;
51778- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51779+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51780 dtp->jif = jiffies;
51781 #endif
51782 return;
51783@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
51784 !phba || !phba->slow_ring_trc)
51785 return;
51786
51787- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
51788+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
51789 (lpfc_debugfs_max_slow_ring_trc - 1);
51790 dtp = phba->slow_ring_trc + index;
51791 dtp->fmt = fmt;
51792 dtp->data1 = data1;
51793 dtp->data2 = data2;
51794 dtp->data3 = data3;
51795- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
51796+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
51797 dtp->jif = jiffies;
51798 #endif
51799 return;
51800@@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51801 "slow_ring buffer\n");
51802 goto debug_failed;
51803 }
51804- atomic_set(&phba->slow_ring_trc_cnt, 0);
51805+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
51806 memset(phba->slow_ring_trc, 0,
51807 (sizeof(struct lpfc_debugfs_trc) *
51808 lpfc_debugfs_max_slow_ring_trc));
51809@@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
51810 "buffer\n");
51811 goto debug_failed;
51812 }
51813- atomic_set(&vport->disc_trc_cnt, 0);
51814+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
51815
51816 snprintf(name, sizeof(name), "discovery_trace");
51817 vport->debug_disc_trc =
51818diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
51819index a5769a9..718ecc7 100644
51820--- a/drivers/scsi/lpfc/lpfc_init.c
51821+++ b/drivers/scsi/lpfc/lpfc_init.c
51822@@ -11299,8 +11299,10 @@ lpfc_init(void)
51823 "misc_register returned with status %d", error);
51824
51825 if (lpfc_enable_npiv) {
51826- lpfc_transport_functions.vport_create = lpfc_vport_create;
51827- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51828+ pax_open_kernel();
51829+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
51830+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
51831+ pax_close_kernel();
51832 }
51833 lpfc_transport_template =
51834 fc_attach_transport(&lpfc_transport_functions);
51835diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
51836index 7862c55..5aa65df 100644
51837--- a/drivers/scsi/lpfc/lpfc_scsi.c
51838+++ b/drivers/scsi/lpfc/lpfc_scsi.c
51839@@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
51840 uint32_t evt_posted;
51841
51842 spin_lock_irqsave(&phba->hbalock, flags);
51843- atomic_inc(&phba->num_rsrc_err);
51844+ atomic_inc_unchecked(&phba->num_rsrc_err);
51845 phba->last_rsrc_error_time = jiffies;
51846
51847 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
51848@@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51849 unsigned long num_rsrc_err, num_cmd_success;
51850 int i;
51851
51852- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
51853- num_cmd_success = atomic_read(&phba->num_cmd_success);
51854+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
51855+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
51856
51857 /*
51858 * The error and success command counters are global per
51859@@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
51860 }
51861 }
51862 lpfc_destroy_vport_work_array(phba, vports);
51863- atomic_set(&phba->num_rsrc_err, 0);
51864- atomic_set(&phba->num_cmd_success, 0);
51865+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
51866+ atomic_set_unchecked(&phba->num_cmd_success, 0);
51867 }
51868
51869 /**
51870diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51871index dd46101..ca80eb9 100644
51872--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51873+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
51874@@ -1559,7 +1559,7 @@ _scsih_get_resync(struct device *dev)
51875 {
51876 struct scsi_device *sdev = to_scsi_device(dev);
51877 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51878- static struct _raid_device *raid_device;
51879+ struct _raid_device *raid_device;
51880 unsigned long flags;
51881 Mpi2RaidVolPage0_t vol_pg0;
51882 Mpi2ConfigReply_t mpi_reply;
51883@@ -1611,7 +1611,7 @@ _scsih_get_state(struct device *dev)
51884 {
51885 struct scsi_device *sdev = to_scsi_device(dev);
51886 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
51887- static struct _raid_device *raid_device;
51888+ struct _raid_device *raid_device;
51889 unsigned long flags;
51890 Mpi2RaidVolPage0_t vol_pg0;
51891 Mpi2ConfigReply_t mpi_reply;
51892@@ -6648,7 +6648,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
51893 Mpi2EventDataIrOperationStatus_t *event_data =
51894 (Mpi2EventDataIrOperationStatus_t *)
51895 fw_event->event_data;
51896- static struct _raid_device *raid_device;
51897+ struct _raid_device *raid_device;
51898 unsigned long flags;
51899 u16 handle;
51900
51901@@ -7119,7 +7119,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
51902 u64 sas_address;
51903 struct _sas_device *sas_device;
51904 struct _sas_node *expander_device;
51905- static struct _raid_device *raid_device;
51906+ struct _raid_device *raid_device;
51907 u8 retry_count;
51908 unsigned long flags;
51909
51910diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
51911index 6f3275d..fa5e6b6 100644
51912--- a/drivers/scsi/pmcraid.c
51913+++ b/drivers/scsi/pmcraid.c
51914@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
51915 res->scsi_dev = scsi_dev;
51916 scsi_dev->hostdata = res;
51917 res->change_detected = 0;
51918- atomic_set(&res->read_failures, 0);
51919- atomic_set(&res->write_failures, 0);
51920+ atomic_set_unchecked(&res->read_failures, 0);
51921+ atomic_set_unchecked(&res->write_failures, 0);
51922 rc = 0;
51923 }
51924 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
51925@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
51926
51927 /* If this was a SCSI read/write command keep count of errors */
51928 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
51929- atomic_inc(&res->read_failures);
51930+ atomic_inc_unchecked(&res->read_failures);
51931 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
51932- atomic_inc(&res->write_failures);
51933+ atomic_inc_unchecked(&res->write_failures);
51934
51935 if (!RES_IS_GSCSI(res->cfg_entry) &&
51936 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
51937@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
51938 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51939 * hrrq_id assigned here in queuecommand
51940 */
51941- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51942+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51943 pinstance->num_hrrq;
51944 cmd->cmd_done = pmcraid_io_done;
51945
51946@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
51947 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
51948 * hrrq_id assigned here in queuecommand
51949 */
51950- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
51951+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
51952 pinstance->num_hrrq;
51953
51954 if (request_size) {
51955@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
51956
51957 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
51958 /* add resources only after host is added into system */
51959- if (!atomic_read(&pinstance->expose_resources))
51960+ if (!atomic_read_unchecked(&pinstance->expose_resources))
51961 return;
51962
51963 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
51964@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
51965 init_waitqueue_head(&pinstance->reset_wait_q);
51966
51967 atomic_set(&pinstance->outstanding_cmds, 0);
51968- atomic_set(&pinstance->last_message_id, 0);
51969- atomic_set(&pinstance->expose_resources, 0);
51970+ atomic_set_unchecked(&pinstance->last_message_id, 0);
51971+ atomic_set_unchecked(&pinstance->expose_resources, 0);
51972
51973 INIT_LIST_HEAD(&pinstance->free_res_q);
51974 INIT_LIST_HEAD(&pinstance->used_res_q);
51975@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
51976 /* Schedule worker thread to handle CCN and take care of adding and
51977 * removing devices to OS
51978 */
51979- atomic_set(&pinstance->expose_resources, 1);
51980+ atomic_set_unchecked(&pinstance->expose_resources, 1);
51981 schedule_work(&pinstance->worker_q);
51982 return rc;
51983
51984diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
51985index e1d150f..6c6df44 100644
51986--- a/drivers/scsi/pmcraid.h
51987+++ b/drivers/scsi/pmcraid.h
51988@@ -748,7 +748,7 @@ struct pmcraid_instance {
51989 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
51990
51991 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
51992- atomic_t last_message_id;
51993+ atomic_unchecked_t last_message_id;
51994
51995 /* configuration table */
51996 struct pmcraid_config_table *cfg_table;
51997@@ -777,7 +777,7 @@ struct pmcraid_instance {
51998 atomic_t outstanding_cmds;
51999
52000 /* should add/delete resources to mid-layer now ?*/
52001- atomic_t expose_resources;
52002+ atomic_unchecked_t expose_resources;
52003
52004
52005
52006@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
52007 struct pmcraid_config_table_entry_ext cfg_entry_ext;
52008 };
52009 struct scsi_device *scsi_dev; /* Link scsi_device structure */
52010- atomic_t read_failures; /* count of failed READ commands */
52011- atomic_t write_failures; /* count of failed WRITE commands */
52012+ atomic_unchecked_t read_failures; /* count of failed READ commands */
52013+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
52014
52015 /* To indicate add/delete/modify during CCN */
52016 u8 change_detected;
52017diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
52018index 16fe519..3b1ec82 100644
52019--- a/drivers/scsi/qla2xxx/qla_attr.c
52020+++ b/drivers/scsi/qla2xxx/qla_attr.c
52021@@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
52022 return 0;
52023 }
52024
52025-struct fc_function_template qla2xxx_transport_functions = {
52026+fc_function_template_no_const qla2xxx_transport_functions = {
52027
52028 .show_host_node_name = 1,
52029 .show_host_port_name = 1,
52030@@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
52031 .bsg_timeout = qla24xx_bsg_timeout,
52032 };
52033
52034-struct fc_function_template qla2xxx_transport_vport_functions = {
52035+fc_function_template_no_const qla2xxx_transport_vport_functions = {
52036
52037 .show_host_node_name = 1,
52038 .show_host_port_name = 1,
52039diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
52040index d646540..5b13554 100644
52041--- a/drivers/scsi/qla2xxx/qla_gbl.h
52042+++ b/drivers/scsi/qla2xxx/qla_gbl.h
52043@@ -569,8 +569,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
52044 struct device_attribute;
52045 extern struct device_attribute *qla2x00_host_attrs[];
52046 struct fc_function_template;
52047-extern struct fc_function_template qla2xxx_transport_functions;
52048-extern struct fc_function_template qla2xxx_transport_vport_functions;
52049+extern fc_function_template_no_const qla2xxx_transport_functions;
52050+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
52051 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
52052 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
52053 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
52054diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
52055index 8252c0e..613adad 100644
52056--- a/drivers/scsi/qla2xxx/qla_os.c
52057+++ b/drivers/scsi/qla2xxx/qla_os.c
52058@@ -1493,8 +1493,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
52059 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
52060 /* Ok, a 64bit DMA mask is applicable. */
52061 ha->flags.enable_64bit_addressing = 1;
52062- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
52063- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
52064+ pax_open_kernel();
52065+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
52066+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
52067+ pax_close_kernel();
52068 return;
52069 }
52070 }
52071diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
52072index 8f6d0fb..1b21097 100644
52073--- a/drivers/scsi/qla4xxx/ql4_def.h
52074+++ b/drivers/scsi/qla4xxx/ql4_def.h
52075@@ -305,7 +305,7 @@ struct ddb_entry {
52076 * (4000 only) */
52077 atomic_t relogin_timer; /* Max Time to wait for
52078 * relogin to complete */
52079- atomic_t relogin_retry_count; /* Num of times relogin has been
52080+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
52081 * retried */
52082 uint32_t default_time2wait; /* Default Min time between
52083 * relogins (+aens) */
52084diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
52085index 199fcf7..3c3a918 100644
52086--- a/drivers/scsi/qla4xxx/ql4_os.c
52087+++ b/drivers/scsi/qla4xxx/ql4_os.c
52088@@ -4496,12 +4496,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
52089 */
52090 if (!iscsi_is_session_online(cls_sess)) {
52091 /* Reset retry relogin timer */
52092- atomic_inc(&ddb_entry->relogin_retry_count);
52093+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
52094 DEBUG2(ql4_printk(KERN_INFO, ha,
52095 "%s: index[%d] relogin timed out-retrying"
52096 " relogin (%d), retry (%d)\n", __func__,
52097 ddb_entry->fw_ddb_index,
52098- atomic_read(&ddb_entry->relogin_retry_count),
52099+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
52100 ddb_entry->default_time2wait + 4));
52101 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
52102 atomic_set(&ddb_entry->retry_relogin_timer,
52103@@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
52104
52105 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
52106 atomic_set(&ddb_entry->relogin_timer, 0);
52107- atomic_set(&ddb_entry->relogin_retry_count, 0);
52108+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
52109 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
52110 ddb_entry->default_relogin_timeout =
52111 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
52112diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
52113index d81f3cc..0093e5b 100644
52114--- a/drivers/scsi/scsi.c
52115+++ b/drivers/scsi/scsi.c
52116@@ -645,7 +645,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
52117 struct Scsi_Host *host = cmd->device->host;
52118 int rtn = 0;
52119
52120- atomic_inc(&cmd->device->iorequest_cnt);
52121+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52122
52123 /* check if the device is still usable */
52124 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
52125diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
52126index 7cb8c73..14561b5 100644
52127--- a/drivers/scsi/scsi_lib.c
52128+++ b/drivers/scsi/scsi_lib.c
52129@@ -1581,7 +1581,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
52130 shost = sdev->host;
52131 scsi_init_cmd_errh(cmd);
52132 cmd->result = DID_NO_CONNECT << 16;
52133- atomic_inc(&cmd->device->iorequest_cnt);
52134+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
52135
52136 /*
52137 * SCSI request completion path will do scsi_device_unbusy(),
52138@@ -1604,9 +1604,9 @@ static void scsi_softirq_done(struct request *rq)
52139
52140 INIT_LIST_HEAD(&cmd->eh_entry);
52141
52142- atomic_inc(&cmd->device->iodone_cnt);
52143+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
52144 if (cmd->result)
52145- atomic_inc(&cmd->device->ioerr_cnt);
52146+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
52147
52148 disposition = scsi_decide_disposition(cmd);
52149 if (disposition != SUCCESS &&
52150diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
52151index 8b4105a..1f58363 100644
52152--- a/drivers/scsi/scsi_sysfs.c
52153+++ b/drivers/scsi/scsi_sysfs.c
52154@@ -805,7 +805,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
52155 char *buf) \
52156 { \
52157 struct scsi_device *sdev = to_scsi_device(dev); \
52158- unsigned long long count = atomic_read(&sdev->field); \
52159+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
52160 return snprintf(buf, 20, "0x%llx\n", count); \
52161 } \
52162 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
52163diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
52164index 5d6f348..18778a6b 100644
52165--- a/drivers/scsi/scsi_transport_fc.c
52166+++ b/drivers/scsi/scsi_transport_fc.c
52167@@ -501,7 +501,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
52168 * Netlink Infrastructure
52169 */
52170
52171-static atomic_t fc_event_seq;
52172+static atomic_unchecked_t fc_event_seq;
52173
52174 /**
52175 * fc_get_event_number - Obtain the next sequential FC event number
52176@@ -514,7 +514,7 @@ static atomic_t fc_event_seq;
52177 u32
52178 fc_get_event_number(void)
52179 {
52180- return atomic_add_return(1, &fc_event_seq);
52181+ return atomic_add_return_unchecked(1, &fc_event_seq);
52182 }
52183 EXPORT_SYMBOL(fc_get_event_number);
52184
52185@@ -658,7 +658,7 @@ static __init int fc_transport_init(void)
52186 {
52187 int error;
52188
52189- atomic_set(&fc_event_seq, 0);
52190+ atomic_set_unchecked(&fc_event_seq, 0);
52191
52192 error = transport_class_register(&fc_host_class);
52193 if (error)
52194@@ -848,7 +848,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
52195 char *cp;
52196
52197 *val = simple_strtoul(buf, &cp, 0);
52198- if ((*cp && (*cp != '\n')) || (*val < 0))
52199+ if (*cp && (*cp != '\n'))
52200 return -EINVAL;
52201 /*
52202 * Check for overflow; dev_loss_tmo is u32
52203diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
52204index 67d43e3..8cee73c 100644
52205--- a/drivers/scsi/scsi_transport_iscsi.c
52206+++ b/drivers/scsi/scsi_transport_iscsi.c
52207@@ -79,7 +79,7 @@ struct iscsi_internal {
52208 struct transport_container session_cont;
52209 };
52210
52211-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
52212+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
52213 static struct workqueue_struct *iscsi_eh_timer_workq;
52214
52215 static DEFINE_IDA(iscsi_sess_ida);
52216@@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
52217 int err;
52218
52219 ihost = shost->shost_data;
52220- session->sid = atomic_add_return(1, &iscsi_session_nr);
52221+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
52222
52223 if (target_id == ISCSI_MAX_TARGET) {
52224 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
52225@@ -4515,7 +4515,7 @@ static __init int iscsi_transport_init(void)
52226 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
52227 ISCSI_TRANSPORT_VERSION);
52228
52229- atomic_set(&iscsi_session_nr, 0);
52230+ atomic_set_unchecked(&iscsi_session_nr, 0);
52231
52232 err = class_register(&iscsi_transport_class);
52233 if (err)
52234diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
52235index ae45bd9..c32a586 100644
52236--- a/drivers/scsi/scsi_transport_srp.c
52237+++ b/drivers/scsi/scsi_transport_srp.c
52238@@ -35,7 +35,7 @@
52239 #include "scsi_priv.h"
52240
52241 struct srp_host_attrs {
52242- atomic_t next_port_id;
52243+ atomic_unchecked_t next_port_id;
52244 };
52245 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
52246
52247@@ -100,7 +100,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
52248 struct Scsi_Host *shost = dev_to_shost(dev);
52249 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
52250
52251- atomic_set(&srp_host->next_port_id, 0);
52252+ atomic_set_unchecked(&srp_host->next_port_id, 0);
52253 return 0;
52254 }
52255
52256@@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
52257 rport_fast_io_fail_timedout);
52258 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
52259
52260- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
52261+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
52262 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
52263
52264 transport_setup_device(&rport->dev);
52265diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
52266index 2c2041c..9d94085 100644
52267--- a/drivers/scsi/sd.c
52268+++ b/drivers/scsi/sd.c
52269@@ -3002,7 +3002,7 @@ static int sd_probe(struct device *dev)
52270 sdkp->disk = gd;
52271 sdkp->index = index;
52272 atomic_set(&sdkp->openers, 0);
52273- atomic_set(&sdkp->device->ioerr_cnt, 0);
52274+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
52275
52276 if (!sdp->request_queue->rq_timeout) {
52277 if (sdp->type != TYPE_MOD)
52278diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
52279index 01cf888..59e0475 100644
52280--- a/drivers/scsi/sg.c
52281+++ b/drivers/scsi/sg.c
52282@@ -1138,7 +1138,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
52283 sdp->disk->disk_name,
52284 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
52285 NULL,
52286- (char *)arg);
52287+ (char __user *)arg);
52288 case BLKTRACESTART:
52289 return blk_trace_startstop(sdp->device->request_queue, 1);
52290 case BLKTRACESTOP:
52291diff --git a/drivers/soc/tegra/fuse/fuse-tegra.c b/drivers/soc/tegra/fuse/fuse-tegra.c
52292index 11a5043..e36f04c 100644
52293--- a/drivers/soc/tegra/fuse/fuse-tegra.c
52294+++ b/drivers/soc/tegra/fuse/fuse-tegra.c
52295@@ -70,7 +70,7 @@ static ssize_t fuse_read(struct file *fd, struct kobject *kobj,
52296 return i;
52297 }
52298
52299-static struct bin_attribute fuse_bin_attr = {
52300+static bin_attribute_no_const fuse_bin_attr = {
52301 .attr = { .name = "fuse", .mode = S_IRUGO, },
52302 .read = fuse_read,
52303 };
52304diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
52305index ca935df..ae8a3dc 100644
52306--- a/drivers/spi/spi.c
52307+++ b/drivers/spi/spi.c
52308@@ -2210,7 +2210,7 @@ int spi_bus_unlock(struct spi_master *master)
52309 EXPORT_SYMBOL_GPL(spi_bus_unlock);
52310
52311 /* portable code must never pass more than 32 bytes */
52312-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
52313+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
52314
52315 static u8 *buf;
52316
52317diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
52318index b41429f..2de5373 100644
52319--- a/drivers/staging/android/timed_output.c
52320+++ b/drivers/staging/android/timed_output.c
52321@@ -25,7 +25,7 @@
52322 #include "timed_output.h"
52323
52324 static struct class *timed_output_class;
52325-static atomic_t device_count;
52326+static atomic_unchecked_t device_count;
52327
52328 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
52329 char *buf)
52330@@ -65,7 +65,7 @@ static int create_timed_output_class(void)
52331 timed_output_class = class_create(THIS_MODULE, "timed_output");
52332 if (IS_ERR(timed_output_class))
52333 return PTR_ERR(timed_output_class);
52334- atomic_set(&device_count, 0);
52335+ atomic_set_unchecked(&device_count, 0);
52336 timed_output_class->dev_groups = timed_output_groups;
52337 }
52338
52339@@ -83,7 +83,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
52340 if (ret < 0)
52341 return ret;
52342
52343- tdev->index = atomic_inc_return(&device_count);
52344+ tdev->index = atomic_inc_return_unchecked(&device_count);
52345 tdev->dev = device_create(timed_output_class, NULL,
52346 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
52347 if (IS_ERR(tdev->dev))
52348diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
52349index 001348c..cfaac8a 100644
52350--- a/drivers/staging/gdm724x/gdm_tty.c
52351+++ b/drivers/staging/gdm724x/gdm_tty.c
52352@@ -44,7 +44,7 @@
52353 #define gdm_tty_send_control(n, r, v, d, l) (\
52354 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
52355
52356-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
52357+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
52358
52359 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
52360 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
52361diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
52362index 6b22106..6c6e641 100644
52363--- a/drivers/staging/imx-drm/imx-drm-core.c
52364+++ b/drivers/staging/imx-drm/imx-drm-core.c
52365@@ -355,7 +355,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
52366 if (imxdrm->pipes >= MAX_CRTC)
52367 return -EINVAL;
52368
52369- if (imxdrm->drm->open_count)
52370+ if (local_read(&imxdrm->drm->open_count))
52371 return -EBUSY;
52372
52373 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
52374diff --git a/drivers/staging/line6/driver.c b/drivers/staging/line6/driver.c
52375index 503b2d7..c918745 100644
52376--- a/drivers/staging/line6/driver.c
52377+++ b/drivers/staging/line6/driver.c
52378@@ -463,7 +463,7 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52379 {
52380 struct usb_device *usbdev = line6->usbdev;
52381 int ret;
52382- unsigned char len;
52383+ unsigned char *plen;
52384
52385 /* query the serial number: */
52386 ret = usb_control_msg(usbdev, usb_sndctrlpipe(usbdev, 0), 0x67,
52387@@ -476,27 +476,34 @@ int line6_read_data(struct usb_line6 *line6, int address, void *data,
52388 return ret;
52389 }
52390
52391+ plen = kmalloc(1, GFP_KERNEL);
52392+ if (plen == NULL)
52393+ return -ENOMEM;
52394+
52395 /* Wait for data length. We'll get 0xff until length arrives. */
52396 do {
52397 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52398 USB_TYPE_VENDOR | USB_RECIP_DEVICE |
52399 USB_DIR_IN,
52400- 0x0012, 0x0000, &len, 1,
52401+ 0x0012, 0x0000, plen, 1,
52402 LINE6_TIMEOUT * HZ);
52403 if (ret < 0) {
52404 dev_err(line6->ifcdev,
52405 "receive length failed (error %d)\n", ret);
52406+ kfree(plen);
52407 return ret;
52408 }
52409- } while (len == 0xff);
52410+ } while (*plen == 0xff);
52411
52412- if (len != datalen) {
52413+ if (*plen != datalen) {
52414 /* should be equal or something went wrong */
52415 dev_err(line6->ifcdev,
52416 "length mismatch (expected %d, got %d)\n",
52417- (int)datalen, (int)len);
52418+ (int)datalen, (int)*plen);
52419+ kfree(plen);
52420 return -EINVAL;
52421 }
52422+ kfree(plen);
52423
52424 /* receive the result: */
52425 ret = usb_control_msg(usbdev, usb_rcvctrlpipe(usbdev, 0), 0x67,
52426diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
52427index bcce919..f30fcf9 100644
52428--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
52429+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
52430@@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
52431 return 0;
52432 }
52433
52434-sfw_test_client_ops_t brw_test_client;
52435-void brw_init_test_client(void)
52436-{
52437- brw_test_client.tso_init = brw_client_init;
52438- brw_test_client.tso_fini = brw_client_fini;
52439- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
52440- brw_test_client.tso_done_rpc = brw_client_done_rpc;
52441+sfw_test_client_ops_t brw_test_client = {
52442+ .tso_init = brw_client_init,
52443+ .tso_fini = brw_client_fini,
52444+ .tso_prep_rpc = brw_client_prep_rpc,
52445+ .tso_done_rpc = brw_client_done_rpc,
52446 };
52447
52448 srpc_service_t brw_test_service;
52449diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
52450index 7e83dff..1f9a545 100644
52451--- a/drivers/staging/lustre/lnet/selftest/framework.c
52452+++ b/drivers/staging/lustre/lnet/selftest/framework.c
52453@@ -1633,12 +1633,10 @@ static srpc_service_t sfw_services[] =
52454
52455 extern sfw_test_client_ops_t ping_test_client;
52456 extern srpc_service_t ping_test_service;
52457-extern void ping_init_test_client(void);
52458 extern void ping_init_test_service(void);
52459
52460 extern sfw_test_client_ops_t brw_test_client;
52461 extern srpc_service_t brw_test_service;
52462-extern void brw_init_test_client(void);
52463 extern void brw_init_test_service(void);
52464
52465
52466@@ -1682,12 +1680,10 @@ sfw_startup (void)
52467 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
52468 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
52469
52470- brw_init_test_client();
52471 brw_init_test_service();
52472 rc = sfw_register_test(&brw_test_service, &brw_test_client);
52473 LASSERT (rc == 0);
52474
52475- ping_init_test_client();
52476 ping_init_test_service();
52477 rc = sfw_register_test(&ping_test_service, &ping_test_client);
52478 LASSERT (rc == 0);
52479diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
52480index 750cac4..e4d751f 100644
52481--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
52482+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
52483@@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
52484 return 0;
52485 }
52486
52487-sfw_test_client_ops_t ping_test_client;
52488-void ping_init_test_client(void)
52489-{
52490- ping_test_client.tso_init = ping_client_init;
52491- ping_test_client.tso_fini = ping_client_fini;
52492- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
52493- ping_test_client.tso_done_rpc = ping_client_done_rpc;
52494-}
52495+sfw_test_client_ops_t ping_test_client = {
52496+ .tso_init = ping_client_init,
52497+ .tso_fini = ping_client_fini,
52498+ .tso_prep_rpc = ping_client_prep_rpc,
52499+ .tso_done_rpc = ping_client_done_rpc,
52500+};
52501
52502 srpc_service_t ping_test_service;
52503 void ping_init_test_service(void)
52504diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52505index 30b1812f..9e5bd0b 100644
52506--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
52507+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
52508@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
52509 ldlm_completion_callback lcs_completion;
52510 ldlm_blocking_callback lcs_blocking;
52511 ldlm_glimpse_callback lcs_glimpse;
52512-};
52513+} __no_const;
52514
52515 /* ldlm_lockd.c */
52516 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
52517diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
52518index 489bdd3..65058081 100644
52519--- a/drivers/staging/lustre/lustre/include/obd.h
52520+++ b/drivers/staging/lustre/lustre/include/obd.h
52521@@ -1438,7 +1438,7 @@ struct md_ops {
52522 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
52523 * wrapper function in include/linux/obd_class.h.
52524 */
52525-};
52526+} __no_const;
52527
52528 struct lsm_operations {
52529 void (*lsm_free)(struct lov_stripe_md *);
52530diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52531index b798daa..b28ca8f 100644
52532--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52533+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
52534@@ -258,7 +258,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
52535 int added = (mode == LCK_NL);
52536 int overlaps = 0;
52537 int splitted = 0;
52538- const struct ldlm_callback_suite null_cbs = { NULL };
52539+ const struct ldlm_callback_suite null_cbs = { };
52540
52541 CDEBUG(D_DLMTRACE, "flags %#llx owner %llu pid %u mode %u start %llu end %llu\n",
52542 *flags, new->l_policy_data.l_flock.owner,
52543diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52544index 13a9266..3439390 100644
52545--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52546+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
52547@@ -235,7 +235,7 @@ int proc_console_max_delay_cs(struct ctl_table *table, int write,
52548 void __user *buffer, size_t *lenp, loff_t *ppos)
52549 {
52550 int rc, max_delay_cs;
52551- struct ctl_table dummy = *table;
52552+ ctl_table_no_const dummy = *table;
52553 long d;
52554
52555 dummy.data = &max_delay_cs;
52556@@ -267,7 +267,7 @@ int proc_console_min_delay_cs(struct ctl_table *table, int write,
52557 void __user *buffer, size_t *lenp, loff_t *ppos)
52558 {
52559 int rc, min_delay_cs;
52560- struct ctl_table dummy = *table;
52561+ ctl_table_no_const dummy = *table;
52562 long d;
52563
52564 dummy.data = &min_delay_cs;
52565@@ -299,7 +299,7 @@ int proc_console_backoff(struct ctl_table *table, int write,
52566 void __user *buffer, size_t *lenp, loff_t *ppos)
52567 {
52568 int rc, backoff;
52569- struct ctl_table dummy = *table;
52570+ ctl_table_no_const dummy = *table;
52571
52572 dummy.data = &backoff;
52573 dummy.proc_handler = &proc_dointvec;
52574diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
52575index 3396858..c0bd996 100644
52576--- a/drivers/staging/lustre/lustre/libcfs/module.c
52577+++ b/drivers/staging/lustre/lustre/libcfs/module.c
52578@@ -314,11 +314,11 @@ out:
52579
52580
52581 struct cfs_psdev_ops libcfs_psdev_ops = {
52582- libcfs_psdev_open,
52583- libcfs_psdev_release,
52584- NULL,
52585- NULL,
52586- libcfs_ioctl
52587+ .p_open = libcfs_psdev_open,
52588+ .p_close = libcfs_psdev_release,
52589+ .p_read = NULL,
52590+ .p_write = NULL,
52591+ .p_ioctl = libcfs_ioctl
52592 };
52593
52594 extern int insert_proc(void);
52595diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
52596index efa2faf..03a9836 100644
52597--- a/drivers/staging/lustre/lustre/llite/dir.c
52598+++ b/drivers/staging/lustre/lustre/llite/dir.c
52599@@ -659,7 +659,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
52600 int mode;
52601 int err;
52602
52603- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
52604+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
52605 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
52606 strlen(filename), mode, LUSTRE_OPC_MKDIR,
52607 lump);
52608diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
52609index a0f4868..139f1fb 100644
52610--- a/drivers/staging/octeon/ethernet-rx.c
52611+++ b/drivers/staging/octeon/ethernet-rx.c
52612@@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52613 /* Increment RX stats for virtual ports */
52614 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
52615 #ifdef CONFIG_64BIT
52616- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
52617- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
52618+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
52619+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
52620 #else
52621- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
52622- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
52623+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
52624+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
52625 #endif
52626 }
52627 netif_receive_skb(skb);
52628@@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
52629 dev->name);
52630 */
52631 #ifdef CONFIG_64BIT
52632- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
52633+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52634 #else
52635- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
52636+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
52637 #endif
52638 dev_kfree_skb_irq(skb);
52639 }
52640diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
52641index 2aa7235..ba3c205 100644
52642--- a/drivers/staging/octeon/ethernet.c
52643+++ b/drivers/staging/octeon/ethernet.c
52644@@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
52645 * since the RX tasklet also increments it.
52646 */
52647 #ifdef CONFIG_64BIT
52648- atomic64_add(rx_status.dropped_packets,
52649- (atomic64_t *)&priv->stats.rx_dropped);
52650+ atomic64_add_unchecked(rx_status.dropped_packets,
52651+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
52652 #else
52653- atomic_add(rx_status.dropped_packets,
52654- (atomic_t *)&priv->stats.rx_dropped);
52655+ atomic_add_unchecked(rx_status.dropped_packets,
52656+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
52657 #endif
52658 }
52659
52660diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
52661index 56d5c50..a14f4db 100644
52662--- a/drivers/staging/rtl8188eu/include/hal_intf.h
52663+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
52664@@ -234,7 +234,7 @@ struct hal_ops {
52665
52666 void (*hal_notch_filter)(struct adapter *adapter, bool enable);
52667 void (*hal_reset_security_engine)(struct adapter *adapter);
52668-};
52669+} __no_const;
52670
52671 enum rt_eeprom_type {
52672 EEPROM_93C46,
52673diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
52674index dc23395..cf7e9b1 100644
52675--- a/drivers/staging/rtl8712/rtl871x_io.h
52676+++ b/drivers/staging/rtl8712/rtl871x_io.h
52677@@ -108,7 +108,7 @@ struct _io_ops {
52678 u8 *pmem);
52679 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
52680 u8 *pmem);
52681-};
52682+} __no_const;
52683
52684 struct io_req {
52685 struct list_head list;
52686diff --git a/drivers/staging/unisys/visorchipset/visorchipset.h b/drivers/staging/unisys/visorchipset/visorchipset.h
52687index 2bf2e2f..84421c9 100644
52688--- a/drivers/staging/unisys/visorchipset/visorchipset.h
52689+++ b/drivers/staging/unisys/visorchipset/visorchipset.h
52690@@ -228,7 +228,7 @@ typedef struct {
52691 void (*device_resume)(ulong busNo, ulong devNo);
52692 int (*get_channel_info)(uuid_le typeGuid, ulong *minSize,
52693 ulong *maxSize);
52694-} VISORCHIPSET_BUSDEV_NOTIFIERS;
52695+} __no_const VISORCHIPSET_BUSDEV_NOTIFIERS;
52696
52697 /* These functions live inside visorchipset, and will be called to indicate
52698 * responses to specific events (by code outside of visorchipset).
52699@@ -243,7 +243,7 @@ typedef struct {
52700 void (*device_destroy)(ulong busNo, ulong devNo, int response);
52701 void (*device_pause)(ulong busNo, ulong devNo, int response);
52702 void (*device_resume)(ulong busNo, ulong devNo, int response);
52703-} VISORCHIPSET_BUSDEV_RESPONDERS;
52704+} __no_const VISORCHIPSET_BUSDEV_RESPONDERS;
52705
52706 /** Register functions (in the bus driver) to get called by visorchipset
52707 * whenever a bus or device appears for which this service partition is
52708diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
52709index 164136b..7244df5 100644
52710--- a/drivers/staging/vt6655/hostap.c
52711+++ b/drivers/staging/vt6655/hostap.c
52712@@ -68,14 +68,13 @@ static int msglevel = MSG_LEVEL_INFO;
52713 *
52714 */
52715
52716+static net_device_ops_no_const apdev_netdev_ops;
52717+
52718 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
52719 {
52720 PSDevice apdev_priv;
52721 struct net_device *dev = pDevice->dev;
52722 int ret;
52723- const struct net_device_ops apdev_netdev_ops = {
52724- .ndo_start_xmit = pDevice->tx_80211,
52725- };
52726
52727 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
52728
52729@@ -87,6 +86,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
52730 *apdev_priv = *pDevice;
52731 eth_hw_addr_inherit(pDevice->apdev, dev);
52732
52733+ /* only half broken now */
52734+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
52735 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
52736
52737 pDevice->apdev->type = ARPHRD_IEEE80211;
52738diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
52739index e7e9372..161f530 100644
52740--- a/drivers/target/sbp/sbp_target.c
52741+++ b/drivers/target/sbp/sbp_target.c
52742@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
52743
52744 #define SESSION_MAINTENANCE_INTERVAL HZ
52745
52746-static atomic_t login_id = ATOMIC_INIT(0);
52747+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
52748
52749 static void session_maintenance_work(struct work_struct *);
52750 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
52751@@ -444,7 +444,7 @@ static void sbp_management_request_login(
52752 login->lun = se_lun;
52753 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
52754 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
52755- login->login_id = atomic_inc_return(&login_id);
52756+ login->login_id = atomic_inc_return_unchecked(&login_id);
52757
52758 login->tgt_agt = sbp_target_agent_register(login);
52759 if (IS_ERR(login->tgt_agt)) {
52760diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
52761index 15a1c13..6c9b96b 100644
52762--- a/drivers/target/target_core_device.c
52763+++ b/drivers/target/target_core_device.c
52764@@ -1526,7 +1526,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
52765 spin_lock_init(&dev->se_tmr_lock);
52766 spin_lock_init(&dev->qf_cmd_lock);
52767 sema_init(&dev->caw_sem, 1);
52768- atomic_set(&dev->dev_ordered_id, 0);
52769+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
52770 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
52771 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
52772 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
52773diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
52774index ab61014..8f1116e 100644
52775--- a/drivers/target/target_core_transport.c
52776+++ b/drivers/target/target_core_transport.c
52777@@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
52778 * Used to determine when ORDERED commands should go from
52779 * Dormant to Active status.
52780 */
52781- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
52782+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
52783 smp_mb__after_atomic();
52784 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
52785 cmd->se_ordered_id, cmd->sam_task_attr,
52786diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
52787index 4b2b999..cad9fa5 100644
52788--- a/drivers/thermal/of-thermal.c
52789+++ b/drivers/thermal/of-thermal.c
52790@@ -30,6 +30,7 @@
52791 #include <linux/err.h>
52792 #include <linux/export.h>
52793 #include <linux/string.h>
52794+#include <linux/mm.h>
52795
52796 #include "thermal_core.h"
52797
52798@@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
52799 tz->get_trend = get_trend;
52800 tz->sensor_data = data;
52801
52802- tzd->ops->get_temp = of_thermal_get_temp;
52803- tzd->ops->get_trend = of_thermal_get_trend;
52804+ pax_open_kernel();
52805+ *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
52806+ *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
52807+ pax_close_kernel();
52808 mutex_unlock(&tzd->lock);
52809
52810 return tzd;
52811@@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
52812 return;
52813
52814 mutex_lock(&tzd->lock);
52815- tzd->ops->get_temp = NULL;
52816- tzd->ops->get_trend = NULL;
52817+ pax_open_kernel();
52818+ *(void **)&tzd->ops->get_temp = NULL;
52819+ *(void **)&tzd->ops->get_trend = NULL;
52820+ pax_close_kernel();
52821
52822 tz->get_temp = NULL;
52823 tz->get_trend = NULL;
52824diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
52825index fd66f57..48e6376 100644
52826--- a/drivers/tty/cyclades.c
52827+++ b/drivers/tty/cyclades.c
52828@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
52829 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
52830 info->port.count);
52831 #endif
52832- info->port.count++;
52833+ atomic_inc(&info->port.count);
52834 #ifdef CY_DEBUG_COUNT
52835 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
52836- current->pid, info->port.count);
52837+ current->pid, atomic_read(&info->port.count));
52838 #endif
52839
52840 /*
52841@@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
52842 for (j = 0; j < cy_card[i].nports; j++) {
52843 info = &cy_card[i].ports[j];
52844
52845- if (info->port.count) {
52846+ if (atomic_read(&info->port.count)) {
52847 /* XXX is the ldisc num worth this? */
52848 struct tty_struct *tty;
52849 struct tty_ldisc *ld;
52850diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
52851index 4fcec1d..5a036f7 100644
52852--- a/drivers/tty/hvc/hvc_console.c
52853+++ b/drivers/tty/hvc/hvc_console.c
52854@@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
52855
52856 spin_lock_irqsave(&hp->port.lock, flags);
52857 /* Check and then increment for fast path open. */
52858- if (hp->port.count++ > 0) {
52859+ if (atomic_inc_return(&hp->port.count) > 1) {
52860 spin_unlock_irqrestore(&hp->port.lock, flags);
52861 hvc_kick();
52862 return 0;
52863@@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52864
52865 spin_lock_irqsave(&hp->port.lock, flags);
52866
52867- if (--hp->port.count == 0) {
52868+ if (atomic_dec_return(&hp->port.count) == 0) {
52869 spin_unlock_irqrestore(&hp->port.lock, flags);
52870 /* We are done with the tty pointer now. */
52871 tty_port_tty_set(&hp->port, NULL);
52872@@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
52873 */
52874 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
52875 } else {
52876- if (hp->port.count < 0)
52877+ if (atomic_read(&hp->port.count) < 0)
52878 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
52879- hp->vtermno, hp->port.count);
52880+ hp->vtermno, atomic_read(&hp->port.count));
52881 spin_unlock_irqrestore(&hp->port.lock, flags);
52882 }
52883 }
52884@@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
52885 * open->hangup case this can be called after the final close so prevent
52886 * that from happening for now.
52887 */
52888- if (hp->port.count <= 0) {
52889+ if (atomic_read(&hp->port.count) <= 0) {
52890 spin_unlock_irqrestore(&hp->port.lock, flags);
52891 return;
52892 }
52893
52894- hp->port.count = 0;
52895+ atomic_set(&hp->port.count, 0);
52896 spin_unlock_irqrestore(&hp->port.lock, flags);
52897 tty_port_tty_set(&hp->port, NULL);
52898
52899@@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
52900 return -EPIPE;
52901
52902 /* FIXME what's this (unprotected) check for? */
52903- if (hp->port.count <= 0)
52904+ if (atomic_read(&hp->port.count) <= 0)
52905 return -EIO;
52906
52907 spin_lock_irqsave(&hp->lock, flags);
52908diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
52909index 81e939e..95ead10 100644
52910--- a/drivers/tty/hvc/hvcs.c
52911+++ b/drivers/tty/hvc/hvcs.c
52912@@ -83,6 +83,7 @@
52913 #include <asm/hvcserver.h>
52914 #include <asm/uaccess.h>
52915 #include <asm/vio.h>
52916+#include <asm/local.h>
52917
52918 /*
52919 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
52920@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
52921
52922 spin_lock_irqsave(&hvcsd->lock, flags);
52923
52924- if (hvcsd->port.count > 0) {
52925+ if (atomic_read(&hvcsd->port.count) > 0) {
52926 spin_unlock_irqrestore(&hvcsd->lock, flags);
52927 printk(KERN_INFO "HVCS: vterm state unchanged. "
52928 "The hvcs device node is still in use.\n");
52929@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
52930 }
52931 }
52932
52933- hvcsd->port.count = 0;
52934+ atomic_set(&hvcsd->port.count, 0);
52935 hvcsd->port.tty = tty;
52936 tty->driver_data = hvcsd;
52937
52938@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
52939 unsigned long flags;
52940
52941 spin_lock_irqsave(&hvcsd->lock, flags);
52942- hvcsd->port.count++;
52943+ atomic_inc(&hvcsd->port.count);
52944 hvcsd->todo_mask |= HVCS_SCHED_READ;
52945 spin_unlock_irqrestore(&hvcsd->lock, flags);
52946
52947@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52948 hvcsd = tty->driver_data;
52949
52950 spin_lock_irqsave(&hvcsd->lock, flags);
52951- if (--hvcsd->port.count == 0) {
52952+ if (atomic_dec_and_test(&hvcsd->port.count)) {
52953
52954 vio_disable_interrupts(hvcsd->vdev);
52955
52956@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
52957
52958 free_irq(irq, hvcsd);
52959 return;
52960- } else if (hvcsd->port.count < 0) {
52961+ } else if (atomic_read(&hvcsd->port.count) < 0) {
52962 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
52963 " is missmanaged.\n",
52964- hvcsd->vdev->unit_address, hvcsd->port.count);
52965+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
52966 }
52967
52968 spin_unlock_irqrestore(&hvcsd->lock, flags);
52969@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52970
52971 spin_lock_irqsave(&hvcsd->lock, flags);
52972 /* Preserve this so that we know how many kref refs to put */
52973- temp_open_count = hvcsd->port.count;
52974+ temp_open_count = atomic_read(&hvcsd->port.count);
52975
52976 /*
52977 * Don't kref put inside the spinlock because the destruction
52978@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
52979 tty->driver_data = NULL;
52980 hvcsd->port.tty = NULL;
52981
52982- hvcsd->port.count = 0;
52983+ atomic_set(&hvcsd->port.count, 0);
52984
52985 /* This will drop any buffered data on the floor which is OK in a hangup
52986 * scenario. */
52987@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
52988 * the middle of a write operation? This is a crummy place to do this
52989 * but we want to keep it all in the spinlock.
52990 */
52991- if (hvcsd->port.count <= 0) {
52992+ if (atomic_read(&hvcsd->port.count) <= 0) {
52993 spin_unlock_irqrestore(&hvcsd->lock, flags);
52994 return -ENODEV;
52995 }
52996@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
52997 {
52998 struct hvcs_struct *hvcsd = tty->driver_data;
52999
53000- if (!hvcsd || hvcsd->port.count <= 0)
53001+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
53002 return 0;
53003
53004 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
53005diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
53006index 4190199..06d5bfa 100644
53007--- a/drivers/tty/hvc/hvsi.c
53008+++ b/drivers/tty/hvc/hvsi.c
53009@@ -85,7 +85,7 @@ struct hvsi_struct {
53010 int n_outbuf;
53011 uint32_t vtermno;
53012 uint32_t virq;
53013- atomic_t seqno; /* HVSI packet sequence number */
53014+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
53015 uint16_t mctrl;
53016 uint8_t state; /* HVSI protocol state */
53017 uint8_t flags;
53018@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
53019
53020 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
53021 packet.hdr.len = sizeof(struct hvsi_query_response);
53022- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53023+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53024 packet.verb = VSV_SEND_VERSION_NUMBER;
53025 packet.u.version = HVSI_VERSION;
53026 packet.query_seqno = query_seqno+1;
53027@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
53028
53029 packet.hdr.type = VS_QUERY_PACKET_HEADER;
53030 packet.hdr.len = sizeof(struct hvsi_query);
53031- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53032+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53033 packet.verb = verb;
53034
53035 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
53036@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
53037 int wrote;
53038
53039 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
53040- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53041+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53042 packet.hdr.len = sizeof(struct hvsi_control);
53043 packet.verb = VSV_SET_MODEM_CTL;
53044 packet.mask = HVSI_TSDTR;
53045@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
53046 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
53047
53048 packet.hdr.type = VS_DATA_PACKET_HEADER;
53049- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53050+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53051 packet.hdr.len = count + sizeof(struct hvsi_header);
53052 memcpy(&packet.data, buf, count);
53053
53054@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
53055 struct hvsi_control packet __ALIGNED__;
53056
53057 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
53058- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
53059+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
53060 packet.hdr.len = 6;
53061 packet.verb = VSV_CLOSE_PROTOCOL;
53062
53063@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
53064
53065 tty_port_tty_set(&hp->port, tty);
53066 spin_lock_irqsave(&hp->lock, flags);
53067- hp->port.count++;
53068+ atomic_inc(&hp->port.count);
53069 atomic_set(&hp->seqno, 0);
53070 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
53071 spin_unlock_irqrestore(&hp->lock, flags);
53072@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
53073
53074 spin_lock_irqsave(&hp->lock, flags);
53075
53076- if (--hp->port.count == 0) {
53077+ if (atomic_dec_return(&hp->port.count) == 0) {
53078 tty_port_tty_set(&hp->port, NULL);
53079 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
53080
53081@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
53082
53083 spin_lock_irqsave(&hp->lock, flags);
53084 }
53085- } else if (hp->port.count < 0)
53086+ } else if (atomic_read(&hp->port.count) < 0)
53087 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
53088- hp - hvsi_ports, hp->port.count);
53089+ hp - hvsi_ports, atomic_read(&hp->port.count));
53090
53091 spin_unlock_irqrestore(&hp->lock, flags);
53092 }
53093@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
53094 tty_port_tty_set(&hp->port, NULL);
53095
53096 spin_lock_irqsave(&hp->lock, flags);
53097- hp->port.count = 0;
53098+ atomic_set(&hp->port.count, 0);
53099 hp->n_outbuf = 0;
53100 spin_unlock_irqrestore(&hp->lock, flags);
53101 }
53102diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
53103index 7ae6c29..05c6dba 100644
53104--- a/drivers/tty/hvc/hvsi_lib.c
53105+++ b/drivers/tty/hvc/hvsi_lib.c
53106@@ -8,7 +8,7 @@
53107
53108 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
53109 {
53110- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
53111+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
53112
53113 /* Assumes that always succeeds, works in practice */
53114 return pv->put_chars(pv->termno, (char *)packet, packet->len);
53115@@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
53116
53117 /* Reset state */
53118 pv->established = 0;
53119- atomic_set(&pv->seqno, 0);
53120+ atomic_set_unchecked(&pv->seqno, 0);
53121
53122 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
53123
53124diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
53125index 345cebb..d5a1e9e 100644
53126--- a/drivers/tty/ipwireless/tty.c
53127+++ b/drivers/tty/ipwireless/tty.c
53128@@ -28,6 +28,7 @@
53129 #include <linux/tty_driver.h>
53130 #include <linux/tty_flip.h>
53131 #include <linux/uaccess.h>
53132+#include <asm/local.h>
53133
53134 #include "tty.h"
53135 #include "network.h"
53136@@ -93,10 +94,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53137 return -ENODEV;
53138
53139 mutex_lock(&tty->ipw_tty_mutex);
53140- if (tty->port.count == 0)
53141+ if (atomic_read(&tty->port.count) == 0)
53142 tty->tx_bytes_queued = 0;
53143
53144- tty->port.count++;
53145+ atomic_inc(&tty->port.count);
53146
53147 tty->port.tty = linux_tty;
53148 linux_tty->driver_data = tty;
53149@@ -112,9 +113,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
53150
53151 static void do_ipw_close(struct ipw_tty *tty)
53152 {
53153- tty->port.count--;
53154-
53155- if (tty->port.count == 0) {
53156+ if (atomic_dec_return(&tty->port.count) == 0) {
53157 struct tty_struct *linux_tty = tty->port.tty;
53158
53159 if (linux_tty != NULL) {
53160@@ -135,7 +134,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
53161 return;
53162
53163 mutex_lock(&tty->ipw_tty_mutex);
53164- if (tty->port.count == 0) {
53165+ if (atomic_read(&tty->port.count) == 0) {
53166 mutex_unlock(&tty->ipw_tty_mutex);
53167 return;
53168 }
53169@@ -158,7 +157,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
53170
53171 mutex_lock(&tty->ipw_tty_mutex);
53172
53173- if (!tty->port.count) {
53174+ if (!atomic_read(&tty->port.count)) {
53175 mutex_unlock(&tty->ipw_tty_mutex);
53176 return;
53177 }
53178@@ -197,7 +196,7 @@ static int ipw_write(struct tty_struct *linux_tty,
53179 return -ENODEV;
53180
53181 mutex_lock(&tty->ipw_tty_mutex);
53182- if (!tty->port.count) {
53183+ if (!atomic_read(&tty->port.count)) {
53184 mutex_unlock(&tty->ipw_tty_mutex);
53185 return -EINVAL;
53186 }
53187@@ -237,7 +236,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
53188 if (!tty)
53189 return -ENODEV;
53190
53191- if (!tty->port.count)
53192+ if (!atomic_read(&tty->port.count))
53193 return -EINVAL;
53194
53195 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
53196@@ -279,7 +278,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
53197 if (!tty)
53198 return 0;
53199
53200- if (!tty->port.count)
53201+ if (!atomic_read(&tty->port.count))
53202 return 0;
53203
53204 return tty->tx_bytes_queued;
53205@@ -360,7 +359,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
53206 if (!tty)
53207 return -ENODEV;
53208
53209- if (!tty->port.count)
53210+ if (!atomic_read(&tty->port.count))
53211 return -EINVAL;
53212
53213 return get_control_lines(tty);
53214@@ -376,7 +375,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
53215 if (!tty)
53216 return -ENODEV;
53217
53218- if (!tty->port.count)
53219+ if (!atomic_read(&tty->port.count))
53220 return -EINVAL;
53221
53222 return set_control_lines(tty, set, clear);
53223@@ -390,7 +389,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
53224 if (!tty)
53225 return -ENODEV;
53226
53227- if (!tty->port.count)
53228+ if (!atomic_read(&tty->port.count))
53229 return -EINVAL;
53230
53231 /* FIXME: Exactly how is the tty object locked here .. */
53232@@ -546,7 +545,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
53233 * are gone */
53234 mutex_lock(&ttyj->ipw_tty_mutex);
53235 }
53236- while (ttyj->port.count)
53237+ while (atomic_read(&ttyj->port.count))
53238 do_ipw_close(ttyj);
53239 ipwireless_disassociate_network_ttys(network,
53240 ttyj->channel_idx);
53241diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
53242index 1deaca4..c8582d4 100644
53243--- a/drivers/tty/moxa.c
53244+++ b/drivers/tty/moxa.c
53245@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
53246 }
53247
53248 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
53249- ch->port.count++;
53250+ atomic_inc(&ch->port.count);
53251 tty->driver_data = ch;
53252 tty_port_tty_set(&ch->port, tty);
53253 mutex_lock(&ch->port.mutex);
53254diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
53255index c434376..114ce13 100644
53256--- a/drivers/tty/n_gsm.c
53257+++ b/drivers/tty/n_gsm.c
53258@@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
53259 spin_lock_init(&dlci->lock);
53260 mutex_init(&dlci->mutex);
53261 dlci->fifo = &dlci->_fifo;
53262- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
53263+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
53264 kfree(dlci);
53265 return NULL;
53266 }
53267@@ -2958,7 +2958,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
53268 struct gsm_dlci *dlci = tty->driver_data;
53269 struct tty_port *port = &dlci->port;
53270
53271- port->count++;
53272+ atomic_inc(&port->count);
53273 tty_port_tty_set(port, tty);
53274
53275 dlci->modem_rx = 0;
53276diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
53277index f44f1ba..a8d5915 100644
53278--- a/drivers/tty/n_tty.c
53279+++ b/drivers/tty/n_tty.c
53280@@ -115,7 +115,7 @@ struct n_tty_data {
53281 int minimum_to_wake;
53282
53283 /* consumer-published */
53284- size_t read_tail;
53285+ size_t read_tail __intentional_overflow(-1);
53286 size_t line_start;
53287
53288 /* protected by output lock */
53289@@ -2517,6 +2517,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
53290 {
53291 *ops = tty_ldisc_N_TTY;
53292 ops->owner = NULL;
53293- ops->refcount = ops->flags = 0;
53294+ atomic_set(&ops->refcount, 0);
53295+ ops->flags = 0;
53296 }
53297 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
53298diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
53299index 9bbdb1d..dc514ee 100644
53300--- a/drivers/tty/pty.c
53301+++ b/drivers/tty/pty.c
53302@@ -789,8 +789,10 @@ static void __init unix98_pty_init(void)
53303 panic("Couldn't register Unix98 pts driver");
53304
53305 /* Now create the /dev/ptmx special device */
53306+ pax_open_kernel();
53307 tty_default_fops(&ptmx_fops);
53308- ptmx_fops.open = ptmx_open;
53309+ *(void **)&ptmx_fops.open = ptmx_open;
53310+ pax_close_kernel();
53311
53312 cdev_init(&ptmx_cdev, &ptmx_fops);
53313 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
53314diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
53315index 383c4c7..d408e21 100644
53316--- a/drivers/tty/rocket.c
53317+++ b/drivers/tty/rocket.c
53318@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53319 tty->driver_data = info;
53320 tty_port_tty_set(port, tty);
53321
53322- if (port->count++ == 0) {
53323+ if (atomic_inc_return(&port->count) == 1) {
53324 atomic_inc(&rp_num_ports_open);
53325
53326 #ifdef ROCKET_DEBUG_OPEN
53327@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
53328 #endif
53329 }
53330 #ifdef ROCKET_DEBUG_OPEN
53331- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
53332+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
53333 #endif
53334
53335 /*
53336@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
53337 spin_unlock_irqrestore(&info->port.lock, flags);
53338 return;
53339 }
53340- if (info->port.count)
53341+ if (atomic_read(&info->port.count))
53342 atomic_dec(&rp_num_ports_open);
53343 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
53344 spin_unlock_irqrestore(&info->port.lock, flags);
53345diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
53346index aa28209..e08fb85 100644
53347--- a/drivers/tty/serial/ioc4_serial.c
53348+++ b/drivers/tty/serial/ioc4_serial.c
53349@@ -437,7 +437,7 @@ struct ioc4_soft {
53350 } is_intr_info[MAX_IOC4_INTR_ENTS];
53351
53352 /* Number of entries active in the above array */
53353- atomic_t is_num_intrs;
53354+ atomic_unchecked_t is_num_intrs;
53355 } is_intr_type[IOC4_NUM_INTR_TYPES];
53356
53357 /* is_ir_lock must be held while
53358@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
53359 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
53360 || (type == IOC4_OTHER_INTR_TYPE)));
53361
53362- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
53363+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
53364 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
53365
53366 /* Save off the lower level interrupt handler */
53367@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
53368
53369 soft = arg;
53370 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
53371- num_intrs = (int)atomic_read(
53372+ num_intrs = (int)atomic_read_unchecked(
53373 &soft->is_intr_type[intr_type].is_num_intrs);
53374
53375 this_mir = this_ir = pending_intrs(soft, intr_type);
53376diff --git a/drivers/tty/serial/kgdb_nmi.c b/drivers/tty/serial/kgdb_nmi.c
53377index 6ec7501..265bcbf 100644
53378--- a/drivers/tty/serial/kgdb_nmi.c
53379+++ b/drivers/tty/serial/kgdb_nmi.c
53380@@ -51,7 +51,9 @@ static int kgdb_nmi_console_setup(struct console *co, char *options)
53381 * I/O utilities that messages sent to the console will automatically
53382 * be displayed on the dbg_io.
53383 */
53384- dbg_io_ops->is_console = true;
53385+ pax_open_kernel();
53386+ *(int *)&dbg_io_ops->is_console = true;
53387+ pax_close_kernel();
53388
53389 return 0;
53390 }
53391diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
53392index a260cde..6b2b5ce 100644
53393--- a/drivers/tty/serial/kgdboc.c
53394+++ b/drivers/tty/serial/kgdboc.c
53395@@ -24,8 +24,9 @@
53396 #define MAX_CONFIG_LEN 40
53397
53398 static struct kgdb_io kgdboc_io_ops;
53399+static struct kgdb_io kgdboc_io_ops_console;
53400
53401-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
53402+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
53403 static int configured = -1;
53404
53405 static char config[MAX_CONFIG_LEN];
53406@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
53407 kgdboc_unregister_kbd();
53408 if (configured == 1)
53409 kgdb_unregister_io_module(&kgdboc_io_ops);
53410+ else if (configured == 2)
53411+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
53412 }
53413
53414 static int configure_kgdboc(void)
53415@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
53416 int err;
53417 char *cptr = config;
53418 struct console *cons;
53419+ int is_console = 0;
53420
53421 err = kgdboc_option_setup(config);
53422 if (err || !strlen(config) || isspace(config[0]))
53423 goto noconfig;
53424
53425 err = -ENODEV;
53426- kgdboc_io_ops.is_console = 0;
53427 kgdb_tty_driver = NULL;
53428
53429 kgdboc_use_kms = 0;
53430@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
53431 int idx;
53432 if (cons->device && cons->device(cons, &idx) == p &&
53433 idx == tty_line) {
53434- kgdboc_io_ops.is_console = 1;
53435+ is_console = 1;
53436 break;
53437 }
53438 cons = cons->next;
53439@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
53440 kgdb_tty_line = tty_line;
53441
53442 do_register:
53443- err = kgdb_register_io_module(&kgdboc_io_ops);
53444+ if (is_console) {
53445+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
53446+ configured = 2;
53447+ } else {
53448+ err = kgdb_register_io_module(&kgdboc_io_ops);
53449+ configured = 1;
53450+ }
53451 if (err)
53452 goto noconfig;
53453
53454@@ -205,8 +214,6 @@ do_register:
53455 if (err)
53456 goto nmi_con_failed;
53457
53458- configured = 1;
53459-
53460 return 0;
53461
53462 nmi_con_failed:
53463@@ -223,7 +230,7 @@ noconfig:
53464 static int __init init_kgdboc(void)
53465 {
53466 /* Already configured? */
53467- if (configured == 1)
53468+ if (configured >= 1)
53469 return 0;
53470
53471 return configure_kgdboc();
53472@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
53473 if (config[len - 1] == '\n')
53474 config[len - 1] = '\0';
53475
53476- if (configured == 1)
53477+ if (configured >= 1)
53478 cleanup_kgdboc();
53479
53480 /* Go and configure with the new params. */
53481@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
53482 .post_exception = kgdboc_post_exp_handler,
53483 };
53484
53485+static struct kgdb_io kgdboc_io_ops_console = {
53486+ .name = "kgdboc",
53487+ .read_char = kgdboc_get_char,
53488+ .write_char = kgdboc_put_char,
53489+ .pre_exception = kgdboc_pre_exp_handler,
53490+ .post_exception = kgdboc_post_exp_handler,
53491+ .is_console = 1
53492+};
53493+
53494 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
53495 /* This is only available if kgdboc is a built in for early debugging */
53496 static int __init kgdboc_early_init(char *opt)
53497diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
53498index 077570a..12550a9 100644
53499--- a/drivers/tty/serial/msm_serial.c
53500+++ b/drivers/tty/serial/msm_serial.c
53501@@ -981,7 +981,7 @@ static struct uart_driver msm_uart_driver = {
53502 .cons = MSM_CONSOLE,
53503 };
53504
53505-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
53506+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
53507
53508 static const struct of_device_id msm_uartdm_table[] = {
53509 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
53510@@ -1000,7 +1000,7 @@ static int msm_serial_probe(struct platform_device *pdev)
53511 int irq;
53512
53513 if (pdev->id == -1)
53514- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
53515+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
53516
53517 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
53518 return -ENXIO;
53519diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
53520index c78f43a..22b1dab 100644
53521--- a/drivers/tty/serial/samsung.c
53522+++ b/drivers/tty/serial/samsung.c
53523@@ -478,11 +478,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
53524 }
53525 }
53526
53527+static int s3c64xx_serial_startup(struct uart_port *port);
53528 static int s3c24xx_serial_startup(struct uart_port *port)
53529 {
53530 struct s3c24xx_uart_port *ourport = to_ourport(port);
53531 int ret;
53532
53533+ /* Startup sequence is different for s3c64xx and higher SoC's */
53534+ if (s3c24xx_serial_has_interrupt_mask(port))
53535+ return s3c64xx_serial_startup(port);
53536+
53537 dbg("s3c24xx_serial_startup: port=%p (%08llx,%p)\n",
53538 port, (unsigned long long)port->mapbase, port->membase);
53539
53540@@ -1155,10 +1160,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
53541 /* setup info for port */
53542 port->dev = &platdev->dev;
53543
53544- /* Startup sequence is different for s3c64xx and higher SoC's */
53545- if (s3c24xx_serial_has_interrupt_mask(port))
53546- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
53547-
53548 port->uartclk = 1;
53549
53550 if (cfg->uart_flags & UPF_CONS_FLOW) {
53551diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
53552index 0f03988..8a8038d 100644
53553--- a/drivers/tty/serial/serial_core.c
53554+++ b/drivers/tty/serial/serial_core.c
53555@@ -1343,7 +1343,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
53556
53557 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
53558
53559- if (!port->count || tty_port_close_start(port, tty, filp) == 0)
53560+ if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
53561 return;
53562
53563 /*
53564@@ -1470,7 +1470,7 @@ static void uart_hangup(struct tty_struct *tty)
53565 uart_flush_buffer(tty);
53566 uart_shutdown(tty, state);
53567 spin_lock_irqsave(&port->lock, flags);
53568- port->count = 0;
53569+ atomic_set(&port->count, 0);
53570 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
53571 spin_unlock_irqrestore(&port->lock, flags);
53572 tty_port_tty_set(port, NULL);
53573@@ -1568,7 +1568,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53574 goto end;
53575 }
53576
53577- port->count++;
53578+ atomic_inc(&port->count);
53579 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
53580 retval = -ENXIO;
53581 goto err_dec_count;
53582@@ -1600,7 +1600,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
53583 end:
53584 return retval;
53585 err_dec_count:
53586- port->count--;
53587+ atomic_inc(&port->count);
53588 mutex_unlock(&port->mutex);
53589 goto end;
53590 }
53591diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
53592index b799170..87dafd5 100644
53593--- a/drivers/tty/synclink.c
53594+++ b/drivers/tty/synclink.c
53595@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53596
53597 if (debug_level >= DEBUG_LEVEL_INFO)
53598 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
53599- __FILE__,__LINE__, info->device_name, info->port.count);
53600+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53601
53602 if (tty_port_close_start(&info->port, tty, filp) == 0)
53603 goto cleanup;
53604@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
53605 cleanup:
53606 if (debug_level >= DEBUG_LEVEL_INFO)
53607 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
53608- tty->driver->name, info->port.count);
53609+ tty->driver->name, atomic_read(&info->port.count));
53610
53611 } /* end of mgsl_close() */
53612
53613@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
53614
53615 mgsl_flush_buffer(tty);
53616 shutdown(info);
53617-
53618- info->port.count = 0;
53619+
53620+ atomic_set(&info->port.count, 0);
53621 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53622 info->port.tty = NULL;
53623
53624@@ -3296,10 +3296,10 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53625
53626 if (debug_level >= DEBUG_LEVEL_INFO)
53627 printk("%s(%d):block_til_ready before block on %s count=%d\n",
53628- __FILE__,__LINE__, tty->driver->name, port->count );
53629+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53630
53631 spin_lock_irqsave(&info->irq_spinlock, flags);
53632- port->count--;
53633+ atomic_dec(&port->count);
53634 spin_unlock_irqrestore(&info->irq_spinlock, flags);
53635 port->blocked_open++;
53636
53637@@ -3327,7 +3327,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53638
53639 if (debug_level >= DEBUG_LEVEL_INFO)
53640 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
53641- __FILE__,__LINE__, tty->driver->name, port->count );
53642+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53643
53644 tty_unlock(tty);
53645 schedule();
53646@@ -3339,12 +3339,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
53647
53648 /* FIXME: Racy on hangup during close wait */
53649 if (!tty_hung_up_p(filp))
53650- port->count++;
53651+ atomic_inc(&port->count);
53652 port->blocked_open--;
53653
53654 if (debug_level >= DEBUG_LEVEL_INFO)
53655 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
53656- __FILE__,__LINE__, tty->driver->name, port->count );
53657+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53658
53659 if (!retval)
53660 port->flags |= ASYNC_NORMAL_ACTIVE;
53661@@ -3396,7 +3396,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53662
53663 if (debug_level >= DEBUG_LEVEL_INFO)
53664 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
53665- __FILE__,__LINE__,tty->driver->name, info->port.count);
53666+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53667
53668 /* If port is closing, signal caller to try again */
53669 if (info->port.flags & ASYNC_CLOSING){
53670@@ -3415,10 +3415,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
53671 spin_unlock_irqrestore(&info->netlock, flags);
53672 goto cleanup;
53673 }
53674- info->port.count++;
53675+ atomic_inc(&info->port.count);
53676 spin_unlock_irqrestore(&info->netlock, flags);
53677
53678- if (info->port.count == 1) {
53679+ if (atomic_read(&info->port.count) == 1) {
53680 /* 1st open on this device, init hardware */
53681 retval = startup(info);
53682 if (retval < 0)
53683@@ -3442,8 +3442,8 @@ cleanup:
53684 if (retval) {
53685 if (tty->count == 1)
53686 info->port.tty = NULL; /* tty layer will release tty struct */
53687- if(info->port.count)
53688- info->port.count--;
53689+ if (atomic_read(&info->port.count))
53690+ atomic_dec(&info->port.count);
53691 }
53692
53693 return retval;
53694@@ -7661,7 +7661,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53695 unsigned short new_crctype;
53696
53697 /* return error if TTY interface open */
53698- if (info->port.count)
53699+ if (atomic_read(&info->port.count))
53700 return -EBUSY;
53701
53702 switch (encoding)
53703@@ -7756,7 +7756,7 @@ static int hdlcdev_open(struct net_device *dev)
53704
53705 /* arbitrate between network and tty opens */
53706 spin_lock_irqsave(&info->netlock, flags);
53707- if (info->port.count != 0 || info->netcount != 0) {
53708+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53709 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53710 spin_unlock_irqrestore(&info->netlock, flags);
53711 return -EBUSY;
53712@@ -7842,7 +7842,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53713 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53714
53715 /* return error if TTY interface open */
53716- if (info->port.count)
53717+ if (atomic_read(&info->port.count))
53718 return -EBUSY;
53719
53720 if (cmd != SIOCWANDEV)
53721diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
53722index 0e8c39b..e0cb171 100644
53723--- a/drivers/tty/synclink_gt.c
53724+++ b/drivers/tty/synclink_gt.c
53725@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53726 tty->driver_data = info;
53727 info->port.tty = tty;
53728
53729- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
53730+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
53731
53732 /* If port is closing, signal caller to try again */
53733 if (info->port.flags & ASYNC_CLOSING){
53734@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53735 mutex_unlock(&info->port.mutex);
53736 goto cleanup;
53737 }
53738- info->port.count++;
53739+ atomic_inc(&info->port.count);
53740 spin_unlock_irqrestore(&info->netlock, flags);
53741
53742- if (info->port.count == 1) {
53743+ if (atomic_read(&info->port.count) == 1) {
53744 /* 1st open on this device, init hardware */
53745 retval = startup(info);
53746 if (retval < 0) {
53747@@ -715,8 +715,8 @@ cleanup:
53748 if (retval) {
53749 if (tty->count == 1)
53750 info->port.tty = NULL; /* tty layer will release tty struct */
53751- if(info->port.count)
53752- info->port.count--;
53753+ if(atomic_read(&info->port.count))
53754+ atomic_dec(&info->port.count);
53755 }
53756
53757 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
53758@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53759
53760 if (sanity_check(info, tty->name, "close"))
53761 return;
53762- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
53763+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
53764
53765 if (tty_port_close_start(&info->port, tty, filp) == 0)
53766 goto cleanup;
53767@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53768 tty_port_close_end(&info->port, tty);
53769 info->port.tty = NULL;
53770 cleanup:
53771- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
53772+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
53773 }
53774
53775 static void hangup(struct tty_struct *tty)
53776@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
53777 shutdown(info);
53778
53779 spin_lock_irqsave(&info->port.lock, flags);
53780- info->port.count = 0;
53781+ atomic_set(&info->port.count, 0);
53782 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53783 info->port.tty = NULL;
53784 spin_unlock_irqrestore(&info->port.lock, flags);
53785@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53786 unsigned short new_crctype;
53787
53788 /* return error if TTY interface open */
53789- if (info->port.count)
53790+ if (atomic_read(&info->port.count))
53791 return -EBUSY;
53792
53793 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
53794@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
53795
53796 /* arbitrate between network and tty opens */
53797 spin_lock_irqsave(&info->netlock, flags);
53798- if (info->port.count != 0 || info->netcount != 0) {
53799+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53800 DBGINFO(("%s hdlc_open busy\n", dev->name));
53801 spin_unlock_irqrestore(&info->netlock, flags);
53802 return -EBUSY;
53803@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53804 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
53805
53806 /* return error if TTY interface open */
53807- if (info->port.count)
53808+ if (atomic_read(&info->port.count))
53809 return -EBUSY;
53810
53811 if (cmd != SIOCWANDEV)
53812@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
53813 if (port == NULL)
53814 continue;
53815 spin_lock(&port->lock);
53816- if ((port->port.count || port->netcount) &&
53817+ if ((atomic_read(&port->port.count) || port->netcount) &&
53818 port->pending_bh && !port->bh_running &&
53819 !port->bh_requested) {
53820 DBGISR(("%s bh queued\n", port->device_name));
53821@@ -3299,7 +3299,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53822 add_wait_queue(&port->open_wait, &wait);
53823
53824 spin_lock_irqsave(&info->lock, flags);
53825- port->count--;
53826+ atomic_dec(&port->count);
53827 spin_unlock_irqrestore(&info->lock, flags);
53828 port->blocked_open++;
53829
53830@@ -3335,7 +3335,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53831 remove_wait_queue(&port->open_wait, &wait);
53832
53833 if (!tty_hung_up_p(filp))
53834- port->count++;
53835+ atomic_inc(&port->count);
53836 port->blocked_open--;
53837
53838 if (!retval)
53839diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
53840index c3f9091..abe4601 100644
53841--- a/drivers/tty/synclinkmp.c
53842+++ b/drivers/tty/synclinkmp.c
53843@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
53844
53845 if (debug_level >= DEBUG_LEVEL_INFO)
53846 printk("%s(%d):%s open(), old ref count = %d\n",
53847- __FILE__,__LINE__,tty->driver->name, info->port.count);
53848+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
53849
53850 /* If port is closing, signal caller to try again */
53851 if (info->port.flags & ASYNC_CLOSING){
53852@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
53853 spin_unlock_irqrestore(&info->netlock, flags);
53854 goto cleanup;
53855 }
53856- info->port.count++;
53857+ atomic_inc(&info->port.count);
53858 spin_unlock_irqrestore(&info->netlock, flags);
53859
53860- if (info->port.count == 1) {
53861+ if (atomic_read(&info->port.count) == 1) {
53862 /* 1st open on this device, init hardware */
53863 retval = startup(info);
53864 if (retval < 0)
53865@@ -796,8 +796,8 @@ cleanup:
53866 if (retval) {
53867 if (tty->count == 1)
53868 info->port.tty = NULL; /* tty layer will release tty struct */
53869- if(info->port.count)
53870- info->port.count--;
53871+ if(atomic_read(&info->port.count))
53872+ atomic_dec(&info->port.count);
53873 }
53874
53875 return retval;
53876@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53877
53878 if (debug_level >= DEBUG_LEVEL_INFO)
53879 printk("%s(%d):%s close() entry, count=%d\n",
53880- __FILE__,__LINE__, info->device_name, info->port.count);
53881+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
53882
53883 if (tty_port_close_start(&info->port, tty, filp) == 0)
53884 goto cleanup;
53885@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
53886 cleanup:
53887 if (debug_level >= DEBUG_LEVEL_INFO)
53888 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
53889- tty->driver->name, info->port.count);
53890+ tty->driver->name, atomic_read(&info->port.count));
53891 }
53892
53893 /* Called by tty_hangup() when a hangup is signaled.
53894@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
53895 shutdown(info);
53896
53897 spin_lock_irqsave(&info->port.lock, flags);
53898- info->port.count = 0;
53899+ atomic_set(&info->port.count, 0);
53900 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
53901 info->port.tty = NULL;
53902 spin_unlock_irqrestore(&info->port.lock, flags);
53903@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
53904 unsigned short new_crctype;
53905
53906 /* return error if TTY interface open */
53907- if (info->port.count)
53908+ if (atomic_read(&info->port.count))
53909 return -EBUSY;
53910
53911 switch (encoding)
53912@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
53913
53914 /* arbitrate between network and tty opens */
53915 spin_lock_irqsave(&info->netlock, flags);
53916- if (info->port.count != 0 || info->netcount != 0) {
53917+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
53918 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
53919 spin_unlock_irqrestore(&info->netlock, flags);
53920 return -EBUSY;
53921@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
53922 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
53923
53924 /* return error if TTY interface open */
53925- if (info->port.count)
53926+ if (atomic_read(&info->port.count))
53927 return -EBUSY;
53928
53929 if (cmd != SIOCWANDEV)
53930@@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
53931 * do not request bottom half processing if the
53932 * device is not open in a normal mode.
53933 */
53934- if ( port && (port->port.count || port->netcount) &&
53935+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
53936 port->pending_bh && !port->bh_running &&
53937 !port->bh_requested ) {
53938 if ( debug_level >= DEBUG_LEVEL_ISR )
53939@@ -3318,10 +3318,10 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53940
53941 if (debug_level >= DEBUG_LEVEL_INFO)
53942 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
53943- __FILE__,__LINE__, tty->driver->name, port->count );
53944+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53945
53946 spin_lock_irqsave(&info->lock, flags);
53947- port->count--;
53948+ atomic_dec(&port->count);
53949 spin_unlock_irqrestore(&info->lock, flags);
53950 port->blocked_open++;
53951
53952@@ -3349,7 +3349,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53953
53954 if (debug_level >= DEBUG_LEVEL_INFO)
53955 printk("%s(%d):%s block_til_ready() count=%d\n",
53956- __FILE__,__LINE__, tty->driver->name, port->count );
53957+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53958
53959 tty_unlock(tty);
53960 schedule();
53961@@ -3359,12 +3359,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
53962 set_current_state(TASK_RUNNING);
53963 remove_wait_queue(&port->open_wait, &wait);
53964 if (!tty_hung_up_p(filp))
53965- port->count++;
53966+ atomic_inc(&port->count);
53967 port->blocked_open--;
53968
53969 if (debug_level >= DEBUG_LEVEL_INFO)
53970 printk("%s(%d):%s block_til_ready() after, count=%d\n",
53971- __FILE__,__LINE__, tty->driver->name, port->count );
53972+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
53973
53974 if (!retval)
53975 port->flags |= ASYNC_NORMAL_ACTIVE;
53976diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
53977index 42bad18..447d7a2 100644
53978--- a/drivers/tty/sysrq.c
53979+++ b/drivers/tty/sysrq.c
53980@@ -1084,7 +1084,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
53981 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
53982 size_t count, loff_t *ppos)
53983 {
53984- if (count) {
53985+ if (count && capable(CAP_SYS_ADMIN)) {
53986 char c;
53987
53988 if (get_user(c, buf))
53989diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
53990index 848c17a..e930437 100644
53991--- a/drivers/tty/tty_io.c
53992+++ b/drivers/tty/tty_io.c
53993@@ -3469,7 +3469,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
53994
53995 void tty_default_fops(struct file_operations *fops)
53996 {
53997- *fops = tty_fops;
53998+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
53999 }
54000
54001 /*
54002diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
54003index 2d822aa..a566234 100644
54004--- a/drivers/tty/tty_ldisc.c
54005+++ b/drivers/tty/tty_ldisc.c
54006@@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
54007 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54008 tty_ldiscs[disc] = new_ldisc;
54009 new_ldisc->num = disc;
54010- new_ldisc->refcount = 0;
54011+ atomic_set(&new_ldisc->refcount, 0);
54012 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
54013
54014 return ret;
54015@@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
54016 return -EINVAL;
54017
54018 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54019- if (tty_ldiscs[disc]->refcount)
54020+ if (atomic_read(&tty_ldiscs[disc]->refcount))
54021 ret = -EBUSY;
54022 else
54023 tty_ldiscs[disc] = NULL;
54024@@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
54025 if (ldops) {
54026 ret = ERR_PTR(-EAGAIN);
54027 if (try_module_get(ldops->owner)) {
54028- ldops->refcount++;
54029+ atomic_inc(&ldops->refcount);
54030 ret = ldops;
54031 }
54032 }
54033@@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
54034 unsigned long flags;
54035
54036 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
54037- ldops->refcount--;
54038+ atomic_dec(&ldops->refcount);
54039 module_put(ldops->owner);
54040 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
54041 }
54042diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
54043index 1b93357..ea9f82c 100644
54044--- a/drivers/tty/tty_port.c
54045+++ b/drivers/tty/tty_port.c
54046@@ -237,7 +237,7 @@ void tty_port_hangup(struct tty_port *port)
54047 unsigned long flags;
54048
54049 spin_lock_irqsave(&port->lock, flags);
54050- port->count = 0;
54051+ atomic_set(&port->count, 0);
54052 port->flags &= ~ASYNC_NORMAL_ACTIVE;
54053 tty = port->tty;
54054 if (tty)
54055@@ -399,7 +399,7 @@ int tty_port_block_til_ready(struct tty_port *port,
54056
54057 /* The port lock protects the port counts */
54058 spin_lock_irqsave(&port->lock, flags);
54059- port->count--;
54060+ atomic_dec(&port->count);
54061 port->blocked_open++;
54062 spin_unlock_irqrestore(&port->lock, flags);
54063
54064@@ -441,7 +441,7 @@ int tty_port_block_til_ready(struct tty_port *port,
54065 we must not mess that up further */
54066 spin_lock_irqsave(&port->lock, flags);
54067 if (!tty_hung_up_p(filp))
54068- port->count++;
54069+ atomic_inc(&port->count);
54070 port->blocked_open--;
54071 if (retval == 0)
54072 port->flags |= ASYNC_NORMAL_ACTIVE;
54073@@ -479,19 +479,19 @@ int tty_port_close_start(struct tty_port *port,
54074 return 0;
54075 }
54076
54077- if (tty->count == 1 && port->count != 1) {
54078+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
54079 printk(KERN_WARNING
54080 "tty_port_close_start: tty->count = 1 port count = %d.\n",
54081- port->count);
54082- port->count = 1;
54083+ atomic_read(&port->count));
54084+ atomic_set(&port->count, 1);
54085 }
54086- if (--port->count < 0) {
54087+ if (atomic_dec_return(&port->count) < 0) {
54088 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
54089- port->count);
54090- port->count = 0;
54091+ atomic_read(&port->count));
54092+ atomic_set(&port->count, 0);
54093 }
54094
54095- if (port->count) {
54096+ if (atomic_read(&port->count)) {
54097 spin_unlock_irqrestore(&port->lock, flags);
54098 return 0;
54099 }
54100@@ -592,7 +592,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
54101 struct file *filp)
54102 {
54103 spin_lock_irq(&port->lock);
54104- ++port->count;
54105+ atomic_inc(&port->count);
54106 spin_unlock_irq(&port->lock);
54107 tty_port_tty_set(port, tty);
54108
54109diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
54110index d0e3a44..5f8b754 100644
54111--- a/drivers/tty/vt/keyboard.c
54112+++ b/drivers/tty/vt/keyboard.c
54113@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
54114 kbd->kbdmode == VC_OFF) &&
54115 value != KVAL(K_SAK))
54116 return; /* SAK is allowed even in raw mode */
54117+
54118+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54119+ {
54120+ void *func = fn_handler[value];
54121+ if (func == fn_show_state || func == fn_show_ptregs ||
54122+ func == fn_show_mem)
54123+ return;
54124+ }
54125+#endif
54126+
54127 fn_handler[value](vc);
54128 }
54129
54130@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54131 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
54132 return -EFAULT;
54133
54134- if (!capable(CAP_SYS_TTY_CONFIG))
54135- perm = 0;
54136-
54137 switch (cmd) {
54138 case KDGKBENT:
54139 /* Ensure another thread doesn't free it under us */
54140@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
54141 spin_unlock_irqrestore(&kbd_event_lock, flags);
54142 return put_user(val, &user_kbe->kb_value);
54143 case KDSKBENT:
54144+ if (!capable(CAP_SYS_TTY_CONFIG))
54145+ perm = 0;
54146+
54147 if (!perm)
54148 return -EPERM;
54149 if (!i && v == K_NOSUCHMAP) {
54150@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54151 int i, j, k;
54152 int ret;
54153
54154- if (!capable(CAP_SYS_TTY_CONFIG))
54155- perm = 0;
54156-
54157 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
54158 if (!kbs) {
54159 ret = -ENOMEM;
54160@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
54161 kfree(kbs);
54162 return ((p && *p) ? -EOVERFLOW : 0);
54163 case KDSKBSENT:
54164+ if (!capable(CAP_SYS_TTY_CONFIG))
54165+ perm = 0;
54166+
54167 if (!perm) {
54168 ret = -EPERM;
54169 goto reterr;
54170diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
54171index a673e5b..36e5d32 100644
54172--- a/drivers/uio/uio.c
54173+++ b/drivers/uio/uio.c
54174@@ -25,6 +25,7 @@
54175 #include <linux/kobject.h>
54176 #include <linux/cdev.h>
54177 #include <linux/uio_driver.h>
54178+#include <asm/local.h>
54179
54180 #define UIO_MAX_DEVICES (1U << MINORBITS)
54181
54182@@ -32,7 +33,7 @@ struct uio_device {
54183 struct module *owner;
54184 struct device *dev;
54185 int minor;
54186- atomic_t event;
54187+ atomic_unchecked_t event;
54188 struct fasync_struct *async_queue;
54189 wait_queue_head_t wait;
54190 struct uio_info *info;
54191@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
54192 struct device_attribute *attr, char *buf)
54193 {
54194 struct uio_device *idev = dev_get_drvdata(dev);
54195- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
54196+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
54197 }
54198 static DEVICE_ATTR_RO(event);
54199
54200@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
54201 {
54202 struct uio_device *idev = info->uio_dev;
54203
54204- atomic_inc(&idev->event);
54205+ atomic_inc_unchecked(&idev->event);
54206 wake_up_interruptible(&idev->wait);
54207 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
54208 }
54209@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
54210 }
54211
54212 listener->dev = idev;
54213- listener->event_count = atomic_read(&idev->event);
54214+ listener->event_count = atomic_read_unchecked(&idev->event);
54215 filep->private_data = listener;
54216
54217 if (idev->info->open) {
54218@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
54219 return -EIO;
54220
54221 poll_wait(filep, &idev->wait, wait);
54222- if (listener->event_count != atomic_read(&idev->event))
54223+ if (listener->event_count != atomic_read_unchecked(&idev->event))
54224 return POLLIN | POLLRDNORM;
54225 return 0;
54226 }
54227@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
54228 do {
54229 set_current_state(TASK_INTERRUPTIBLE);
54230
54231- event_count = atomic_read(&idev->event);
54232+ event_count = atomic_read_unchecked(&idev->event);
54233 if (event_count != listener->event_count) {
54234 if (copy_to_user(buf, &event_count, count))
54235 retval = -EFAULT;
54236@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
54237 static int uio_find_mem_index(struct vm_area_struct *vma)
54238 {
54239 struct uio_device *idev = vma->vm_private_data;
54240+ unsigned long size;
54241
54242 if (vma->vm_pgoff < MAX_UIO_MAPS) {
54243- if (idev->info->mem[vma->vm_pgoff].size == 0)
54244+ size = idev->info->mem[vma->vm_pgoff].size;
54245+ if (size == 0)
54246+ return -1;
54247+ if (vma->vm_end - vma->vm_start > size)
54248 return -1;
54249 return (int)vma->vm_pgoff;
54250 }
54251@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
54252 idev->owner = owner;
54253 idev->info = info;
54254 init_waitqueue_head(&idev->wait);
54255- atomic_set(&idev->event, 0);
54256+ atomic_set_unchecked(&idev->event, 0);
54257
54258 ret = uio_get_minor(idev);
54259 if (ret)
54260diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
54261index 813d4d3..a71934f 100644
54262--- a/drivers/usb/atm/cxacru.c
54263+++ b/drivers/usb/atm/cxacru.c
54264@@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
54265 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
54266 if (ret < 2)
54267 return -EINVAL;
54268- if (index < 0 || index > 0x7f)
54269+ if (index > 0x7f)
54270 return -EINVAL;
54271 pos += tmp;
54272
54273diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
54274index dada014..1d0d517 100644
54275--- a/drivers/usb/atm/usbatm.c
54276+++ b/drivers/usb/atm/usbatm.c
54277@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54278 if (printk_ratelimit())
54279 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
54280 __func__, vpi, vci);
54281- atomic_inc(&vcc->stats->rx_err);
54282+ atomic_inc_unchecked(&vcc->stats->rx_err);
54283 return;
54284 }
54285
54286@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54287 if (length > ATM_MAX_AAL5_PDU) {
54288 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
54289 __func__, length, vcc);
54290- atomic_inc(&vcc->stats->rx_err);
54291+ atomic_inc_unchecked(&vcc->stats->rx_err);
54292 goto out;
54293 }
54294
54295@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54296 if (sarb->len < pdu_length) {
54297 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
54298 __func__, pdu_length, sarb->len, vcc);
54299- atomic_inc(&vcc->stats->rx_err);
54300+ atomic_inc_unchecked(&vcc->stats->rx_err);
54301 goto out;
54302 }
54303
54304 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
54305 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
54306 __func__, vcc);
54307- atomic_inc(&vcc->stats->rx_err);
54308+ atomic_inc_unchecked(&vcc->stats->rx_err);
54309 goto out;
54310 }
54311
54312@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54313 if (printk_ratelimit())
54314 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
54315 __func__, length);
54316- atomic_inc(&vcc->stats->rx_drop);
54317+ atomic_inc_unchecked(&vcc->stats->rx_drop);
54318 goto out;
54319 }
54320
54321@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
54322
54323 vcc->push(vcc, skb);
54324
54325- atomic_inc(&vcc->stats->rx);
54326+ atomic_inc_unchecked(&vcc->stats->rx);
54327 out:
54328 skb_trim(sarb, 0);
54329 }
54330@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
54331 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
54332
54333 usbatm_pop(vcc, skb);
54334- atomic_inc(&vcc->stats->tx);
54335+ atomic_inc_unchecked(&vcc->stats->tx);
54336
54337 skb = skb_dequeue(&instance->sndqueue);
54338 }
54339@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
54340 if (!left--)
54341 return sprintf(page,
54342 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
54343- atomic_read(&atm_dev->stats.aal5.tx),
54344- atomic_read(&atm_dev->stats.aal5.tx_err),
54345- atomic_read(&atm_dev->stats.aal5.rx),
54346- atomic_read(&atm_dev->stats.aal5.rx_err),
54347- atomic_read(&atm_dev->stats.aal5.rx_drop));
54348+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
54349+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
54350+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
54351+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
54352+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
54353
54354 if (!left--) {
54355 if (instance->disconnected)
54356diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
54357index 2a3bbdf..91d72cf 100644
54358--- a/drivers/usb/core/devices.c
54359+++ b/drivers/usb/core/devices.c
54360@@ -126,7 +126,7 @@ static const char format_endpt[] =
54361 * time it gets called.
54362 */
54363 static struct device_connect_event {
54364- atomic_t count;
54365+ atomic_unchecked_t count;
54366 wait_queue_head_t wait;
54367 } device_event = {
54368 .count = ATOMIC_INIT(1),
54369@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
54370
54371 void usbfs_conn_disc_event(void)
54372 {
54373- atomic_add(2, &device_event.count);
54374+ atomic_add_unchecked(2, &device_event.count);
54375 wake_up(&device_event.wait);
54376 }
54377
54378@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
54379
54380 poll_wait(file, &device_event.wait, wait);
54381
54382- event_count = atomic_read(&device_event.count);
54383+ event_count = atomic_read_unchecked(&device_event.count);
54384 if (file->f_version != event_count) {
54385 file->f_version = event_count;
54386 return POLLIN | POLLRDNORM;
54387diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
54388index 0b59731..46ee7d1 100644
54389--- a/drivers/usb/core/devio.c
54390+++ b/drivers/usb/core/devio.c
54391@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54392 struct usb_dev_state *ps = file->private_data;
54393 struct usb_device *dev = ps->dev;
54394 ssize_t ret = 0;
54395- unsigned len;
54396+ size_t len;
54397 loff_t pos;
54398 int i;
54399
54400@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
54401 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
54402 struct usb_config_descriptor *config =
54403 (struct usb_config_descriptor *)dev->rawdescriptors[i];
54404- unsigned int length = le16_to_cpu(config->wTotalLength);
54405+ size_t length = le16_to_cpu(config->wTotalLength);
54406
54407 if (*ppos < pos + length) {
54408
54409 /* The descriptor may claim to be longer than it
54410 * really is. Here is the actual allocated length. */
54411- unsigned alloclen =
54412+ size_t alloclen =
54413 le16_to_cpu(dev->config[i].desc.wTotalLength);
54414
54415- len = length - (*ppos - pos);
54416+ len = length + pos - *ppos;
54417 if (len > nbytes)
54418 len = nbytes;
54419
54420 /* Simply don't write (skip over) unallocated parts */
54421 if (alloclen > (*ppos - pos)) {
54422- alloclen -= (*ppos - pos);
54423+ alloclen = alloclen + pos - *ppos;
54424 if (copy_to_user(buf,
54425 dev->rawdescriptors[i] + (*ppos - pos),
54426 min(len, alloclen))) {
54427diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
54428index 258e6fe..9ea48d7 100644
54429--- a/drivers/usb/core/hcd.c
54430+++ b/drivers/usb/core/hcd.c
54431@@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54432 */
54433 usb_get_urb(urb);
54434 atomic_inc(&urb->use_count);
54435- atomic_inc(&urb->dev->urbnum);
54436+ atomic_inc_unchecked(&urb->dev->urbnum);
54437 usbmon_urb_submit(&hcd->self, urb);
54438
54439 /* NOTE requirements on root-hub callers (usbfs and the hub
54440@@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
54441 urb->hcpriv = NULL;
54442 INIT_LIST_HEAD(&urb->urb_list);
54443 atomic_dec(&urb->use_count);
54444- atomic_dec(&urb->dev->urbnum);
54445+ atomic_dec_unchecked(&urb->dev->urbnum);
54446 if (atomic_read(&urb->reject))
54447 wake_up(&usb_kill_urb_queue);
54448 usb_put_urb(urb);
54449diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
54450index 674c262..71fdd90 100644
54451--- a/drivers/usb/core/hub.c
54452+++ b/drivers/usb/core/hub.c
54453@@ -27,6 +27,7 @@
54454 #include <linux/freezer.h>
54455 #include <linux/random.h>
54456 #include <linux/pm_qos.h>
54457+#include <linux/grsecurity.h>
54458
54459 #include <asm/uaccess.h>
54460 #include <asm/byteorder.h>
54461@@ -4665,6 +4666,10 @@ static void hub_port_connect(struct usb_hub *hub, int port1, u16 portstatus,
54462 goto done;
54463 return;
54464 }
54465+
54466+ if (gr_handle_new_usb())
54467+ goto done;
54468+
54469 if (hub_is_superspeed(hub->hdev))
54470 unit_load = 150;
54471 else
54472diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
54473index 0c8a7fc..c45b40a 100644
54474--- a/drivers/usb/core/message.c
54475+++ b/drivers/usb/core/message.c
54476@@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
54477 * Return: If successful, the number of bytes transferred. Otherwise, a negative
54478 * error number.
54479 */
54480-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54481+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
54482 __u8 requesttype, __u16 value, __u16 index, void *data,
54483 __u16 size, int timeout)
54484 {
54485@@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
54486 * If successful, 0. Otherwise a negative error number. The number of actual
54487 * bytes transferred will be stored in the @actual_length parameter.
54488 */
54489-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54490+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
54491 void *data, int len, int *actual_length, int timeout)
54492 {
54493 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
54494@@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
54495 * bytes transferred will be stored in the @actual_length parameter.
54496 *
54497 */
54498-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54499+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
54500 void *data, int len, int *actual_length, int timeout)
54501 {
54502 struct urb *urb;
54503diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
54504index 1236c60..d47a51c 100644
54505--- a/drivers/usb/core/sysfs.c
54506+++ b/drivers/usb/core/sysfs.c
54507@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
54508 struct usb_device *udev;
54509
54510 udev = to_usb_device(dev);
54511- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
54512+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
54513 }
54514 static DEVICE_ATTR_RO(urbnum);
54515
54516diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
54517index 2dd2362..1135437 100644
54518--- a/drivers/usb/core/usb.c
54519+++ b/drivers/usb/core/usb.c
54520@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
54521 set_dev_node(&dev->dev, dev_to_node(bus->controller));
54522 dev->state = USB_STATE_ATTACHED;
54523 dev->lpm_disable_count = 1;
54524- atomic_set(&dev->urbnum, 0);
54525+ atomic_set_unchecked(&dev->urbnum, 0);
54526
54527 INIT_LIST_HEAD(&dev->ep0.urb_list);
54528 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
54529diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
54530index 8cfc319..4868255 100644
54531--- a/drivers/usb/early/ehci-dbgp.c
54532+++ b/drivers/usb/early/ehci-dbgp.c
54533@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
54534
54535 #ifdef CONFIG_KGDB
54536 static struct kgdb_io kgdbdbgp_io_ops;
54537-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
54538+static struct kgdb_io kgdbdbgp_io_ops_console;
54539+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
54540 #else
54541 #define dbgp_kgdb_mode (0)
54542 #endif
54543@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
54544 .write_char = kgdbdbgp_write_char,
54545 };
54546
54547+static struct kgdb_io kgdbdbgp_io_ops_console = {
54548+ .name = "kgdbdbgp",
54549+ .read_char = kgdbdbgp_read_char,
54550+ .write_char = kgdbdbgp_write_char,
54551+ .is_console = 1
54552+};
54553+
54554 static int kgdbdbgp_wait_time;
54555
54556 static int __init kgdbdbgp_parse_config(char *str)
54557@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
54558 ptr++;
54559 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
54560 }
54561- kgdb_register_io_module(&kgdbdbgp_io_ops);
54562- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
54563+ if (early_dbgp_console.index != -1)
54564+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
54565+ else
54566+ kgdb_register_io_module(&kgdbdbgp_io_ops);
54567
54568 return 0;
54569 }
54570diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
54571index 2b4c82d..06a8ee6 100644
54572--- a/drivers/usb/gadget/function/f_uac1.c
54573+++ b/drivers/usb/gadget/function/f_uac1.c
54574@@ -13,6 +13,7 @@
54575 #include <linux/kernel.h>
54576 #include <linux/device.h>
54577 #include <linux/atomic.h>
54578+#include <linux/module.h>
54579
54580 #include "u_uac1.h"
54581
54582diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
54583index ad0aca8..8ff84865 100644
54584--- a/drivers/usb/gadget/function/u_serial.c
54585+++ b/drivers/usb/gadget/function/u_serial.c
54586@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54587 spin_lock_irq(&port->port_lock);
54588
54589 /* already open? Great. */
54590- if (port->port.count) {
54591+ if (atomic_read(&port->port.count)) {
54592 status = 0;
54593- port->port.count++;
54594+ atomic_inc(&port->port.count);
54595
54596 /* currently opening/closing? wait ... */
54597 } else if (port->openclose) {
54598@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
54599 tty->driver_data = port;
54600 port->port.tty = tty;
54601
54602- port->port.count = 1;
54603+ atomic_set(&port->port.count, 1);
54604 port->openclose = false;
54605
54606 /* if connected, start the I/O stream */
54607@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54608
54609 spin_lock_irq(&port->port_lock);
54610
54611- if (port->port.count != 1) {
54612- if (port->port.count == 0)
54613+ if (atomic_read(&port->port.count) != 1) {
54614+ if (atomic_read(&port->port.count) == 0)
54615 WARN_ON(1);
54616 else
54617- --port->port.count;
54618+ atomic_dec(&port->port.count);
54619 goto exit;
54620 }
54621
54622@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
54623 * and sleep if necessary
54624 */
54625 port->openclose = true;
54626- port->port.count = 0;
54627+ atomic_set(&port->port.count, 0);
54628
54629 gser = port->port_usb;
54630 if (gser && gser->disconnect)
54631@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
54632 int cond;
54633
54634 spin_lock_irq(&port->port_lock);
54635- cond = (port->port.count == 0) && !port->openclose;
54636+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
54637 spin_unlock_irq(&port->port_lock);
54638 return cond;
54639 }
54640@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
54641 /* if it's already open, start I/O ... and notify the serial
54642 * protocol about open/close status (connect/disconnect).
54643 */
54644- if (port->port.count) {
54645+ if (atomic_read(&port->port.count)) {
54646 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
54647 gs_start_io(port);
54648 if (gser->connect)
54649@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
54650
54651 port->port_usb = NULL;
54652 gser->ioport = NULL;
54653- if (port->port.count > 0 || port->openclose) {
54654+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
54655 wake_up_interruptible(&port->drain_wait);
54656 if (port->port.tty)
54657 tty_hangup(port->port.tty);
54658@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
54659
54660 /* finally, free any unused/unusable I/O buffers */
54661 spin_lock_irqsave(&port->port_lock, flags);
54662- if (port->port.count == 0 && !port->openclose)
54663+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
54664 gs_buf_free(&port->port_write_buf);
54665 gs_free_requests(gser->out, &port->read_pool, NULL);
54666 gs_free_requests(gser->out, &port->read_queue, NULL);
54667diff --git a/drivers/usb/gadget/function/u_uac1.c b/drivers/usb/gadget/function/u_uac1.c
54668index 7a55fea..cc0ed4f 100644
54669--- a/drivers/usb/gadget/function/u_uac1.c
54670+++ b/drivers/usb/gadget/function/u_uac1.c
54671@@ -16,6 +16,7 @@
54672 #include <linux/ctype.h>
54673 #include <linux/random.h>
54674 #include <linux/syscalls.h>
54675+#include <linux/module.h>
54676
54677 #include "u_uac1.h"
54678
54679diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
54680index 6130b75..3b60008 100644
54681--- a/drivers/usb/host/ehci-hub.c
54682+++ b/drivers/usb/host/ehci-hub.c
54683@@ -771,7 +771,7 @@ static struct urb *request_single_step_set_feature_urb(
54684 urb->transfer_flags = URB_DIR_IN;
54685 usb_get_urb(urb);
54686 atomic_inc(&urb->use_count);
54687- atomic_inc(&urb->dev->urbnum);
54688+ atomic_inc_unchecked(&urb->dev->urbnum);
54689 urb->setup_dma = dma_map_single(
54690 hcd->self.controller,
54691 urb->setup_packet,
54692@@ -838,7 +838,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
54693 urb->status = -EINPROGRESS;
54694 usb_get_urb(urb);
54695 atomic_inc(&urb->use_count);
54696- atomic_inc(&urb->dev->urbnum);
54697+ atomic_inc_unchecked(&urb->dev->urbnum);
54698 retval = submit_single_step_set_feature(hcd, urb, 0);
54699 if (!retval && !wait_for_completion_timeout(&done,
54700 msecs_to_jiffies(2000))) {
54701diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
54702index d0d8fad..668ef7b 100644
54703--- a/drivers/usb/host/hwa-hc.c
54704+++ b/drivers/usb/host/hwa-hc.c
54705@@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54706 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
54707 struct wahc *wa = &hwahc->wa;
54708 struct device *dev = &wa->usb_iface->dev;
54709- u8 mas_le[UWB_NUM_MAS/8];
54710+ u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
54711+
54712+ if (mas_le == NULL)
54713+ return -ENOMEM;
54714
54715 /* Set the stream index */
54716 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
54717@@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
54718 WUSB_REQ_SET_WUSB_MAS,
54719 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
54720 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
54721- mas_le, 32, USB_CTRL_SET_TIMEOUT);
54722+ mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
54723 if (result < 0)
54724 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
54725 out:
54726+ kfree(mas_le);
54727+
54728 return result;
54729 }
54730
54731diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
54732index b3d245e..99549ed 100644
54733--- a/drivers/usb/misc/appledisplay.c
54734+++ b/drivers/usb/misc/appledisplay.c
54735@@ -84,7 +84,7 @@ struct appledisplay {
54736 struct mutex sysfslock; /* concurrent read and write */
54737 };
54738
54739-static atomic_t count_displays = ATOMIC_INIT(0);
54740+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
54741 static struct workqueue_struct *wq;
54742
54743 static void appledisplay_complete(struct urb *urb)
54744@@ -288,7 +288,7 @@ static int appledisplay_probe(struct usb_interface *iface,
54745
54746 /* Register backlight device */
54747 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
54748- atomic_inc_return(&count_displays) - 1);
54749+ atomic_inc_return_unchecked(&count_displays) - 1);
54750 memset(&props, 0, sizeof(struct backlight_properties));
54751 props.type = BACKLIGHT_RAW;
54752 props.max_brightness = 0xff;
54753diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
54754index 8d7fc48..01c4986 100644
54755--- a/drivers/usb/serial/console.c
54756+++ b/drivers/usb/serial/console.c
54757@@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
54758
54759 info->port = port;
54760
54761- ++port->port.count;
54762+ atomic_inc(&port->port.count);
54763 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
54764 if (serial->type->set_termios) {
54765 /*
54766@@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
54767 }
54768 /* Now that any required fake tty operations are completed restore
54769 * the tty port count */
54770- --port->port.count;
54771+ atomic_dec(&port->port.count);
54772 /* The console is special in terms of closing the device so
54773 * indicate this port is now acting as a system console. */
54774 port->port.console = 1;
54775@@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
54776 free_tty:
54777 kfree(tty);
54778 reset_open_count:
54779- port->port.count = 0;
54780+ atomic_set(&port->port.count, 0);
54781 usb_autopm_put_interface(serial->interface);
54782 error_get_interface:
54783 usb_serial_put(serial);
54784@@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
54785 static void usb_console_write(struct console *co,
54786 const char *buf, unsigned count)
54787 {
54788- static struct usbcons_info *info = &usbcons_info;
54789+ struct usbcons_info *info = &usbcons_info;
54790 struct usb_serial_port *port = info->port;
54791 struct usb_serial *serial;
54792 int retval = -ENODEV;
54793diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
54794index 307e339..6aa97cb 100644
54795--- a/drivers/usb/storage/usb.h
54796+++ b/drivers/usb/storage/usb.h
54797@@ -63,7 +63,7 @@ struct us_unusual_dev {
54798 __u8 useProtocol;
54799 __u8 useTransport;
54800 int (*initFunction)(struct us_data *);
54801-};
54802+} __do_const;
54803
54804
54805 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
54806diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
54807index a863a98..d272795 100644
54808--- a/drivers/usb/usbip/vhci.h
54809+++ b/drivers/usb/usbip/vhci.h
54810@@ -83,7 +83,7 @@ struct vhci_hcd {
54811 unsigned resuming:1;
54812 unsigned long re_timeout;
54813
54814- atomic_t seqnum;
54815+ atomic_unchecked_t seqnum;
54816
54817 /*
54818 * NOTE:
54819diff --git a/drivers/usb/usbip/vhci_hcd.c b/drivers/usb/usbip/vhci_hcd.c
54820index c02374b..32d47a9 100644
54821--- a/drivers/usb/usbip/vhci_hcd.c
54822+++ b/drivers/usb/usbip/vhci_hcd.c
54823@@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
54824
54825 spin_lock(&vdev->priv_lock);
54826
54827- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
54828+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54829 if (priv->seqnum == 0xffff)
54830 dev_info(&urb->dev->dev, "seqnum max\n");
54831
54832@@ -686,7 +686,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
54833 return -ENOMEM;
54834 }
54835
54836- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
54837+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
54838 if (unlink->seqnum == 0xffff)
54839 pr_info("seqnum max\n");
54840
54841@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
54842 vdev->rhport = rhport;
54843 }
54844
54845- atomic_set(&vhci->seqnum, 0);
54846+ atomic_set_unchecked(&vhci->seqnum, 0);
54847 spin_lock_init(&vhci->lock);
54848
54849 hcd->power_budget = 0; /* no limit */
54850diff --git a/drivers/usb/usbip/vhci_rx.c b/drivers/usb/usbip/vhci_rx.c
54851index 00e4a54..d676f85 100644
54852--- a/drivers/usb/usbip/vhci_rx.c
54853+++ b/drivers/usb/usbip/vhci_rx.c
54854@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
54855 if (!urb) {
54856 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
54857 pr_info("max seqnum %d\n",
54858- atomic_read(&the_controller->seqnum));
54859+ atomic_read_unchecked(&the_controller->seqnum));
54860 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
54861 return;
54862 }
54863diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
54864index f2a8d29..7bc3fe7 100644
54865--- a/drivers/usb/wusbcore/wa-hc.h
54866+++ b/drivers/usb/wusbcore/wa-hc.h
54867@@ -240,7 +240,7 @@ struct wahc {
54868 spinlock_t xfer_list_lock;
54869 struct work_struct xfer_enqueue_work;
54870 struct work_struct xfer_error_work;
54871- atomic_t xfer_id_count;
54872+ atomic_unchecked_t xfer_id_count;
54873
54874 kernel_ulong_t quirks;
54875 };
54876@@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
54877 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
54878 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
54879 wa->dto_in_use = 0;
54880- atomic_set(&wa->xfer_id_count, 1);
54881+ atomic_set_unchecked(&wa->xfer_id_count, 1);
54882 /* init the buf in URBs */
54883 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
54884 usb_init_urb(&(wa->buf_in_urbs[index]));
54885diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
54886index e279015..c2d0dae 100644
54887--- a/drivers/usb/wusbcore/wa-xfer.c
54888+++ b/drivers/usb/wusbcore/wa-xfer.c
54889@@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
54890 */
54891 static void wa_xfer_id_init(struct wa_xfer *xfer)
54892 {
54893- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
54894+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
54895 }
54896
54897 /* Return the xfer's ID. */
54898diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
54899index f018d8d..ccab63f 100644
54900--- a/drivers/vfio/vfio.c
54901+++ b/drivers/vfio/vfio.c
54902@@ -481,7 +481,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
54903 return 0;
54904
54905 /* TODO Prevent device auto probing */
54906- WARN("Device %s added to live group %d!\n", dev_name(dev),
54907+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
54908 iommu_group_id(group->iommu_group));
54909
54910 return 0;
54911diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
54912index 5174eba..451e6bc 100644
54913--- a/drivers/vhost/vringh.c
54914+++ b/drivers/vhost/vringh.c
54915@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
54916 /* Userspace access helpers: in this case, addresses are really userspace. */
54917 static inline int getu16_user(u16 *val, const u16 *p)
54918 {
54919- return get_user(*val, (__force u16 __user *)p);
54920+ return get_user(*val, (u16 __force_user *)p);
54921 }
54922
54923 static inline int putu16_user(u16 *p, u16 val)
54924 {
54925- return put_user(val, (__force u16 __user *)p);
54926+ return put_user(val, (u16 __force_user *)p);
54927 }
54928
54929 static inline int copydesc_user(void *dst, const void *src, size_t len)
54930 {
54931- return copy_from_user(dst, (__force void __user *)src, len) ?
54932+ return copy_from_user(dst, (void __force_user *)src, len) ?
54933 -EFAULT : 0;
54934 }
54935
54936@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
54937 const struct vring_used_elem *src,
54938 unsigned int num)
54939 {
54940- return copy_to_user((__force void __user *)dst, src,
54941+ return copy_to_user((void __force_user *)dst, src,
54942 sizeof(*dst) * num) ? -EFAULT : 0;
54943 }
54944
54945 static inline int xfer_from_user(void *src, void *dst, size_t len)
54946 {
54947- return copy_from_user(dst, (__force void __user *)src, len) ?
54948+ return copy_from_user(dst, (void __force_user *)src, len) ?
54949 -EFAULT : 0;
54950 }
54951
54952 static inline int xfer_to_user(void *dst, void *src, size_t len)
54953 {
54954- return copy_to_user((__force void __user *)dst, src, len) ?
54955+ return copy_to_user((void __force_user *)dst, src, len) ?
54956 -EFAULT : 0;
54957 }
54958
54959@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
54960 vrh->last_used_idx = 0;
54961 vrh->vring.num = num;
54962 /* vring expects kernel addresses, but only used via accessors. */
54963- vrh->vring.desc = (__force struct vring_desc *)desc;
54964- vrh->vring.avail = (__force struct vring_avail *)avail;
54965- vrh->vring.used = (__force struct vring_used *)used;
54966+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
54967+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
54968+ vrh->vring.used = (__force_kernel struct vring_used *)used;
54969 return 0;
54970 }
54971 EXPORT_SYMBOL(vringh_init_user);
54972@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
54973
54974 static inline int putu16_kern(u16 *p, u16 val)
54975 {
54976- ACCESS_ONCE(*p) = val;
54977+ ACCESS_ONCE_RW(*p) = val;
54978 return 0;
54979 }
54980
54981diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
54982index 84a110a..96312c3 100644
54983--- a/drivers/video/backlight/kb3886_bl.c
54984+++ b/drivers/video/backlight/kb3886_bl.c
54985@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
54986 static unsigned long kb3886bl_flags;
54987 #define KB3886BL_SUSPENDED 0x01
54988
54989-static struct dmi_system_id kb3886bl_device_table[] __initdata = {
54990+static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
54991 {
54992 .ident = "Sahara Touch-iT",
54993 .matches = {
54994diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
54995index 1b0b233..6f34c2c 100644
54996--- a/drivers/video/fbdev/arcfb.c
54997+++ b/drivers/video/fbdev/arcfb.c
54998@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
54999 return -ENOSPC;
55000
55001 err = 0;
55002- if ((count + p) > fbmemlength) {
55003+ if (count > (fbmemlength - p)) {
55004 count = fbmemlength - p;
55005 err = -ENOSPC;
55006 }
55007diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
55008index ff60701..814b973 100644
55009--- a/drivers/video/fbdev/aty/aty128fb.c
55010+++ b/drivers/video/fbdev/aty/aty128fb.c
55011@@ -149,7 +149,7 @@ enum {
55012 };
55013
55014 /* Must match above enum */
55015-static char * const r128_family[] = {
55016+static const char * const r128_family[] = {
55017 "AGP",
55018 "PCI",
55019 "PRO AGP",
55020diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
55021index 37ec09b..98f8862 100644
55022--- a/drivers/video/fbdev/aty/atyfb_base.c
55023+++ b/drivers/video/fbdev/aty/atyfb_base.c
55024@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
55025 par->accel_flags = var->accel_flags; /* hack */
55026
55027 if (var->accel_flags) {
55028- info->fbops->fb_sync = atyfb_sync;
55029+ pax_open_kernel();
55030+ *(void **)&info->fbops->fb_sync = atyfb_sync;
55031+ pax_close_kernel();
55032 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55033 } else {
55034- info->fbops->fb_sync = NULL;
55035+ pax_open_kernel();
55036+ *(void **)&info->fbops->fb_sync = NULL;
55037+ pax_close_kernel();
55038 info->flags |= FBINFO_HWACCEL_DISABLED;
55039 }
55040
55041diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
55042index 2fa0317..4983f2a 100644
55043--- a/drivers/video/fbdev/aty/mach64_cursor.c
55044+++ b/drivers/video/fbdev/aty/mach64_cursor.c
55045@@ -8,6 +8,7 @@
55046 #include "../core/fb_draw.h"
55047
55048 #include <asm/io.h>
55049+#include <asm/pgtable.h>
55050
55051 #ifdef __sparc__
55052 #include <asm/fbio.h>
55053@@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
55054 info->sprite.buf_align = 16; /* and 64 lines tall. */
55055 info->sprite.flags = FB_PIXMAP_IO;
55056
55057- info->fbops->fb_cursor = atyfb_cursor;
55058+ pax_open_kernel();
55059+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
55060+ pax_close_kernel();
55061
55062 return 0;
55063 }
55064diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
55065index 900aa4e..6d49418 100644
55066--- a/drivers/video/fbdev/core/fb_defio.c
55067+++ b/drivers/video/fbdev/core/fb_defio.c
55068@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
55069
55070 BUG_ON(!fbdefio);
55071 mutex_init(&fbdefio->lock);
55072- info->fbops->fb_mmap = fb_deferred_io_mmap;
55073+ pax_open_kernel();
55074+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
55075+ pax_close_kernel();
55076 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
55077 INIT_LIST_HEAD(&fbdefio->pagelist);
55078 if (fbdefio->delay == 0) /* set a default of 1 s */
55079@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
55080 page->mapping = NULL;
55081 }
55082
55083- info->fbops->fb_mmap = NULL;
55084+ *(void **)&info->fbops->fb_mmap = NULL;
55085 mutex_destroy(&fbdefio->lock);
55086 }
55087 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
55088diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
55089index b5e85f6..290f8c7 100644
55090--- a/drivers/video/fbdev/core/fbmem.c
55091+++ b/drivers/video/fbdev/core/fbmem.c
55092@@ -1301,7 +1301,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
55093 __u32 data;
55094 int err;
55095
55096- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
55097+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
55098
55099 data = (__u32) (unsigned long) fix->smem_start;
55100 err |= put_user(data, &fix32->smem_start);
55101diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
55102index 4254336..282567e 100644
55103--- a/drivers/video/fbdev/hyperv_fb.c
55104+++ b/drivers/video/fbdev/hyperv_fb.c
55105@@ -240,7 +240,7 @@ static uint screen_fb_size;
55106 static inline int synthvid_send(struct hv_device *hdev,
55107 struct synthvid_msg *msg)
55108 {
55109- static atomic64_t request_id = ATOMIC64_INIT(0);
55110+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
55111 int ret;
55112
55113 msg->pipe_hdr.type = PIPE_MSG_DATA;
55114@@ -248,7 +248,7 @@ static inline int synthvid_send(struct hv_device *hdev,
55115
55116 ret = vmbus_sendpacket(hdev->channel, msg,
55117 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
55118- atomic64_inc_return(&request_id),
55119+ atomic64_inc_return_unchecked(&request_id),
55120 VM_PKT_DATA_INBAND, 0);
55121
55122 if (ret)
55123diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
55124index 7672d2e..b56437f 100644
55125--- a/drivers/video/fbdev/i810/i810_accel.c
55126+++ b/drivers/video/fbdev/i810/i810_accel.c
55127@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
55128 }
55129 }
55130 printk("ringbuffer lockup!!!\n");
55131+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
55132 i810_report_error(mmio);
55133 par->dev_flags |= LOCKUP;
55134 info->pixmap.scan_align = 1;
55135diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55136index a01147f..5d896f8 100644
55137--- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55138+++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
55139@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55140
55141 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55142 struct matrox_switch matrox_mystique = {
55143- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55144+ .preinit = MGA1064_preinit,
55145+ .reset = MGA1064_reset,
55146+ .init = MGA1064_init,
55147+ .restore = MGA1064_restore,
55148 };
55149 EXPORT_SYMBOL(matrox_mystique);
55150 #endif
55151
55152 #ifdef CONFIG_FB_MATROX_G
55153 struct matrox_switch matrox_G100 = {
55154- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55155+ .preinit = MGAG100_preinit,
55156+ .reset = MGAG100_reset,
55157+ .init = MGAG100_init,
55158+ .restore = MGAG100_restore,
55159 };
55160 EXPORT_SYMBOL(matrox_G100);
55161 #endif
55162diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55163index 195ad7c..09743fc 100644
55164--- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55165+++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
55166@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55167 }
55168
55169 struct matrox_switch matrox_millennium = {
55170- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55171+ .preinit = Ti3026_preinit,
55172+ .reset = Ti3026_reset,
55173+ .init = Ti3026_init,
55174+ .restore = Ti3026_restore
55175 };
55176 EXPORT_SYMBOL(matrox_millennium);
55177 #endif
55178diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55179index fe92eed..106e085 100644
55180--- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55181+++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
55182@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55183 struct mb862xxfb_par *par = info->par;
55184
55185 if (info->var.bits_per_pixel == 32) {
55186- info->fbops->fb_fillrect = cfb_fillrect;
55187- info->fbops->fb_copyarea = cfb_copyarea;
55188- info->fbops->fb_imageblit = cfb_imageblit;
55189+ pax_open_kernel();
55190+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55191+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55192+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55193+ pax_close_kernel();
55194 } else {
55195 outreg(disp, GC_L0EM, 3);
55196- info->fbops->fb_fillrect = mb86290fb_fillrect;
55197- info->fbops->fb_copyarea = mb86290fb_copyarea;
55198- info->fbops->fb_imageblit = mb86290fb_imageblit;
55199+ pax_open_kernel();
55200+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55201+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55202+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55203+ pax_close_kernel();
55204 }
55205 outreg(draw, GDC_REG_DRAW_BASE, 0);
55206 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55207diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
55208index def0412..fed6529 100644
55209--- a/drivers/video/fbdev/nvidia/nvidia.c
55210+++ b/drivers/video/fbdev/nvidia/nvidia.c
55211@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55212 info->fix.line_length = (info->var.xres_virtual *
55213 info->var.bits_per_pixel) >> 3;
55214 if (info->var.accel_flags) {
55215- info->fbops->fb_imageblit = nvidiafb_imageblit;
55216- info->fbops->fb_fillrect = nvidiafb_fillrect;
55217- info->fbops->fb_copyarea = nvidiafb_copyarea;
55218- info->fbops->fb_sync = nvidiafb_sync;
55219+ pax_open_kernel();
55220+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55221+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55222+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55223+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55224+ pax_close_kernel();
55225 info->pixmap.scan_align = 4;
55226 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55227 info->flags |= FBINFO_READS_FAST;
55228 NVResetGraphics(info);
55229 } else {
55230- info->fbops->fb_imageblit = cfb_imageblit;
55231- info->fbops->fb_fillrect = cfb_fillrect;
55232- info->fbops->fb_copyarea = cfb_copyarea;
55233- info->fbops->fb_sync = NULL;
55234+ pax_open_kernel();
55235+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55236+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55237+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55238+ *(void **)&info->fbops->fb_sync = NULL;
55239+ pax_close_kernel();
55240 info->pixmap.scan_align = 1;
55241 info->flags |= FBINFO_HWACCEL_DISABLED;
55242 info->flags &= ~FBINFO_READS_FAST;
55243@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55244 info->pixmap.size = 8 * 1024;
55245 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55246
55247- if (!hwcur)
55248- info->fbops->fb_cursor = NULL;
55249+ if (!hwcur) {
55250+ pax_open_kernel();
55251+ *(void **)&info->fbops->fb_cursor = NULL;
55252+ pax_close_kernel();
55253+ }
55254
55255 info->var.accel_flags = (!noaccel);
55256
55257diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
55258index 2412a0d..294215b 100644
55259--- a/drivers/video/fbdev/omap2/dss/display.c
55260+++ b/drivers/video/fbdev/omap2/dss/display.c
55261@@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55262 if (dssdev->name == NULL)
55263 dssdev->name = dssdev->alias;
55264
55265+ pax_open_kernel();
55266 if (drv && drv->get_resolution == NULL)
55267- drv->get_resolution = omapdss_default_get_resolution;
55268+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55269 if (drv && drv->get_recommended_bpp == NULL)
55270- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55271+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55272 if (drv && drv->get_timings == NULL)
55273- drv->get_timings = omapdss_default_get_timings;
55274+ *(void **)&drv->get_timings = omapdss_default_get_timings;
55275+ pax_close_kernel();
55276
55277 mutex_lock(&panel_list_mutex);
55278 list_add_tail(&dssdev->panel_list, &panel_list);
55279diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
55280index 83433cb..71e9b98 100644
55281--- a/drivers/video/fbdev/s1d13xxxfb.c
55282+++ b/drivers/video/fbdev/s1d13xxxfb.c
55283@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55284
55285 switch(prod_id) {
55286 case S1D13506_PROD_ID: /* activate acceleration */
55287- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55288- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55289+ pax_open_kernel();
55290+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55291+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55292+ pax_close_kernel();
55293 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55294 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55295 break;
55296diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55297index 2bcc84a..29dd1ea 100644
55298--- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
55299+++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
55300@@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
55301 }
55302
55303 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
55304- lcdc_sys_write_index,
55305- lcdc_sys_write_data,
55306- lcdc_sys_read_data,
55307+ .write_index = lcdc_sys_write_index,
55308+ .write_data = lcdc_sys_write_data,
55309+ .read_data = lcdc_sys_read_data,
55310 };
55311
55312 static int sh_mobile_lcdc_sginit(struct fb_info *info,
55313diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
55314index d513ed6..90b0de9 100644
55315--- a/drivers/video/fbdev/smscufx.c
55316+++ b/drivers/video/fbdev/smscufx.c
55317@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55318 fb_deferred_io_cleanup(info);
55319 kfree(info->fbdefio);
55320 info->fbdefio = NULL;
55321- info->fbops->fb_mmap = ufx_ops_mmap;
55322+ pax_open_kernel();
55323+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55324+ pax_close_kernel();
55325 }
55326
55327 pr_debug("released /dev/fb%d user=%d count=%d",
55328diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
55329index 77b890e..458e666 100644
55330--- a/drivers/video/fbdev/udlfb.c
55331+++ b/drivers/video/fbdev/udlfb.c
55332@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55333 dlfb_urb_completion(urb);
55334
55335 error:
55336- atomic_add(bytes_sent, &dev->bytes_sent);
55337- atomic_add(bytes_identical, &dev->bytes_identical);
55338- atomic_add(width*height*2, &dev->bytes_rendered);
55339+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55340+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55341+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55342 end_cycles = get_cycles();
55343- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55344+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55345 >> 10)), /* Kcycles */
55346 &dev->cpu_kcycles_used);
55347
55348@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55349 dlfb_urb_completion(urb);
55350
55351 error:
55352- atomic_add(bytes_sent, &dev->bytes_sent);
55353- atomic_add(bytes_identical, &dev->bytes_identical);
55354- atomic_add(bytes_rendered, &dev->bytes_rendered);
55355+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55356+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55357+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55358 end_cycles = get_cycles();
55359- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55360+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55361 >> 10)), /* Kcycles */
55362 &dev->cpu_kcycles_used);
55363 }
55364@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55365 fb_deferred_io_cleanup(info);
55366 kfree(info->fbdefio);
55367 info->fbdefio = NULL;
55368- info->fbops->fb_mmap = dlfb_ops_mmap;
55369+ pax_open_kernel();
55370+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55371+ pax_close_kernel();
55372 }
55373
55374 pr_warn("released /dev/fb%d user=%d count=%d\n",
55375@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55376 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55377 struct dlfb_data *dev = fb_info->par;
55378 return snprintf(buf, PAGE_SIZE, "%u\n",
55379- atomic_read(&dev->bytes_rendered));
55380+ atomic_read_unchecked(&dev->bytes_rendered));
55381 }
55382
55383 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55384@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55385 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55386 struct dlfb_data *dev = fb_info->par;
55387 return snprintf(buf, PAGE_SIZE, "%u\n",
55388- atomic_read(&dev->bytes_identical));
55389+ atomic_read_unchecked(&dev->bytes_identical));
55390 }
55391
55392 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55393@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55394 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55395 struct dlfb_data *dev = fb_info->par;
55396 return snprintf(buf, PAGE_SIZE, "%u\n",
55397- atomic_read(&dev->bytes_sent));
55398+ atomic_read_unchecked(&dev->bytes_sent));
55399 }
55400
55401 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55402@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55403 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55404 struct dlfb_data *dev = fb_info->par;
55405 return snprintf(buf, PAGE_SIZE, "%u\n",
55406- atomic_read(&dev->cpu_kcycles_used));
55407+ atomic_read_unchecked(&dev->cpu_kcycles_used));
55408 }
55409
55410 static ssize_t edid_show(
55411@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55412 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55413 struct dlfb_data *dev = fb_info->par;
55414
55415- atomic_set(&dev->bytes_rendered, 0);
55416- atomic_set(&dev->bytes_identical, 0);
55417- atomic_set(&dev->bytes_sent, 0);
55418- atomic_set(&dev->cpu_kcycles_used, 0);
55419+ atomic_set_unchecked(&dev->bytes_rendered, 0);
55420+ atomic_set_unchecked(&dev->bytes_identical, 0);
55421+ atomic_set_unchecked(&dev->bytes_sent, 0);
55422+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55423
55424 return count;
55425 }
55426diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
55427index 509d452..7c9d2de 100644
55428--- a/drivers/video/fbdev/uvesafb.c
55429+++ b/drivers/video/fbdev/uvesafb.c
55430@@ -19,6 +19,7 @@
55431 #include <linux/io.h>
55432 #include <linux/mutex.h>
55433 #include <linux/slab.h>
55434+#include <linux/moduleloader.h>
55435 #include <video/edid.h>
55436 #include <video/uvesafb.h>
55437 #ifdef CONFIG_X86
55438@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55439 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55440 par->pmi_setpal = par->ypan = 0;
55441 } else {
55442+
55443+#ifdef CONFIG_PAX_KERNEXEC
55444+#ifdef CONFIG_MODULES
55445+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55446+#endif
55447+ if (!par->pmi_code) {
55448+ par->pmi_setpal = par->ypan = 0;
55449+ return 0;
55450+ }
55451+#endif
55452+
55453 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55454 + task->t.regs.edi);
55455+
55456+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55457+ pax_open_kernel();
55458+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55459+ pax_close_kernel();
55460+
55461+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55462+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55463+#else
55464 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55465 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55466+#endif
55467+
55468 printk(KERN_INFO "uvesafb: protected mode interface info at "
55469 "%04x:%04x\n",
55470 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55471@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55472 par->ypan = ypan;
55473
55474 if (par->pmi_setpal || par->ypan) {
55475+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55476 if (__supported_pte_mask & _PAGE_NX) {
55477 par->pmi_setpal = par->ypan = 0;
55478 printk(KERN_WARNING "uvesafb: NX protection is active, "
55479 "better not use the PMI.\n");
55480- } else {
55481+ } else
55482+#endif
55483 uvesafb_vbe_getpmi(task, par);
55484- }
55485 }
55486 #else
55487 /* The protected mode interface is not available on non-x86. */
55488@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55489 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55490
55491 /* Disable blanking if the user requested so. */
55492- if (!blank)
55493- info->fbops->fb_blank = NULL;
55494+ if (!blank) {
55495+ pax_open_kernel();
55496+ *(void **)&info->fbops->fb_blank = NULL;
55497+ pax_close_kernel();
55498+ }
55499
55500 /*
55501 * Find out how much IO memory is required for the mode with
55502@@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55503 info->flags = FBINFO_FLAG_DEFAULT |
55504 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55505
55506- if (!par->ypan)
55507- info->fbops->fb_pan_display = NULL;
55508+ if (!par->ypan) {
55509+ pax_open_kernel();
55510+ *(void **)&info->fbops->fb_pan_display = NULL;
55511+ pax_close_kernel();
55512+ }
55513 }
55514
55515 static void uvesafb_init_mtrr(struct fb_info *info)
55516@@ -1787,6 +1817,11 @@ out_mode:
55517 out:
55518 kfree(par->vbe_modes);
55519
55520+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55521+ if (par->pmi_code)
55522+ module_free_exec(NULL, par->pmi_code);
55523+#endif
55524+
55525 framebuffer_release(info);
55526 return err;
55527 }
55528@@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
55529 kfree(par->vbe_state_orig);
55530 kfree(par->vbe_state_saved);
55531
55532+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55533+ if (par->pmi_code)
55534+ module_free_exec(NULL, par->pmi_code);
55535+#endif
55536+
55537 framebuffer_release(info);
55538 }
55539 return 0;
55540diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
55541index 6170e7f..dd63031 100644
55542--- a/drivers/video/fbdev/vesafb.c
55543+++ b/drivers/video/fbdev/vesafb.c
55544@@ -9,6 +9,7 @@
55545 */
55546
55547 #include <linux/module.h>
55548+#include <linux/moduleloader.h>
55549 #include <linux/kernel.h>
55550 #include <linux/errno.h>
55551 #include <linux/string.h>
55552@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55553 static int vram_total; /* Set total amount of memory */
55554 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55555 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55556-static void (*pmi_start)(void) __read_mostly;
55557-static void (*pmi_pal) (void) __read_mostly;
55558+static void (*pmi_start)(void) __read_only;
55559+static void (*pmi_pal) (void) __read_only;
55560 static int depth __read_mostly;
55561 static int vga_compat __read_mostly;
55562 /* --------------------------------------------------------------------- */
55563@@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
55564 unsigned int size_remap;
55565 unsigned int size_total;
55566 char *option = NULL;
55567+ void *pmi_code = NULL;
55568
55569 /* ignore error return of fb_get_options */
55570 fb_get_options("vesafb", &option);
55571@@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
55572 size_remap = size_total;
55573 vesafb_fix.smem_len = size_remap;
55574
55575-#ifndef __i386__
55576- screen_info.vesapm_seg = 0;
55577-#endif
55578-
55579 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55580 printk(KERN_WARNING
55581 "vesafb: cannot reserve video memory at 0x%lx\n",
55582@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55583 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55584 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55585
55586+#ifdef __i386__
55587+
55588+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55589+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
55590+ if (!pmi_code)
55591+#elif !defined(CONFIG_PAX_KERNEXEC)
55592+ if (0)
55593+#endif
55594+
55595+#endif
55596+ screen_info.vesapm_seg = 0;
55597+
55598 if (screen_info.vesapm_seg) {
55599- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55600- screen_info.vesapm_seg,screen_info.vesapm_off);
55601+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55602+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55603 }
55604
55605 if (screen_info.vesapm_seg < 0xc000)
55606@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55607
55608 if (ypan || pmi_setpal) {
55609 unsigned short *pmi_base;
55610+
55611 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55612- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55613- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55614+
55615+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55616+ pax_open_kernel();
55617+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55618+#else
55619+ pmi_code = pmi_base;
55620+#endif
55621+
55622+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55623+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55624+
55625+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55626+ pmi_start = ktva_ktla(pmi_start);
55627+ pmi_pal = ktva_ktla(pmi_pal);
55628+ pax_close_kernel();
55629+#endif
55630+
55631 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55632 if (pmi_base[3]) {
55633 printk(KERN_INFO "vesafb: pmi: ports = ");
55634@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55635 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55636 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55637
55638- if (!ypan)
55639- info->fbops->fb_pan_display = NULL;
55640+ if (!ypan) {
55641+ pax_open_kernel();
55642+ *(void **)&info->fbops->fb_pan_display = NULL;
55643+ pax_close_kernel();
55644+ }
55645
55646 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55647 err = -ENOMEM;
55648@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55649 fb_info(info, "%s frame buffer device\n", info->fix.id);
55650 return 0;
55651 err:
55652+
55653+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55654+ module_free_exec(NULL, pmi_code);
55655+#endif
55656+
55657 if (info->screen_base)
55658 iounmap(info->screen_base);
55659 framebuffer_release(info);
55660diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
55661index 88714ae..16c2e11 100644
55662--- a/drivers/video/fbdev/via/via_clock.h
55663+++ b/drivers/video/fbdev/via/via_clock.h
55664@@ -56,7 +56,7 @@ struct via_clock {
55665
55666 void (*set_engine_pll_state)(u8 state);
55667 void (*set_engine_pll)(struct via_pll_config config);
55668-};
55669+} __no_const;
55670
55671
55672 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55673diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
55674index 3c14e43..2630570 100644
55675--- a/drivers/video/logo/logo_linux_clut224.ppm
55676+++ b/drivers/video/logo/logo_linux_clut224.ppm
55677@@ -2,1603 +2,1123 @@ P3
55678 # Standard 224-color Linux logo
55679 80 80
55680 255
55681- 0 0 0 0 0 0 0 0 0 0 0 0
55682- 0 0 0 0 0 0 0 0 0 0 0 0
55683- 0 0 0 0 0 0 0 0 0 0 0 0
55684- 0 0 0 0 0 0 0 0 0 0 0 0
55685- 0 0 0 0 0 0 0 0 0 0 0 0
55686- 0 0 0 0 0 0 0 0 0 0 0 0
55687- 0 0 0 0 0 0 0 0 0 0 0 0
55688- 0 0 0 0 0 0 0 0 0 0 0 0
55689- 0 0 0 0 0 0 0 0 0 0 0 0
55690- 6 6 6 6 6 6 10 10 10 10 10 10
55691- 10 10 10 6 6 6 6 6 6 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 0 0 0 0
55699- 0 0 0 0 0 0 0 0 0 0 0 0
55700- 0 0 0 0 0 0 0 0 0 0 0 0
55701- 0 0 0 0 0 0 0 0 0 0 0 0
55702- 0 0 0 0 0 0 0 0 0 0 0 0
55703- 0 0 0 0 0 0 0 0 0 0 0 0
55704- 0 0 0 0 0 0 0 0 0 0 0 0
55705- 0 0 0 0 0 0 0 0 0 0 0 0
55706- 0 0 0 0 0 0 0 0 0 0 0 0
55707- 0 0 0 0 0 0 0 0 0 0 0 0
55708- 0 0 0 0 0 0 0 0 0 0 0 0
55709- 0 0 0 6 6 6 10 10 10 14 14 14
55710- 22 22 22 26 26 26 30 30 30 34 34 34
55711- 30 30 30 30 30 30 26 26 26 18 18 18
55712- 14 14 14 10 10 10 6 6 6 0 0 0
55713- 0 0 0 0 0 0 0 0 0 0 0 0
55714- 0 0 0 0 0 0 0 0 0 0 0 0
55715- 0 0 0 0 0 0 0 0 0 0 0 0
55716- 0 0 0 0 0 0 0 0 0 0 0 0
55717- 0 0 0 0 0 0 0 0 0 0 0 0
55718- 0 0 0 0 0 0 0 0 0 0 0 0
55719- 0 0 0 0 0 0 0 0 0 0 0 0
55720- 0 0 0 0 0 0 0 0 0 0 0 0
55721- 0 0 0 0 0 0 0 0 0 0 0 0
55722- 0 0 0 0 0 1 0 0 1 0 0 0
55723- 0 0 0 0 0 0 0 0 0 0 0 0
55724- 0 0 0 0 0 0 0 0 0 0 0 0
55725- 0 0 0 0 0 0 0 0 0 0 0 0
55726- 0 0 0 0 0 0 0 0 0 0 0 0
55727- 0 0 0 0 0 0 0 0 0 0 0 0
55728- 0 0 0 0 0 0 0 0 0 0 0 0
55729- 6 6 6 14 14 14 26 26 26 42 42 42
55730- 54 54 54 66 66 66 78 78 78 78 78 78
55731- 78 78 78 74 74 74 66 66 66 54 54 54
55732- 42 42 42 26 26 26 18 18 18 10 10 10
55733- 6 6 6 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 1 0 0 0 0 0 0 0 0 0
55743- 0 0 0 0 0 0 0 0 0 0 0 0
55744- 0 0 0 0 0 0 0 0 0 0 0 0
55745- 0 0 0 0 0 0 0 0 0 0 0 0
55746- 0 0 0 0 0 0 0 0 0 0 0 0
55747- 0 0 0 0 0 0 0 0 0 0 0 0
55748- 0 0 0 0 0 0 0 0 0 10 10 10
55749- 22 22 22 42 42 42 66 66 66 86 86 86
55750- 66 66 66 38 38 38 38 38 38 22 22 22
55751- 26 26 26 34 34 34 54 54 54 66 66 66
55752- 86 86 86 70 70 70 46 46 46 26 26 26
55753- 14 14 14 6 6 6 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 1 0 0 1 0 0 1 0 0 0
55763- 0 0 0 0 0 0 0 0 0 0 0 0
55764- 0 0 0 0 0 0 0 0 0 0 0 0
55765- 0 0 0 0 0 0 0 0 0 0 0 0
55766- 0 0 0 0 0 0 0 0 0 0 0 0
55767- 0 0 0 0 0 0 0 0 0 0 0 0
55768- 0 0 0 0 0 0 10 10 10 26 26 26
55769- 50 50 50 82 82 82 58 58 58 6 6 6
55770- 2 2 6 2 2 6 2 2 6 2 2 6
55771- 2 2 6 2 2 6 2 2 6 2 2 6
55772- 6 6 6 54 54 54 86 86 86 66 66 66
55773- 38 38 38 18 18 18 6 6 6 0 0 0
55774- 0 0 0 0 0 0 0 0 0 0 0 0
55775- 0 0 0 0 0 0 0 0 0 0 0 0
55776- 0 0 0 0 0 0 0 0 0 0 0 0
55777- 0 0 0 0 0 0 0 0 0 0 0 0
55778- 0 0 0 0 0 0 0 0 0 0 0 0
55779- 0 0 0 0 0 0 0 0 0 0 0 0
55780- 0 0 0 0 0 0 0 0 0 0 0 0
55781- 0 0 0 0 0 0 0 0 0 0 0 0
55782- 0 0 0 0 0 0 0 0 0 0 0 0
55783- 0 0 0 0 0 0 0 0 0 0 0 0
55784- 0 0 0 0 0 0 0 0 0 0 0 0
55785- 0 0 0 0 0 0 0 0 0 0 0 0
55786- 0 0 0 0 0 0 0 0 0 0 0 0
55787- 0 0 0 0 0 0 0 0 0 0 0 0
55788- 0 0 0 6 6 6 22 22 22 50 50 50
55789- 78 78 78 34 34 34 2 2 6 2 2 6
55790- 2 2 6 2 2 6 2 2 6 2 2 6
55791- 2 2 6 2 2 6 2 2 6 2 2 6
55792- 2 2 6 2 2 6 6 6 6 70 70 70
55793- 78 78 78 46 46 46 22 22 22 6 6 6
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 1 0 0 1 0 0 1 0 0 0
55803- 0 0 0 0 0 0 0 0 0 0 0 0
55804- 0 0 0 0 0 0 0 0 0 0 0 0
55805- 0 0 0 0 0 0 0 0 0 0 0 0
55806- 0 0 0 0 0 0 0 0 0 0 0 0
55807- 0 0 0 0 0 0 0 0 0 0 0 0
55808- 6 6 6 18 18 18 42 42 42 82 82 82
55809- 26 26 26 2 2 6 2 2 6 2 2 6
55810- 2 2 6 2 2 6 2 2 6 2 2 6
55811- 2 2 6 2 2 6 2 2 6 14 14 14
55812- 46 46 46 34 34 34 6 6 6 2 2 6
55813- 42 42 42 78 78 78 42 42 42 18 18 18
55814- 6 6 6 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 1 0 0 0 0 0 1 0 0 0
55823- 0 0 0 0 0 0 0 0 0 0 0 0
55824- 0 0 0 0 0 0 0 0 0 0 0 0
55825- 0 0 0 0 0 0 0 0 0 0 0 0
55826- 0 0 0 0 0 0 0 0 0 0 0 0
55827- 0 0 0 0 0 0 0 0 0 0 0 0
55828- 10 10 10 30 30 30 66 66 66 58 58 58
55829- 2 2 6 2 2 6 2 2 6 2 2 6
55830- 2 2 6 2 2 6 2 2 6 2 2 6
55831- 2 2 6 2 2 6 2 2 6 26 26 26
55832- 86 86 86 101 101 101 46 46 46 10 10 10
55833- 2 2 6 58 58 58 70 70 70 34 34 34
55834- 10 10 10 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 1 0 0 1 0 0 1 0 0 0
55843- 0 0 0 0 0 0 0 0 0 0 0 0
55844- 0 0 0 0 0 0 0 0 0 0 0 0
55845- 0 0 0 0 0 0 0 0 0 0 0 0
55846- 0 0 0 0 0 0 0 0 0 0 0 0
55847- 0 0 0 0 0 0 0 0 0 0 0 0
55848- 14 14 14 42 42 42 86 86 86 10 10 10
55849- 2 2 6 2 2 6 2 2 6 2 2 6
55850- 2 2 6 2 2 6 2 2 6 2 2 6
55851- 2 2 6 2 2 6 2 2 6 30 30 30
55852- 94 94 94 94 94 94 58 58 58 26 26 26
55853- 2 2 6 6 6 6 78 78 78 54 54 54
55854- 22 22 22 6 6 6 0 0 0 0 0 0
55855- 0 0 0 0 0 0 0 0 0 0 0 0
55856- 0 0 0 0 0 0 0 0 0 0 0 0
55857- 0 0 0 0 0 0 0 0 0 0 0 0
55858- 0 0 0 0 0 0 0 0 0 0 0 0
55859- 0 0 0 0 0 0 0 0 0 0 0 0
55860- 0 0 0 0 0 0 0 0 0 0 0 0
55861- 0 0 0 0 0 0 0 0 0 0 0 0
55862- 0 0 0 0 0 0 0 0 0 0 0 0
55863- 0 0 0 0 0 0 0 0 0 0 0 0
55864- 0 0 0 0 0 0 0 0 0 0 0 0
55865- 0 0 0 0 0 0 0 0 0 0 0 0
55866- 0 0 0 0 0 0 0 0 0 0 0 0
55867- 0 0 0 0 0 0 0 0 0 6 6 6
55868- 22 22 22 62 62 62 62 62 62 2 2 6
55869- 2 2 6 2 2 6 2 2 6 2 2 6
55870- 2 2 6 2 2 6 2 2 6 2 2 6
55871- 2 2 6 2 2 6 2 2 6 26 26 26
55872- 54 54 54 38 38 38 18 18 18 10 10 10
55873- 2 2 6 2 2 6 34 34 34 82 82 82
55874- 38 38 38 14 14 14 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 1 0 0 1 0 0 0
55883- 0 0 0 0 0 0 0 0 0 0 0 0
55884- 0 0 0 0 0 0 0 0 0 0 0 0
55885- 0 0 0 0 0 0 0 0 0 0 0 0
55886- 0 0 0 0 0 0 0 0 0 0 0 0
55887- 0 0 0 0 0 0 0 0 0 6 6 6
55888- 30 30 30 78 78 78 30 30 30 2 2 6
55889- 2 2 6 2 2 6 2 2 6 2 2 6
55890- 2 2 6 2 2 6 2 2 6 2 2 6
55891- 2 2 6 2 2 6 2 2 6 10 10 10
55892- 10 10 10 2 2 6 2 2 6 2 2 6
55893- 2 2 6 2 2 6 2 2 6 78 78 78
55894- 50 50 50 18 18 18 6 6 6 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 1 0 0 0 0 0 0 0 0 0
55903- 0 0 0 0 0 0 0 0 0 0 0 0
55904- 0 0 0 0 0 0 0 0 0 0 0 0
55905- 0 0 0 0 0 0 0 0 0 0 0 0
55906- 0 0 0 0 0 0 0 0 0 0 0 0
55907- 0 0 0 0 0 0 0 0 0 10 10 10
55908- 38 38 38 86 86 86 14 14 14 2 2 6
55909- 2 2 6 2 2 6 2 2 6 2 2 6
55910- 2 2 6 2 2 6 2 2 6 2 2 6
55911- 2 2 6 2 2 6 2 2 6 2 2 6
55912- 2 2 6 2 2 6 2 2 6 2 2 6
55913- 2 2 6 2 2 6 2 2 6 54 54 54
55914- 66 66 66 26 26 26 6 6 6 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 1 0 0 1 0 0 0
55923- 0 0 0 0 0 0 0 0 0 0 0 0
55924- 0 0 0 0 0 0 0 0 0 0 0 0
55925- 0 0 0 0 0 0 0 0 0 0 0 0
55926- 0 0 0 0 0 0 0 0 0 0 0 0
55927- 0 0 0 0 0 0 0 0 0 14 14 14
55928- 42 42 42 82 82 82 2 2 6 2 2 6
55929- 2 2 6 6 6 6 10 10 10 2 2 6
55930- 2 2 6 2 2 6 2 2 6 2 2 6
55931- 2 2 6 2 2 6 2 2 6 6 6 6
55932- 14 14 14 10 10 10 2 2 6 2 2 6
55933- 2 2 6 2 2 6 2 2 6 18 18 18
55934- 82 82 82 34 34 34 10 10 10 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 1 0 0 0 0 0 0 0 0 0
55943- 0 0 0 0 0 0 0 0 0 0 0 0
55944- 0 0 0 0 0 0 0 0 0 0 0 0
55945- 0 0 0 0 0 0 0 0 0 0 0 0
55946- 0 0 0 0 0 0 0 0 0 0 0 0
55947- 0 0 0 0 0 0 0 0 0 14 14 14
55948- 46 46 46 86 86 86 2 2 6 2 2 6
55949- 6 6 6 6 6 6 22 22 22 34 34 34
55950- 6 6 6 2 2 6 2 2 6 2 2 6
55951- 2 2 6 2 2 6 18 18 18 34 34 34
55952- 10 10 10 50 50 50 22 22 22 2 2 6
55953- 2 2 6 2 2 6 2 2 6 10 10 10
55954- 86 86 86 42 42 42 14 14 14 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 1 0 0 1 0 0 1 0 0 0
55963- 0 0 0 0 0 0 0 0 0 0 0 0
55964- 0 0 0 0 0 0 0 0 0 0 0 0
55965- 0 0 0 0 0 0 0 0 0 0 0 0
55966- 0 0 0 0 0 0 0 0 0 0 0 0
55967- 0 0 0 0 0 0 0 0 0 14 14 14
55968- 46 46 46 86 86 86 2 2 6 2 2 6
55969- 38 38 38 116 116 116 94 94 94 22 22 22
55970- 22 22 22 2 2 6 2 2 6 2 2 6
55971- 14 14 14 86 86 86 138 138 138 162 162 162
55972-154 154 154 38 38 38 26 26 26 6 6 6
55973- 2 2 6 2 2 6 2 2 6 2 2 6
55974- 86 86 86 46 46 46 14 14 14 0 0 0
55975- 0 0 0 0 0 0 0 0 0 0 0 0
55976- 0 0 0 0 0 0 0 0 0 0 0 0
55977- 0 0 0 0 0 0 0 0 0 0 0 0
55978- 0 0 0 0 0 0 0 0 0 0 0 0
55979- 0 0 0 0 0 0 0 0 0 0 0 0
55980- 0 0 0 0 0 0 0 0 0 0 0 0
55981- 0 0 0 0 0 0 0 0 0 0 0 0
55982- 0 0 0 0 0 0 0 0 0 0 0 0
55983- 0 0 0 0 0 0 0 0 0 0 0 0
55984- 0 0 0 0 0 0 0 0 0 0 0 0
55985- 0 0 0 0 0 0 0 0 0 0 0 0
55986- 0 0 0 0 0 0 0 0 0 0 0 0
55987- 0 0 0 0 0 0 0 0 0 14 14 14
55988- 46 46 46 86 86 86 2 2 6 14 14 14
55989-134 134 134 198 198 198 195 195 195 116 116 116
55990- 10 10 10 2 2 6 2 2 6 6 6 6
55991-101 98 89 187 187 187 210 210 210 218 218 218
55992-214 214 214 134 134 134 14 14 14 6 6 6
55993- 2 2 6 2 2 6 2 2 6 2 2 6
55994- 86 86 86 50 50 50 18 18 18 6 6 6
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 1 0 0 0
56002- 0 0 1 0 0 1 0 0 1 0 0 0
56003- 0 0 0 0 0 0 0 0 0 0 0 0
56004- 0 0 0 0 0 0 0 0 0 0 0 0
56005- 0 0 0 0 0 0 0 0 0 0 0 0
56006- 0 0 0 0 0 0 0 0 0 0 0 0
56007- 0 0 0 0 0 0 0 0 0 14 14 14
56008- 46 46 46 86 86 86 2 2 6 54 54 54
56009-218 218 218 195 195 195 226 226 226 246 246 246
56010- 58 58 58 2 2 6 2 2 6 30 30 30
56011-210 210 210 253 253 253 174 174 174 123 123 123
56012-221 221 221 234 234 234 74 74 74 2 2 6
56013- 2 2 6 2 2 6 2 2 6 2 2 6
56014- 70 70 70 58 58 58 22 22 22 6 6 6
56015- 0 0 0 0 0 0 0 0 0 0 0 0
56016- 0 0 0 0 0 0 0 0 0 0 0 0
56017- 0 0 0 0 0 0 0 0 0 0 0 0
56018- 0 0 0 0 0 0 0 0 0 0 0 0
56019- 0 0 0 0 0 0 0 0 0 0 0 0
56020- 0 0 0 0 0 0 0 0 0 0 0 0
56021- 0 0 0 0 0 0 0 0 0 0 0 0
56022- 0 0 0 0 0 0 0 0 0 0 0 0
56023- 0 0 0 0 0 0 0 0 0 0 0 0
56024- 0 0 0 0 0 0 0 0 0 0 0 0
56025- 0 0 0 0 0 0 0 0 0 0 0 0
56026- 0 0 0 0 0 0 0 0 0 0 0 0
56027- 0 0 0 0 0 0 0 0 0 14 14 14
56028- 46 46 46 82 82 82 2 2 6 106 106 106
56029-170 170 170 26 26 26 86 86 86 226 226 226
56030-123 123 123 10 10 10 14 14 14 46 46 46
56031-231 231 231 190 190 190 6 6 6 70 70 70
56032- 90 90 90 238 238 238 158 158 158 2 2 6
56033- 2 2 6 2 2 6 2 2 6 2 2 6
56034- 70 70 70 58 58 58 22 22 22 6 6 6
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 1 0 0 0
56042- 0 0 1 0 0 1 0 0 1 0 0 0
56043- 0 0 0 0 0 0 0 0 0 0 0 0
56044- 0 0 0 0 0 0 0 0 0 0 0 0
56045- 0 0 0 0 0 0 0 0 0 0 0 0
56046- 0 0 0 0 0 0 0 0 0 0 0 0
56047- 0 0 0 0 0 0 0 0 0 14 14 14
56048- 42 42 42 86 86 86 6 6 6 116 116 116
56049-106 106 106 6 6 6 70 70 70 149 149 149
56050-128 128 128 18 18 18 38 38 38 54 54 54
56051-221 221 221 106 106 106 2 2 6 14 14 14
56052- 46 46 46 190 190 190 198 198 198 2 2 6
56053- 2 2 6 2 2 6 2 2 6 2 2 6
56054- 74 74 74 62 62 62 22 22 22 6 6 6
56055- 0 0 0 0 0 0 0 0 0 0 0 0
56056- 0 0 0 0 0 0 0 0 0 0 0 0
56057- 0 0 0 0 0 0 0 0 0 0 0 0
56058- 0 0 0 0 0 0 0 0 0 0 0 0
56059- 0 0 0 0 0 0 0 0 0 0 0 0
56060- 0 0 0 0 0 0 0 0 0 0 0 0
56061- 0 0 0 0 0 0 0 0 1 0 0 0
56062- 0 0 1 0 0 0 0 0 1 0 0 0
56063- 0 0 0 0 0 0 0 0 0 0 0 0
56064- 0 0 0 0 0 0 0 0 0 0 0 0
56065- 0 0 0 0 0 0 0 0 0 0 0 0
56066- 0 0 0 0 0 0 0 0 0 0 0 0
56067- 0 0 0 0 0 0 0 0 0 14 14 14
56068- 42 42 42 94 94 94 14 14 14 101 101 101
56069-128 128 128 2 2 6 18 18 18 116 116 116
56070-118 98 46 121 92 8 121 92 8 98 78 10
56071-162 162 162 106 106 106 2 2 6 2 2 6
56072- 2 2 6 195 195 195 195 195 195 6 6 6
56073- 2 2 6 2 2 6 2 2 6 2 2 6
56074- 74 74 74 62 62 62 22 22 22 6 6 6
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 1 0 0 1
56082- 0 0 1 0 0 0 0 0 1 0 0 0
56083- 0 0 0 0 0 0 0 0 0 0 0 0
56084- 0 0 0 0 0 0 0 0 0 0 0 0
56085- 0 0 0 0 0 0 0 0 0 0 0 0
56086- 0 0 0 0 0 0 0 0 0 0 0 0
56087- 0 0 0 0 0 0 0 0 0 10 10 10
56088- 38 38 38 90 90 90 14 14 14 58 58 58
56089-210 210 210 26 26 26 54 38 6 154 114 10
56090-226 170 11 236 186 11 225 175 15 184 144 12
56091-215 174 15 175 146 61 37 26 9 2 2 6
56092- 70 70 70 246 246 246 138 138 138 2 2 6
56093- 2 2 6 2 2 6 2 2 6 2 2 6
56094- 70 70 70 66 66 66 26 26 26 6 6 6
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 0 0 0
56103- 0 0 0 0 0 0 0 0 0 0 0 0
56104- 0 0 0 0 0 0 0 0 0 0 0 0
56105- 0 0 0 0 0 0 0 0 0 0 0 0
56106- 0 0 0 0 0 0 0 0 0 0 0 0
56107- 0 0 0 0 0 0 0 0 0 10 10 10
56108- 38 38 38 86 86 86 14 14 14 10 10 10
56109-195 195 195 188 164 115 192 133 9 225 175 15
56110-239 182 13 234 190 10 232 195 16 232 200 30
56111-245 207 45 241 208 19 232 195 16 184 144 12
56112-218 194 134 211 206 186 42 42 42 2 2 6
56113- 2 2 6 2 2 6 2 2 6 2 2 6
56114- 50 50 50 74 74 74 30 30 30 6 6 6
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 0 0 0
56123- 0 0 0 0 0 0 0 0 0 0 0 0
56124- 0 0 0 0 0 0 0 0 0 0 0 0
56125- 0 0 0 0 0 0 0 0 0 0 0 0
56126- 0 0 0 0 0 0 0 0 0 0 0 0
56127- 0 0 0 0 0 0 0 0 0 10 10 10
56128- 34 34 34 86 86 86 14 14 14 2 2 6
56129-121 87 25 192 133 9 219 162 10 239 182 13
56130-236 186 11 232 195 16 241 208 19 244 214 54
56131-246 218 60 246 218 38 246 215 20 241 208 19
56132-241 208 19 226 184 13 121 87 25 2 2 6
56133- 2 2 6 2 2 6 2 2 6 2 2 6
56134- 50 50 50 82 82 82 34 34 34 10 10 10
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 0 0 0
56143- 0 0 0 0 0 0 0 0 0 0 0 0
56144- 0 0 0 0 0 0 0 0 0 0 0 0
56145- 0 0 0 0 0 0 0 0 0 0 0 0
56146- 0 0 0 0 0 0 0 0 0 0 0 0
56147- 0 0 0 0 0 0 0 0 0 10 10 10
56148- 34 34 34 82 82 82 30 30 30 61 42 6
56149-180 123 7 206 145 10 230 174 11 239 182 13
56150-234 190 10 238 202 15 241 208 19 246 218 74
56151-246 218 38 246 215 20 246 215 20 246 215 20
56152-226 184 13 215 174 15 184 144 12 6 6 6
56153- 2 2 6 2 2 6 2 2 6 2 2 6
56154- 26 26 26 94 94 94 42 42 42 14 14 14
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 0 0 0 0 0 0
56163- 0 0 0 0 0 0 0 0 0 0 0 0
56164- 0 0 0 0 0 0 0 0 0 0 0 0
56165- 0 0 0 0 0 0 0 0 0 0 0 0
56166- 0 0 0 0 0 0 0 0 0 0 0 0
56167- 0 0 0 0 0 0 0 0 0 10 10 10
56168- 30 30 30 78 78 78 50 50 50 104 69 6
56169-192 133 9 216 158 10 236 178 12 236 186 11
56170-232 195 16 241 208 19 244 214 54 245 215 43
56171-246 215 20 246 215 20 241 208 19 198 155 10
56172-200 144 11 216 158 10 156 118 10 2 2 6
56173- 2 2 6 2 2 6 2 2 6 2 2 6
56174- 6 6 6 90 90 90 54 54 54 18 18 18
56175- 6 6 6 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 0 0 0 0 0 0
56183- 0 0 0 0 0 0 0 0 0 0 0 0
56184- 0 0 0 0 0 0 0 0 0 0 0 0
56185- 0 0 0 0 0 0 0 0 0 0 0 0
56186- 0 0 0 0 0 0 0 0 0 0 0 0
56187- 0 0 0 0 0 0 0 0 0 10 10 10
56188- 30 30 30 78 78 78 46 46 46 22 22 22
56189-137 92 6 210 162 10 239 182 13 238 190 10
56190-238 202 15 241 208 19 246 215 20 246 215 20
56191-241 208 19 203 166 17 185 133 11 210 150 10
56192-216 158 10 210 150 10 102 78 10 2 2 6
56193- 6 6 6 54 54 54 14 14 14 2 2 6
56194- 2 2 6 62 62 62 74 74 74 30 30 30
56195- 10 10 10 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 0 0 0 0 0 0 0 0 0
56203- 0 0 0 0 0 0 0 0 0 0 0 0
56204- 0 0 0 0 0 0 0 0 0 0 0 0
56205- 0 0 0 0 0 0 0 0 0 0 0 0
56206- 0 0 0 0 0 0 0 0 0 0 0 0
56207- 0 0 0 0 0 0 0 0 0 10 10 10
56208- 34 34 34 78 78 78 50 50 50 6 6 6
56209- 94 70 30 139 102 15 190 146 13 226 184 13
56210-232 200 30 232 195 16 215 174 15 190 146 13
56211-168 122 10 192 133 9 210 150 10 213 154 11
56212-202 150 34 182 157 106 101 98 89 2 2 6
56213- 2 2 6 78 78 78 116 116 116 58 58 58
56214- 2 2 6 22 22 22 90 90 90 46 46 46
56215- 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0
56223- 0 0 0 0 0 0 0 0 0 0 0 0
56224- 0 0 0 0 0 0 0 0 0 0 0 0
56225- 0 0 0 0 0 0 0 0 0 0 0 0
56226- 0 0 0 0 0 0 0 0 0 0 0 0
56227- 0 0 0 0 0 0 0 0 0 10 10 10
56228- 38 38 38 86 86 86 50 50 50 6 6 6
56229-128 128 128 174 154 114 156 107 11 168 122 10
56230-198 155 10 184 144 12 197 138 11 200 144 11
56231-206 145 10 206 145 10 197 138 11 188 164 115
56232-195 195 195 198 198 198 174 174 174 14 14 14
56233- 2 2 6 22 22 22 116 116 116 116 116 116
56234- 22 22 22 2 2 6 74 74 74 70 70 70
56235- 30 30 30 10 10 10 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- 0 0 0 0 0 0 0 0 0 0 0 0
56243- 0 0 0 0 0 0 0 0 0 0 0 0
56244- 0 0 0 0 0 0 0 0 0 0 0 0
56245- 0 0 0 0 0 0 0 0 0 0 0 0
56246- 0 0 0 0 0 0 0 0 0 0 0 0
56247- 0 0 0 0 0 0 6 6 6 18 18 18
56248- 50 50 50 101 101 101 26 26 26 10 10 10
56249-138 138 138 190 190 190 174 154 114 156 107 11
56250-197 138 11 200 144 11 197 138 11 192 133 9
56251-180 123 7 190 142 34 190 178 144 187 187 187
56252-202 202 202 221 221 221 214 214 214 66 66 66
56253- 2 2 6 2 2 6 50 50 50 62 62 62
56254- 6 6 6 2 2 6 10 10 10 90 90 90
56255- 50 50 50 18 18 18 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
56263- 0 0 0 0 0 0 0 0 0 0 0 0
56264- 0 0 0 0 0 0 0 0 0 0 0 0
56265- 0 0 0 0 0 0 0 0 0 0 0 0
56266- 0 0 0 0 0 0 0 0 0 0 0 0
56267- 0 0 0 0 0 0 10 10 10 34 34 34
56268- 74 74 74 74 74 74 2 2 6 6 6 6
56269-144 144 144 198 198 198 190 190 190 178 166 146
56270-154 121 60 156 107 11 156 107 11 168 124 44
56271-174 154 114 187 187 187 190 190 190 210 210 210
56272-246 246 246 253 253 253 253 253 253 182 182 182
56273- 6 6 6 2 2 6 2 2 6 2 2 6
56274- 2 2 6 2 2 6 2 2 6 62 62 62
56275- 74 74 74 34 34 34 14 14 14 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 0 0 0
56282- 0 0 0 0 0 0 0 0 0 0 0 0
56283- 0 0 0 0 0 0 0 0 0 0 0 0
56284- 0 0 0 0 0 0 0 0 0 0 0 0
56285- 0 0 0 0 0 0 0 0 0 0 0 0
56286- 0 0 0 0 0 0 0 0 0 0 0 0
56287- 0 0 0 10 10 10 22 22 22 54 54 54
56288- 94 94 94 18 18 18 2 2 6 46 46 46
56289-234 234 234 221 221 221 190 190 190 190 190 190
56290-190 190 190 187 187 187 187 187 187 190 190 190
56291-190 190 190 195 195 195 214 214 214 242 242 242
56292-253 253 253 253 253 253 253 253 253 253 253 253
56293- 82 82 82 2 2 6 2 2 6 2 2 6
56294- 2 2 6 2 2 6 2 2 6 14 14 14
56295- 86 86 86 54 54 54 22 22 22 6 6 6
56296- 0 0 0 0 0 0 0 0 0 0 0 0
56297- 0 0 0 0 0 0 0 0 0 0 0 0
56298- 0 0 0 0 0 0 0 0 0 0 0 0
56299- 0 0 0 0 0 0 0 0 0 0 0 0
56300- 0 0 0 0 0 0 0 0 0 0 0 0
56301- 0 0 0 0 0 0 0 0 0 0 0 0
56302- 0 0 0 0 0 0 0 0 0 0 0 0
56303- 0 0 0 0 0 0 0 0 0 0 0 0
56304- 0 0 0 0 0 0 0 0 0 0 0 0
56305- 0 0 0 0 0 0 0 0 0 0 0 0
56306- 0 0 0 0 0 0 0 0 0 0 0 0
56307- 6 6 6 18 18 18 46 46 46 90 90 90
56308- 46 46 46 18 18 18 6 6 6 182 182 182
56309-253 253 253 246 246 246 206 206 206 190 190 190
56310-190 190 190 190 190 190 190 190 190 190 190 190
56311-206 206 206 231 231 231 250 250 250 253 253 253
56312-253 253 253 253 253 253 253 253 253 253 253 253
56313-202 202 202 14 14 14 2 2 6 2 2 6
56314- 2 2 6 2 2 6 2 2 6 2 2 6
56315- 42 42 42 86 86 86 42 42 42 18 18 18
56316- 6 6 6 0 0 0 0 0 0 0 0 0
56317- 0 0 0 0 0 0 0 0 0 0 0 0
56318- 0 0 0 0 0 0 0 0 0 0 0 0
56319- 0 0 0 0 0 0 0 0 0 0 0 0
56320- 0 0 0 0 0 0 0 0 0 0 0 0
56321- 0 0 0 0 0 0 0 0 0 0 0 0
56322- 0 0 0 0 0 0 0 0 0 0 0 0
56323- 0 0 0 0 0 0 0 0 0 0 0 0
56324- 0 0 0 0 0 0 0 0 0 0 0 0
56325- 0 0 0 0 0 0 0 0 0 0 0 0
56326- 0 0 0 0 0 0 0 0 0 6 6 6
56327- 14 14 14 38 38 38 74 74 74 66 66 66
56328- 2 2 6 6 6 6 90 90 90 250 250 250
56329-253 253 253 253 253 253 238 238 238 198 198 198
56330-190 190 190 190 190 190 195 195 195 221 221 221
56331-246 246 246 253 253 253 253 253 253 253 253 253
56332-253 253 253 253 253 253 253 253 253 253 253 253
56333-253 253 253 82 82 82 2 2 6 2 2 6
56334- 2 2 6 2 2 6 2 2 6 2 2 6
56335- 2 2 6 78 78 78 70 70 70 34 34 34
56336- 14 14 14 6 6 6 0 0 0 0 0 0
56337- 0 0 0 0 0 0 0 0 0 0 0 0
56338- 0 0 0 0 0 0 0 0 0 0 0 0
56339- 0 0 0 0 0 0 0 0 0 0 0 0
56340- 0 0 0 0 0 0 0 0 0 0 0 0
56341- 0 0 0 0 0 0 0 0 0 0 0 0
56342- 0 0 0 0 0 0 0 0 0 0 0 0
56343- 0 0 0 0 0 0 0 0 0 0 0 0
56344- 0 0 0 0 0 0 0 0 0 0 0 0
56345- 0 0 0 0 0 0 0 0 0 0 0 0
56346- 0 0 0 0 0 0 0 0 0 14 14 14
56347- 34 34 34 66 66 66 78 78 78 6 6 6
56348- 2 2 6 18 18 18 218 218 218 253 253 253
56349-253 253 253 253 253 253 253 253 253 246 246 246
56350-226 226 226 231 231 231 246 246 246 253 253 253
56351-253 253 253 253 253 253 253 253 253 253 253 253
56352-253 253 253 253 253 253 253 253 253 253 253 253
56353-253 253 253 178 178 178 2 2 6 2 2 6
56354- 2 2 6 2 2 6 2 2 6 2 2 6
56355- 2 2 6 18 18 18 90 90 90 62 62 62
56356- 30 30 30 10 10 10 0 0 0 0 0 0
56357- 0 0 0 0 0 0 0 0 0 0 0 0
56358- 0 0 0 0 0 0 0 0 0 0 0 0
56359- 0 0 0 0 0 0 0 0 0 0 0 0
56360- 0 0 0 0 0 0 0 0 0 0 0 0
56361- 0 0 0 0 0 0 0 0 0 0 0 0
56362- 0 0 0 0 0 0 0 0 0 0 0 0
56363- 0 0 0 0 0 0 0 0 0 0 0 0
56364- 0 0 0 0 0 0 0 0 0 0 0 0
56365- 0 0 0 0 0 0 0 0 0 0 0 0
56366- 0 0 0 0 0 0 10 10 10 26 26 26
56367- 58 58 58 90 90 90 18 18 18 2 2 6
56368- 2 2 6 110 110 110 253 253 253 253 253 253
56369-253 253 253 253 253 253 253 253 253 253 253 253
56370-250 250 250 253 253 253 253 253 253 253 253 253
56371-253 253 253 253 253 253 253 253 253 253 253 253
56372-253 253 253 253 253 253 253 253 253 253 253 253
56373-253 253 253 231 231 231 18 18 18 2 2 6
56374- 2 2 6 2 2 6 2 2 6 2 2 6
56375- 2 2 6 2 2 6 18 18 18 94 94 94
56376- 54 54 54 26 26 26 10 10 10 0 0 0
56377- 0 0 0 0 0 0 0 0 0 0 0 0
56378- 0 0 0 0 0 0 0 0 0 0 0 0
56379- 0 0 0 0 0 0 0 0 0 0 0 0
56380- 0 0 0 0 0 0 0 0 0 0 0 0
56381- 0 0 0 0 0 0 0 0 0 0 0 0
56382- 0 0 0 0 0 0 0 0 0 0 0 0
56383- 0 0 0 0 0 0 0 0 0 0 0 0
56384- 0 0 0 0 0 0 0 0 0 0 0 0
56385- 0 0 0 0 0 0 0 0 0 0 0 0
56386- 0 0 0 6 6 6 22 22 22 50 50 50
56387- 90 90 90 26 26 26 2 2 6 2 2 6
56388- 14 14 14 195 195 195 250 250 250 253 253 253
56389-253 253 253 253 253 253 253 253 253 253 253 253
56390-253 253 253 253 253 253 253 253 253 253 253 253
56391-253 253 253 253 253 253 253 253 253 253 253 253
56392-253 253 253 253 253 253 253 253 253 253 253 253
56393-250 250 250 242 242 242 54 54 54 2 2 6
56394- 2 2 6 2 2 6 2 2 6 2 2 6
56395- 2 2 6 2 2 6 2 2 6 38 38 38
56396- 86 86 86 50 50 50 22 22 22 6 6 6
56397- 0 0 0 0 0 0 0 0 0 0 0 0
56398- 0 0 0 0 0 0 0 0 0 0 0 0
56399- 0 0 0 0 0 0 0 0 0 0 0 0
56400- 0 0 0 0 0 0 0 0 0 0 0 0
56401- 0 0 0 0 0 0 0 0 0 0 0 0
56402- 0 0 0 0 0 0 0 0 0 0 0 0
56403- 0 0 0 0 0 0 0 0 0 0 0 0
56404- 0 0 0 0 0 0 0 0 0 0 0 0
56405- 0 0 0 0 0 0 0 0 0 0 0 0
56406- 6 6 6 14 14 14 38 38 38 82 82 82
56407- 34 34 34 2 2 6 2 2 6 2 2 6
56408- 42 42 42 195 195 195 246 246 246 253 253 253
56409-253 253 253 253 253 253 253 253 253 250 250 250
56410-242 242 242 242 242 242 250 250 250 253 253 253
56411-253 253 253 253 253 253 253 253 253 253 253 253
56412-253 253 253 250 250 250 246 246 246 238 238 238
56413-226 226 226 231 231 231 101 101 101 6 6 6
56414- 2 2 6 2 2 6 2 2 6 2 2 6
56415- 2 2 6 2 2 6 2 2 6 2 2 6
56416- 38 38 38 82 82 82 42 42 42 14 14 14
56417- 6 6 6 0 0 0 0 0 0 0 0 0
56418- 0 0 0 0 0 0 0 0 0 0 0 0
56419- 0 0 0 0 0 0 0 0 0 0 0 0
56420- 0 0 0 0 0 0 0 0 0 0 0 0
56421- 0 0 0 0 0 0 0 0 0 0 0 0
56422- 0 0 0 0 0 0 0 0 0 0 0 0
56423- 0 0 0 0 0 0 0 0 0 0 0 0
56424- 0 0 0 0 0 0 0 0 0 0 0 0
56425- 0 0 0 0 0 0 0 0 0 0 0 0
56426- 10 10 10 26 26 26 62 62 62 66 66 66
56427- 2 2 6 2 2 6 2 2 6 6 6 6
56428- 70 70 70 170 170 170 206 206 206 234 234 234
56429-246 246 246 250 250 250 250 250 250 238 238 238
56430-226 226 226 231 231 231 238 238 238 250 250 250
56431-250 250 250 250 250 250 246 246 246 231 231 231
56432-214 214 214 206 206 206 202 202 202 202 202 202
56433-198 198 198 202 202 202 182 182 182 18 18 18
56434- 2 2 6 2 2 6 2 2 6 2 2 6
56435- 2 2 6 2 2 6 2 2 6 2 2 6
56436- 2 2 6 62 62 62 66 66 66 30 30 30
56437- 10 10 10 0 0 0 0 0 0 0 0 0
56438- 0 0 0 0 0 0 0 0 0 0 0 0
56439- 0 0 0 0 0 0 0 0 0 0 0 0
56440- 0 0 0 0 0 0 0 0 0 0 0 0
56441- 0 0 0 0 0 0 0 0 0 0 0 0
56442- 0 0 0 0 0 0 0 0 0 0 0 0
56443- 0 0 0 0 0 0 0 0 0 0 0 0
56444- 0 0 0 0 0 0 0 0 0 0 0 0
56445- 0 0 0 0 0 0 0 0 0 0 0 0
56446- 14 14 14 42 42 42 82 82 82 18 18 18
56447- 2 2 6 2 2 6 2 2 6 10 10 10
56448- 94 94 94 182 182 182 218 218 218 242 242 242
56449-250 250 250 253 253 253 253 253 253 250 250 250
56450-234 234 234 253 253 253 253 253 253 253 253 253
56451-253 253 253 253 253 253 253 253 253 246 246 246
56452-238 238 238 226 226 226 210 210 210 202 202 202
56453-195 195 195 195 195 195 210 210 210 158 158 158
56454- 6 6 6 14 14 14 50 50 50 14 14 14
56455- 2 2 6 2 2 6 2 2 6 2 2 6
56456- 2 2 6 6 6 6 86 86 86 46 46 46
56457- 18 18 18 6 6 6 0 0 0 0 0 0
56458- 0 0 0 0 0 0 0 0 0 0 0 0
56459- 0 0 0 0 0 0 0 0 0 0 0 0
56460- 0 0 0 0 0 0 0 0 0 0 0 0
56461- 0 0 0 0 0 0 0 0 0 0 0 0
56462- 0 0 0 0 0 0 0 0 0 0 0 0
56463- 0 0 0 0 0 0 0 0 0 0 0 0
56464- 0 0 0 0 0 0 0 0 0 0 0 0
56465- 0 0 0 0 0 0 0 0 0 6 6 6
56466- 22 22 22 54 54 54 70 70 70 2 2 6
56467- 2 2 6 10 10 10 2 2 6 22 22 22
56468-166 166 166 231 231 231 250 250 250 253 253 253
56469-253 253 253 253 253 253 253 253 253 250 250 250
56470-242 242 242 253 253 253 253 253 253 253 253 253
56471-253 253 253 253 253 253 253 253 253 253 253 253
56472-253 253 253 253 253 253 253 253 253 246 246 246
56473-231 231 231 206 206 206 198 198 198 226 226 226
56474- 94 94 94 2 2 6 6 6 6 38 38 38
56475- 30 30 30 2 2 6 2 2 6 2 2 6
56476- 2 2 6 2 2 6 62 62 62 66 66 66
56477- 26 26 26 10 10 10 0 0 0 0 0 0
56478- 0 0 0 0 0 0 0 0 0 0 0 0
56479- 0 0 0 0 0 0 0 0 0 0 0 0
56480- 0 0 0 0 0 0 0 0 0 0 0 0
56481- 0 0 0 0 0 0 0 0 0 0 0 0
56482- 0 0 0 0 0 0 0 0 0 0 0 0
56483- 0 0 0 0 0 0 0 0 0 0 0 0
56484- 0 0 0 0 0 0 0 0 0 0 0 0
56485- 0 0 0 0 0 0 0 0 0 10 10 10
56486- 30 30 30 74 74 74 50 50 50 2 2 6
56487- 26 26 26 26 26 26 2 2 6 106 106 106
56488-238 238 238 253 253 253 253 253 253 253 253 253
56489-253 253 253 253 253 253 253 253 253 253 253 253
56490-253 253 253 253 253 253 253 253 253 253 253 253
56491-253 253 253 253 253 253 253 253 253 253 253 253
56492-253 253 253 253 253 253 253 253 253 253 253 253
56493-253 253 253 246 246 246 218 218 218 202 202 202
56494-210 210 210 14 14 14 2 2 6 2 2 6
56495- 30 30 30 22 22 22 2 2 6 2 2 6
56496- 2 2 6 2 2 6 18 18 18 86 86 86
56497- 42 42 42 14 14 14 0 0 0 0 0 0
56498- 0 0 0 0 0 0 0 0 0 0 0 0
56499- 0 0 0 0 0 0 0 0 0 0 0 0
56500- 0 0 0 0 0 0 0 0 0 0 0 0
56501- 0 0 0 0 0 0 0 0 0 0 0 0
56502- 0 0 0 0 0 0 0 0 0 0 0 0
56503- 0 0 0 0 0 0 0 0 0 0 0 0
56504- 0 0 0 0 0 0 0 0 0 0 0 0
56505- 0 0 0 0 0 0 0 0 0 14 14 14
56506- 42 42 42 90 90 90 22 22 22 2 2 6
56507- 42 42 42 2 2 6 18 18 18 218 218 218
56508-253 253 253 253 253 253 253 253 253 253 253 253
56509-253 253 253 253 253 253 253 253 253 253 253 253
56510-253 253 253 253 253 253 253 253 253 253 253 253
56511-253 253 253 253 253 253 253 253 253 253 253 253
56512-253 253 253 253 253 253 253 253 253 253 253 253
56513-253 253 253 253 253 253 250 250 250 221 221 221
56514-218 218 218 101 101 101 2 2 6 14 14 14
56515- 18 18 18 38 38 38 10 10 10 2 2 6
56516- 2 2 6 2 2 6 2 2 6 78 78 78
56517- 58 58 58 22 22 22 6 6 6 0 0 0
56518- 0 0 0 0 0 0 0 0 0 0 0 0
56519- 0 0 0 0 0 0 0 0 0 0 0 0
56520- 0 0 0 0 0 0 0 0 0 0 0 0
56521- 0 0 0 0 0 0 0 0 0 0 0 0
56522- 0 0 0 0 0 0 0 0 0 0 0 0
56523- 0 0 0 0 0 0 0 0 0 0 0 0
56524- 0 0 0 0 0 0 0 0 0 0 0 0
56525- 0 0 0 0 0 0 6 6 6 18 18 18
56526- 54 54 54 82 82 82 2 2 6 26 26 26
56527- 22 22 22 2 2 6 123 123 123 253 253 253
56528-253 253 253 253 253 253 253 253 253 253 253 253
56529-253 253 253 253 253 253 253 253 253 253 253 253
56530-253 253 253 253 253 253 253 253 253 253 253 253
56531-253 253 253 253 253 253 253 253 253 253 253 253
56532-253 253 253 253 253 253 253 253 253 253 253 253
56533-253 253 253 253 253 253 253 253 253 250 250 250
56534-238 238 238 198 198 198 6 6 6 38 38 38
56535- 58 58 58 26 26 26 38 38 38 2 2 6
56536- 2 2 6 2 2 6 2 2 6 46 46 46
56537- 78 78 78 30 30 30 10 10 10 0 0 0
56538- 0 0 0 0 0 0 0 0 0 0 0 0
56539- 0 0 0 0 0 0 0 0 0 0 0 0
56540- 0 0 0 0 0 0 0 0 0 0 0 0
56541- 0 0 0 0 0 0 0 0 0 0 0 0
56542- 0 0 0 0 0 0 0 0 0 0 0 0
56543- 0 0 0 0 0 0 0 0 0 0 0 0
56544- 0 0 0 0 0 0 0 0 0 0 0 0
56545- 0 0 0 0 0 0 10 10 10 30 30 30
56546- 74 74 74 58 58 58 2 2 6 42 42 42
56547- 2 2 6 22 22 22 231 231 231 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 250 250 250
56550-253 253 253 253 253 253 253 253 253 253 253 253
56551-253 253 253 253 253 253 253 253 253 253 253 253
56552-253 253 253 253 253 253 253 253 253 253 253 253
56553-253 253 253 253 253 253 253 253 253 253 253 253
56554-253 253 253 246 246 246 46 46 46 38 38 38
56555- 42 42 42 14 14 14 38 38 38 14 14 14
56556- 2 2 6 2 2 6 2 2 6 6 6 6
56557- 86 86 86 46 46 46 14 14 14 0 0 0
56558- 0 0 0 0 0 0 0 0 0 0 0 0
56559- 0 0 0 0 0 0 0 0 0 0 0 0
56560- 0 0 0 0 0 0 0 0 0 0 0 0
56561- 0 0 0 0 0 0 0 0 0 0 0 0
56562- 0 0 0 0 0 0 0 0 0 0 0 0
56563- 0 0 0 0 0 0 0 0 0 0 0 0
56564- 0 0 0 0 0 0 0 0 0 0 0 0
56565- 0 0 0 6 6 6 14 14 14 42 42 42
56566- 90 90 90 18 18 18 18 18 18 26 26 26
56567- 2 2 6 116 116 116 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 250 250 250 238 238 238
56570-253 253 253 253 253 253 253 253 253 253 253 253
56571-253 253 253 253 253 253 253 253 253 253 253 253
56572-253 253 253 253 253 253 253 253 253 253 253 253
56573-253 253 253 253 253 253 253 253 253 253 253 253
56574-253 253 253 253 253 253 94 94 94 6 6 6
56575- 2 2 6 2 2 6 10 10 10 34 34 34
56576- 2 2 6 2 2 6 2 2 6 2 2 6
56577- 74 74 74 58 58 58 22 22 22 6 6 6
56578- 0 0 0 0 0 0 0 0 0 0 0 0
56579- 0 0 0 0 0 0 0 0 0 0 0 0
56580- 0 0 0 0 0 0 0 0 0 0 0 0
56581- 0 0 0 0 0 0 0 0 0 0 0 0
56582- 0 0 0 0 0 0 0 0 0 0 0 0
56583- 0 0 0 0 0 0 0 0 0 0 0 0
56584- 0 0 0 0 0 0 0 0 0 0 0 0
56585- 0 0 0 10 10 10 26 26 26 66 66 66
56586- 82 82 82 2 2 6 38 38 38 6 6 6
56587- 14 14 14 210 210 210 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 246 246 246 242 242 242
56590-253 253 253 253 253 253 253 253 253 253 253 253
56591-253 253 253 253 253 253 253 253 253 253 253 253
56592-253 253 253 253 253 253 253 253 253 253 253 253
56593-253 253 253 253 253 253 253 253 253 253 253 253
56594-253 253 253 253 253 253 144 144 144 2 2 6
56595- 2 2 6 2 2 6 2 2 6 46 46 46
56596- 2 2 6 2 2 6 2 2 6 2 2 6
56597- 42 42 42 74 74 74 30 30 30 10 10 10
56598- 0 0 0 0 0 0 0 0 0 0 0 0
56599- 0 0 0 0 0 0 0 0 0 0 0 0
56600- 0 0 0 0 0 0 0 0 0 0 0 0
56601- 0 0 0 0 0 0 0 0 0 0 0 0
56602- 0 0 0 0 0 0 0 0 0 0 0 0
56603- 0 0 0 0 0 0 0 0 0 0 0 0
56604- 0 0 0 0 0 0 0 0 0 0 0 0
56605- 6 6 6 14 14 14 42 42 42 90 90 90
56606- 26 26 26 6 6 6 42 42 42 2 2 6
56607- 74 74 74 250 250 250 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 242 242 242 242 242 242
56610-253 253 253 253 253 253 253 253 253 253 253 253
56611-253 253 253 253 253 253 253 253 253 253 253 253
56612-253 253 253 253 253 253 253 253 253 253 253 253
56613-253 253 253 253 253 253 253 253 253 253 253 253
56614-253 253 253 253 253 253 182 182 182 2 2 6
56615- 2 2 6 2 2 6 2 2 6 46 46 46
56616- 2 2 6 2 2 6 2 2 6 2 2 6
56617- 10 10 10 86 86 86 38 38 38 10 10 10
56618- 0 0 0 0 0 0 0 0 0 0 0 0
56619- 0 0 0 0 0 0 0 0 0 0 0 0
56620- 0 0 0 0 0 0 0 0 0 0 0 0
56621- 0 0 0 0 0 0 0 0 0 0 0 0
56622- 0 0 0 0 0 0 0 0 0 0 0 0
56623- 0 0 0 0 0 0 0 0 0 0 0 0
56624- 0 0 0 0 0 0 0 0 0 0 0 0
56625- 10 10 10 26 26 26 66 66 66 82 82 82
56626- 2 2 6 22 22 22 18 18 18 2 2 6
56627-149 149 149 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 234 234 234 242 242 242
56630-253 253 253 253 253 253 253 253 253 253 253 253
56631-253 253 253 253 253 253 253 253 253 253 253 253
56632-253 253 253 253 253 253 253 253 253 253 253 253
56633-253 253 253 253 253 253 253 253 253 253 253 253
56634-253 253 253 253 253 253 206 206 206 2 2 6
56635- 2 2 6 2 2 6 2 2 6 38 38 38
56636- 2 2 6 2 2 6 2 2 6 2 2 6
56637- 6 6 6 86 86 86 46 46 46 14 14 14
56638- 0 0 0 0 0 0 0 0 0 0 0 0
56639- 0 0 0 0 0 0 0 0 0 0 0 0
56640- 0 0 0 0 0 0 0 0 0 0 0 0
56641- 0 0 0 0 0 0 0 0 0 0 0 0
56642- 0 0 0 0 0 0 0 0 0 0 0 0
56643- 0 0 0 0 0 0 0 0 0 0 0 0
56644- 0 0 0 0 0 0 0 0 0 6 6 6
56645- 18 18 18 46 46 46 86 86 86 18 18 18
56646- 2 2 6 34 34 34 10 10 10 6 6 6
56647-210 210 210 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 234 234 234 242 242 242
56650-253 253 253 253 253 253 253 253 253 253 253 253
56651-253 253 253 253 253 253 253 253 253 253 253 253
56652-253 253 253 253 253 253 253 253 253 253 253 253
56653-253 253 253 253 253 253 253 253 253 253 253 253
56654-253 253 253 253 253 253 221 221 221 6 6 6
56655- 2 2 6 2 2 6 6 6 6 30 30 30
56656- 2 2 6 2 2 6 2 2 6 2 2 6
56657- 2 2 6 82 82 82 54 54 54 18 18 18
56658- 6 6 6 0 0 0 0 0 0 0 0 0
56659- 0 0 0 0 0 0 0 0 0 0 0 0
56660- 0 0 0 0 0 0 0 0 0 0 0 0
56661- 0 0 0 0 0 0 0 0 0 0 0 0
56662- 0 0 0 0 0 0 0 0 0 0 0 0
56663- 0 0 0 0 0 0 0 0 0 0 0 0
56664- 0 0 0 0 0 0 0 0 0 10 10 10
56665- 26 26 26 66 66 66 62 62 62 2 2 6
56666- 2 2 6 38 38 38 10 10 10 26 26 26
56667-238 238 238 253 253 253 253 253 253 253 253 253
56668-253 253 253 253 253 253 253 253 253 253 253 253
56669-253 253 253 253 253 253 231 231 231 238 238 238
56670-253 253 253 253 253 253 253 253 253 253 253 253
56671-253 253 253 253 253 253 253 253 253 253 253 253
56672-253 253 253 253 253 253 253 253 253 253 253 253
56673-253 253 253 253 253 253 253 253 253 253 253 253
56674-253 253 253 253 253 253 231 231 231 6 6 6
56675- 2 2 6 2 2 6 10 10 10 30 30 30
56676- 2 2 6 2 2 6 2 2 6 2 2 6
56677- 2 2 6 66 66 66 58 58 58 22 22 22
56678- 6 6 6 0 0 0 0 0 0 0 0 0
56679- 0 0 0 0 0 0 0 0 0 0 0 0
56680- 0 0 0 0 0 0 0 0 0 0 0 0
56681- 0 0 0 0 0 0 0 0 0 0 0 0
56682- 0 0 0 0 0 0 0 0 0 0 0 0
56683- 0 0 0 0 0 0 0 0 0 0 0 0
56684- 0 0 0 0 0 0 0 0 0 10 10 10
56685- 38 38 38 78 78 78 6 6 6 2 2 6
56686- 2 2 6 46 46 46 14 14 14 42 42 42
56687-246 246 246 253 253 253 253 253 253 253 253 253
56688-253 253 253 253 253 253 253 253 253 253 253 253
56689-253 253 253 253 253 253 231 231 231 242 242 242
56690-253 253 253 253 253 253 253 253 253 253 253 253
56691-253 253 253 253 253 253 253 253 253 253 253 253
56692-253 253 253 253 253 253 253 253 253 253 253 253
56693-253 253 253 253 253 253 253 253 253 253 253 253
56694-253 253 253 253 253 253 234 234 234 10 10 10
56695- 2 2 6 2 2 6 22 22 22 14 14 14
56696- 2 2 6 2 2 6 2 2 6 2 2 6
56697- 2 2 6 66 66 66 62 62 62 22 22 22
56698- 6 6 6 0 0 0 0 0 0 0 0 0
56699- 0 0 0 0 0 0 0 0 0 0 0 0
56700- 0 0 0 0 0 0 0 0 0 0 0 0
56701- 0 0 0 0 0 0 0 0 0 0 0 0
56702- 0 0 0 0 0 0 0 0 0 0 0 0
56703- 0 0 0 0 0 0 0 0 0 0 0 0
56704- 0 0 0 0 0 0 6 6 6 18 18 18
56705- 50 50 50 74 74 74 2 2 6 2 2 6
56706- 14 14 14 70 70 70 34 34 34 62 62 62
56707-250 250 250 253 253 253 253 253 253 253 253 253
56708-253 253 253 253 253 253 253 253 253 253 253 253
56709-253 253 253 253 253 253 231 231 231 246 246 246
56710-253 253 253 253 253 253 253 253 253 253 253 253
56711-253 253 253 253 253 253 253 253 253 253 253 253
56712-253 253 253 253 253 253 253 253 253 253 253 253
56713-253 253 253 253 253 253 253 253 253 253 253 253
56714-253 253 253 253 253 253 234 234 234 14 14 14
56715- 2 2 6 2 2 6 30 30 30 2 2 6
56716- 2 2 6 2 2 6 2 2 6 2 2 6
56717- 2 2 6 66 66 66 62 62 62 22 22 22
56718- 6 6 6 0 0 0 0 0 0 0 0 0
56719- 0 0 0 0 0 0 0 0 0 0 0 0
56720- 0 0 0 0 0 0 0 0 0 0 0 0
56721- 0 0 0 0 0 0 0 0 0 0 0 0
56722- 0 0 0 0 0 0 0 0 0 0 0 0
56723- 0 0 0 0 0 0 0 0 0 0 0 0
56724- 0 0 0 0 0 0 6 6 6 18 18 18
56725- 54 54 54 62 62 62 2 2 6 2 2 6
56726- 2 2 6 30 30 30 46 46 46 70 70 70
56727-250 250 250 253 253 253 253 253 253 253 253 253
56728-253 253 253 253 253 253 253 253 253 253 253 253
56729-253 253 253 253 253 253 231 231 231 246 246 246
56730-253 253 253 253 253 253 253 253 253 253 253 253
56731-253 253 253 253 253 253 253 253 253 253 253 253
56732-253 253 253 253 253 253 253 253 253 253 253 253
56733-253 253 253 253 253 253 253 253 253 253 253 253
56734-253 253 253 253 253 253 226 226 226 10 10 10
56735- 2 2 6 6 6 6 30 30 30 2 2 6
56736- 2 2 6 2 2 6 2 2 6 2 2 6
56737- 2 2 6 66 66 66 58 58 58 22 22 22
56738- 6 6 6 0 0 0 0 0 0 0 0 0
56739- 0 0 0 0 0 0 0 0 0 0 0 0
56740- 0 0 0 0 0 0 0 0 0 0 0 0
56741- 0 0 0 0 0 0 0 0 0 0 0 0
56742- 0 0 0 0 0 0 0 0 0 0 0 0
56743- 0 0 0 0 0 0 0 0 0 0 0 0
56744- 0 0 0 0 0 0 6 6 6 22 22 22
56745- 58 58 58 62 62 62 2 2 6 2 2 6
56746- 2 2 6 2 2 6 30 30 30 78 78 78
56747-250 250 250 253 253 253 253 253 253 253 253 253
56748-253 253 253 253 253 253 253 253 253 253 253 253
56749-253 253 253 253 253 253 231 231 231 246 246 246
56750-253 253 253 253 253 253 253 253 253 253 253 253
56751-253 253 253 253 253 253 253 253 253 253 253 253
56752-253 253 253 253 253 253 253 253 253 253 253 253
56753-253 253 253 253 253 253 253 253 253 253 253 253
56754-253 253 253 253 253 253 206 206 206 2 2 6
56755- 22 22 22 34 34 34 18 14 6 22 22 22
56756- 26 26 26 18 18 18 6 6 6 2 2 6
56757- 2 2 6 82 82 82 54 54 54 18 18 18
56758- 6 6 6 0 0 0 0 0 0 0 0 0
56759- 0 0 0 0 0 0 0 0 0 0 0 0
56760- 0 0 0 0 0 0 0 0 0 0 0 0
56761- 0 0 0 0 0 0 0 0 0 0 0 0
56762- 0 0 0 0 0 0 0 0 0 0 0 0
56763- 0 0 0 0 0 0 0 0 0 0 0 0
56764- 0 0 0 0 0 0 6 6 6 26 26 26
56765- 62 62 62 106 106 106 74 54 14 185 133 11
56766-210 162 10 121 92 8 6 6 6 62 62 62
56767-238 238 238 253 253 253 253 253 253 253 253 253
56768-253 253 253 253 253 253 253 253 253 253 253 253
56769-253 253 253 253 253 253 231 231 231 246 246 246
56770-253 253 253 253 253 253 253 253 253 253 253 253
56771-253 253 253 253 253 253 253 253 253 253 253 253
56772-253 253 253 253 253 253 253 253 253 253 253 253
56773-253 253 253 253 253 253 253 253 253 253 253 253
56774-253 253 253 253 253 253 158 158 158 18 18 18
56775- 14 14 14 2 2 6 2 2 6 2 2 6
56776- 6 6 6 18 18 18 66 66 66 38 38 38
56777- 6 6 6 94 94 94 50 50 50 18 18 18
56778- 6 6 6 0 0 0 0 0 0 0 0 0
56779- 0 0 0 0 0 0 0 0 0 0 0 0
56780- 0 0 0 0 0 0 0 0 0 0 0 0
56781- 0 0 0 0 0 0 0 0 0 0 0 0
56782- 0 0 0 0 0 0 0 0 0 0 0 0
56783- 0 0 0 0 0 0 0 0 0 6 6 6
56784- 10 10 10 10 10 10 18 18 18 38 38 38
56785- 78 78 78 142 134 106 216 158 10 242 186 14
56786-246 190 14 246 190 14 156 118 10 10 10 10
56787- 90 90 90 238 238 238 253 253 253 253 253 253
56788-253 253 253 253 253 253 253 253 253 253 253 253
56789-253 253 253 253 253 253 231 231 231 250 250 250
56790-253 253 253 253 253 253 253 253 253 253 253 253
56791-253 253 253 253 253 253 253 253 253 253 253 253
56792-253 253 253 253 253 253 253 253 253 253 253 253
56793-253 253 253 253 253 253 253 253 253 246 230 190
56794-238 204 91 238 204 91 181 142 44 37 26 9
56795- 2 2 6 2 2 6 2 2 6 2 2 6
56796- 2 2 6 2 2 6 38 38 38 46 46 46
56797- 26 26 26 106 106 106 54 54 54 18 18 18
56798- 6 6 6 0 0 0 0 0 0 0 0 0
56799- 0 0 0 0 0 0 0 0 0 0 0 0
56800- 0 0 0 0 0 0 0 0 0 0 0 0
56801- 0 0 0 0 0 0 0 0 0 0 0 0
56802- 0 0 0 0 0 0 0 0 0 0 0 0
56803- 0 0 0 6 6 6 14 14 14 22 22 22
56804- 30 30 30 38 38 38 50 50 50 70 70 70
56805-106 106 106 190 142 34 226 170 11 242 186 14
56806-246 190 14 246 190 14 246 190 14 154 114 10
56807- 6 6 6 74 74 74 226 226 226 253 253 253
56808-253 253 253 253 253 253 253 253 253 253 253 253
56809-253 253 253 253 253 253 231 231 231 250 250 250
56810-253 253 253 253 253 253 253 253 253 253 253 253
56811-253 253 253 253 253 253 253 253 253 253 253 253
56812-253 253 253 253 253 253 253 253 253 253 253 253
56813-253 253 253 253 253 253 253 253 253 228 184 62
56814-241 196 14 241 208 19 232 195 16 38 30 10
56815- 2 2 6 2 2 6 2 2 6 2 2 6
56816- 2 2 6 6 6 6 30 30 30 26 26 26
56817-203 166 17 154 142 90 66 66 66 26 26 26
56818- 6 6 6 0 0 0 0 0 0 0 0 0
56819- 0 0 0 0 0 0 0 0 0 0 0 0
56820- 0 0 0 0 0 0 0 0 0 0 0 0
56821- 0 0 0 0 0 0 0 0 0 0 0 0
56822- 0 0 0 0 0 0 0 0 0 0 0 0
56823- 6 6 6 18 18 18 38 38 38 58 58 58
56824- 78 78 78 86 86 86 101 101 101 123 123 123
56825-175 146 61 210 150 10 234 174 13 246 186 14
56826-246 190 14 246 190 14 246 190 14 238 190 10
56827-102 78 10 2 2 6 46 46 46 198 198 198
56828-253 253 253 253 253 253 253 253 253 253 253 253
56829-253 253 253 253 253 253 234 234 234 242 242 242
56830-253 253 253 253 253 253 253 253 253 253 253 253
56831-253 253 253 253 253 253 253 253 253 253 253 253
56832-253 253 253 253 253 253 253 253 253 253 253 253
56833-253 253 253 253 253 253 253 253 253 224 178 62
56834-242 186 14 241 196 14 210 166 10 22 18 6
56835- 2 2 6 2 2 6 2 2 6 2 2 6
56836- 2 2 6 2 2 6 6 6 6 121 92 8
56837-238 202 15 232 195 16 82 82 82 34 34 34
56838- 10 10 10 0 0 0 0 0 0 0 0 0
56839- 0 0 0 0 0 0 0 0 0 0 0 0
56840- 0 0 0 0 0 0 0 0 0 0 0 0
56841- 0 0 0 0 0 0 0 0 0 0 0 0
56842- 0 0 0 0 0 0 0 0 0 0 0 0
56843- 14 14 14 38 38 38 70 70 70 154 122 46
56844-190 142 34 200 144 11 197 138 11 197 138 11
56845-213 154 11 226 170 11 242 186 14 246 190 14
56846-246 190 14 246 190 14 246 190 14 246 190 14
56847-225 175 15 46 32 6 2 2 6 22 22 22
56848-158 158 158 250 250 250 253 253 253 253 253 253
56849-253 253 253 253 253 253 253 253 253 253 253 253
56850-253 253 253 253 253 253 253 253 253 253 253 253
56851-253 253 253 253 253 253 253 253 253 253 253 253
56852-253 253 253 253 253 253 253 253 253 253 253 253
56853-253 253 253 250 250 250 242 242 242 224 178 62
56854-239 182 13 236 186 11 213 154 11 46 32 6
56855- 2 2 6 2 2 6 2 2 6 2 2 6
56856- 2 2 6 2 2 6 61 42 6 225 175 15
56857-238 190 10 236 186 11 112 100 78 42 42 42
56858- 14 14 14 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 0 0 0 0 0 0 6 6 6
56863- 22 22 22 54 54 54 154 122 46 213 154 11
56864-226 170 11 230 174 11 226 170 11 226 170 11
56865-236 178 12 242 186 14 246 190 14 246 190 14
56866-246 190 14 246 190 14 246 190 14 246 190 14
56867-241 196 14 184 144 12 10 10 10 2 2 6
56868- 6 6 6 116 116 116 242 242 242 253 253 253
56869-253 253 253 253 253 253 253 253 253 253 253 253
56870-253 253 253 253 253 253 253 253 253 253 253 253
56871-253 253 253 253 253 253 253 253 253 253 253 253
56872-253 253 253 253 253 253 253 253 253 253 253 253
56873-253 253 253 231 231 231 198 198 198 214 170 54
56874-236 178 12 236 178 12 210 150 10 137 92 6
56875- 18 14 6 2 2 6 2 2 6 2 2 6
56876- 6 6 6 70 47 6 200 144 11 236 178 12
56877-239 182 13 239 182 13 124 112 88 58 58 58
56878- 22 22 22 6 6 6 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 10 10 10
56883- 30 30 30 70 70 70 180 133 36 226 170 11
56884-239 182 13 242 186 14 242 186 14 246 186 14
56885-246 190 14 246 190 14 246 190 14 246 190 14
56886-246 190 14 246 190 14 246 190 14 246 190 14
56887-246 190 14 232 195 16 98 70 6 2 2 6
56888- 2 2 6 2 2 6 66 66 66 221 221 221
56889-253 253 253 253 253 253 253 253 253 253 253 253
56890-253 253 253 253 253 253 253 253 253 253 253 253
56891-253 253 253 253 253 253 253 253 253 253 253 253
56892-253 253 253 253 253 253 253 253 253 253 253 253
56893-253 253 253 206 206 206 198 198 198 214 166 58
56894-230 174 11 230 174 11 216 158 10 192 133 9
56895-163 110 8 116 81 8 102 78 10 116 81 8
56896-167 114 7 197 138 11 226 170 11 239 182 13
56897-242 186 14 242 186 14 162 146 94 78 78 78
56898- 34 34 34 14 14 14 6 6 6 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 6 6 6
56903- 30 30 30 78 78 78 190 142 34 226 170 11
56904-239 182 13 246 190 14 246 190 14 246 190 14
56905-246 190 14 246 190 14 246 190 14 246 190 14
56906-246 190 14 246 190 14 246 190 14 246 190 14
56907-246 190 14 241 196 14 203 166 17 22 18 6
56908- 2 2 6 2 2 6 2 2 6 38 38 38
56909-218 218 218 253 253 253 253 253 253 253 253 253
56910-253 253 253 253 253 253 253 253 253 253 253 253
56911-253 253 253 253 253 253 253 253 253 253 253 253
56912-253 253 253 253 253 253 253 253 253 253 253 253
56913-250 250 250 206 206 206 198 198 198 202 162 69
56914-226 170 11 236 178 12 224 166 10 210 150 10
56915-200 144 11 197 138 11 192 133 9 197 138 11
56916-210 150 10 226 170 11 242 186 14 246 190 14
56917-246 190 14 246 186 14 225 175 15 124 112 88
56918- 62 62 62 30 30 30 14 14 14 6 6 6
56919- 0 0 0 0 0 0 0 0 0 0 0 0
56920- 0 0 0 0 0 0 0 0 0 0 0 0
56921- 0 0 0 0 0 0 0 0 0 0 0 0
56922- 0 0 0 0 0 0 0 0 0 10 10 10
56923- 30 30 30 78 78 78 174 135 50 224 166 10
56924-239 182 13 246 190 14 246 190 14 246 190 14
56925-246 190 14 246 190 14 246 190 14 246 190 14
56926-246 190 14 246 190 14 246 190 14 246 190 14
56927-246 190 14 246 190 14 241 196 14 139 102 15
56928- 2 2 6 2 2 6 2 2 6 2 2 6
56929- 78 78 78 250 250 250 253 253 253 253 253 253
56930-253 253 253 253 253 253 253 253 253 253 253 253
56931-253 253 253 253 253 253 253 253 253 253 253 253
56932-253 253 253 253 253 253 253 253 253 253 253 253
56933-250 250 250 214 214 214 198 198 198 190 150 46
56934-219 162 10 236 178 12 234 174 13 224 166 10
56935-216 158 10 213 154 11 213 154 11 216 158 10
56936-226 170 11 239 182 13 246 190 14 246 190 14
56937-246 190 14 246 190 14 242 186 14 206 162 42
56938-101 101 101 58 58 58 30 30 30 14 14 14
56939- 6 6 6 0 0 0 0 0 0 0 0 0
56940- 0 0 0 0 0 0 0 0 0 0 0 0
56941- 0 0 0 0 0 0 0 0 0 0 0 0
56942- 0 0 0 0 0 0 0 0 0 10 10 10
56943- 30 30 30 74 74 74 174 135 50 216 158 10
56944-236 178 12 246 190 14 246 190 14 246 190 14
56945-246 190 14 246 190 14 246 190 14 246 190 14
56946-246 190 14 246 190 14 246 190 14 246 190 14
56947-246 190 14 246 190 14 241 196 14 226 184 13
56948- 61 42 6 2 2 6 2 2 6 2 2 6
56949- 22 22 22 238 238 238 253 253 253 253 253 253
56950-253 253 253 253 253 253 253 253 253 253 253 253
56951-253 253 253 253 253 253 253 253 253 253 253 253
56952-253 253 253 253 253 253 253 253 253 253 253 253
56953-253 253 253 226 226 226 187 187 187 180 133 36
56954-216 158 10 236 178 12 239 182 13 236 178 12
56955-230 174 11 226 170 11 226 170 11 230 174 11
56956-236 178 12 242 186 14 246 190 14 246 190 14
56957-246 190 14 246 190 14 246 186 14 239 182 13
56958-206 162 42 106 106 106 66 66 66 34 34 34
56959- 14 14 14 6 6 6 0 0 0 0 0 0
56960- 0 0 0 0 0 0 0 0 0 0 0 0
56961- 0 0 0 0 0 0 0 0 0 0 0 0
56962- 0 0 0 0 0 0 0 0 0 6 6 6
56963- 26 26 26 70 70 70 163 133 67 213 154 11
56964-236 178 12 246 190 14 246 190 14 246 190 14
56965-246 190 14 246 190 14 246 190 14 246 190 14
56966-246 190 14 246 190 14 246 190 14 246 190 14
56967-246 190 14 246 190 14 246 190 14 241 196 14
56968-190 146 13 18 14 6 2 2 6 2 2 6
56969- 46 46 46 246 246 246 253 253 253 253 253 253
56970-253 253 253 253 253 253 253 253 253 253 253 253
56971-253 253 253 253 253 253 253 253 253 253 253 253
56972-253 253 253 253 253 253 253 253 253 253 253 253
56973-253 253 253 221 221 221 86 86 86 156 107 11
56974-216 158 10 236 178 12 242 186 14 246 186 14
56975-242 186 14 239 182 13 239 182 13 242 186 14
56976-242 186 14 246 186 14 246 190 14 246 190 14
56977-246 190 14 246 190 14 246 190 14 246 190 14
56978-242 186 14 225 175 15 142 122 72 66 66 66
56979- 30 30 30 10 10 10 0 0 0 0 0 0
56980- 0 0 0 0 0 0 0 0 0 0 0 0
56981- 0 0 0 0 0 0 0 0 0 0 0 0
56982- 0 0 0 0 0 0 0 0 0 6 6 6
56983- 26 26 26 70 70 70 163 133 67 210 150 10
56984-236 178 12 246 190 14 246 190 14 246 190 14
56985-246 190 14 246 190 14 246 190 14 246 190 14
56986-246 190 14 246 190 14 246 190 14 246 190 14
56987-246 190 14 246 190 14 246 190 14 246 190 14
56988-232 195 16 121 92 8 34 34 34 106 106 106
56989-221 221 221 253 253 253 253 253 253 253 253 253
56990-253 253 253 253 253 253 253 253 253 253 253 253
56991-253 253 253 253 253 253 253 253 253 253 253 253
56992-253 253 253 253 253 253 253 253 253 253 253 253
56993-242 242 242 82 82 82 18 14 6 163 110 8
56994-216 158 10 236 178 12 242 186 14 246 190 14
56995-246 190 14 246 190 14 246 190 14 246 190 14
56996-246 190 14 246 190 14 246 190 14 246 190 14
56997-246 190 14 246 190 14 246 190 14 246 190 14
56998-246 190 14 246 190 14 242 186 14 163 133 67
56999- 46 46 46 18 18 18 6 6 6 0 0 0
57000- 0 0 0 0 0 0 0 0 0 0 0 0
57001- 0 0 0 0 0 0 0 0 0 0 0 0
57002- 0 0 0 0 0 0 0 0 0 10 10 10
57003- 30 30 30 78 78 78 163 133 67 210 150 10
57004-236 178 12 246 186 14 246 190 14 246 190 14
57005-246 190 14 246 190 14 246 190 14 246 190 14
57006-246 190 14 246 190 14 246 190 14 246 190 14
57007-246 190 14 246 190 14 246 190 14 246 190 14
57008-241 196 14 215 174 15 190 178 144 253 253 253
57009-253 253 253 253 253 253 253 253 253 253 253 253
57010-253 253 253 253 253 253 253 253 253 253 253 253
57011-253 253 253 253 253 253 253 253 253 253 253 253
57012-253 253 253 253 253 253 253 253 253 218 218 218
57013- 58 58 58 2 2 6 22 18 6 167 114 7
57014-216 158 10 236 178 12 246 186 14 246 190 14
57015-246 190 14 246 190 14 246 190 14 246 190 14
57016-246 190 14 246 190 14 246 190 14 246 190 14
57017-246 190 14 246 190 14 246 190 14 246 190 14
57018-246 190 14 246 186 14 242 186 14 190 150 46
57019- 54 54 54 22 22 22 6 6 6 0 0 0
57020- 0 0 0 0 0 0 0 0 0 0 0 0
57021- 0 0 0 0 0 0 0 0 0 0 0 0
57022- 0 0 0 0 0 0 0 0 0 14 14 14
57023- 38 38 38 86 86 86 180 133 36 213 154 11
57024-236 178 12 246 186 14 246 190 14 246 190 14
57025-246 190 14 246 190 14 246 190 14 246 190 14
57026-246 190 14 246 190 14 246 190 14 246 190 14
57027-246 190 14 246 190 14 246 190 14 246 190 14
57028-246 190 14 232 195 16 190 146 13 214 214 214
57029-253 253 253 253 253 253 253 253 253 253 253 253
57030-253 253 253 253 253 253 253 253 253 253 253 253
57031-253 253 253 253 253 253 253 253 253 253 253 253
57032-253 253 253 250 250 250 170 170 170 26 26 26
57033- 2 2 6 2 2 6 37 26 9 163 110 8
57034-219 162 10 239 182 13 246 186 14 246 190 14
57035-246 190 14 246 190 14 246 190 14 246 190 14
57036-246 190 14 246 190 14 246 190 14 246 190 14
57037-246 190 14 246 190 14 246 190 14 246 190 14
57038-246 186 14 236 178 12 224 166 10 142 122 72
57039- 46 46 46 18 18 18 6 6 6 0 0 0
57040- 0 0 0 0 0 0 0 0 0 0 0 0
57041- 0 0 0 0 0 0 0 0 0 0 0 0
57042- 0 0 0 0 0 0 6 6 6 18 18 18
57043- 50 50 50 109 106 95 192 133 9 224 166 10
57044-242 186 14 246 190 14 246 190 14 246 190 14
57045-246 190 14 246 190 14 246 190 14 246 190 14
57046-246 190 14 246 190 14 246 190 14 246 190 14
57047-246 190 14 246 190 14 246 190 14 246 190 14
57048-242 186 14 226 184 13 210 162 10 142 110 46
57049-226 226 226 253 253 253 253 253 253 253 253 253
57050-253 253 253 253 253 253 253 253 253 253 253 253
57051-253 253 253 253 253 253 253 253 253 253 253 253
57052-198 198 198 66 66 66 2 2 6 2 2 6
57053- 2 2 6 2 2 6 50 34 6 156 107 11
57054-219 162 10 239 182 13 246 186 14 246 190 14
57055-246 190 14 246 190 14 246 190 14 246 190 14
57056-246 190 14 246 190 14 246 190 14 246 190 14
57057-246 190 14 246 190 14 246 190 14 242 186 14
57058-234 174 13 213 154 11 154 122 46 66 66 66
57059- 30 30 30 10 10 10 0 0 0 0 0 0
57060- 0 0 0 0 0 0 0 0 0 0 0 0
57061- 0 0 0 0 0 0 0 0 0 0 0 0
57062- 0 0 0 0 0 0 6 6 6 22 22 22
57063- 58 58 58 154 121 60 206 145 10 234 174 13
57064-242 186 14 246 186 14 246 190 14 246 190 14
57065-246 190 14 246 190 14 246 190 14 246 190 14
57066-246 190 14 246 190 14 246 190 14 246 190 14
57067-246 190 14 246 190 14 246 190 14 246 190 14
57068-246 186 14 236 178 12 210 162 10 163 110 8
57069- 61 42 6 138 138 138 218 218 218 250 250 250
57070-253 253 253 253 253 253 253 253 253 250 250 250
57071-242 242 242 210 210 210 144 144 144 66 66 66
57072- 6 6 6 2 2 6 2 2 6 2 2 6
57073- 2 2 6 2 2 6 61 42 6 163 110 8
57074-216 158 10 236 178 12 246 190 14 246 190 14
57075-246 190 14 246 190 14 246 190 14 246 190 14
57076-246 190 14 246 190 14 246 190 14 246 190 14
57077-246 190 14 239 182 13 230 174 11 216 158 10
57078-190 142 34 124 112 88 70 70 70 38 38 38
57079- 18 18 18 6 6 6 0 0 0 0 0 0
57080- 0 0 0 0 0 0 0 0 0 0 0 0
57081- 0 0 0 0 0 0 0 0 0 0 0 0
57082- 0 0 0 0 0 0 6 6 6 22 22 22
57083- 62 62 62 168 124 44 206 145 10 224 166 10
57084-236 178 12 239 182 13 242 186 14 242 186 14
57085-246 186 14 246 190 14 246 190 14 246 190 14
57086-246 190 14 246 190 14 246 190 14 246 190 14
57087-246 190 14 246 190 14 246 190 14 246 190 14
57088-246 190 14 236 178 12 216 158 10 175 118 6
57089- 80 54 7 2 2 6 6 6 6 30 30 30
57090- 54 54 54 62 62 62 50 50 50 38 38 38
57091- 14 14 14 2 2 6 2 2 6 2 2 6
57092- 2 2 6 2 2 6 2 2 6 2 2 6
57093- 2 2 6 6 6 6 80 54 7 167 114 7
57094-213 154 11 236 178 12 246 190 14 246 190 14
57095-246 190 14 246 190 14 246 190 14 246 190 14
57096-246 190 14 242 186 14 239 182 13 239 182 13
57097-230 174 11 210 150 10 174 135 50 124 112 88
57098- 82 82 82 54 54 54 34 34 34 18 18 18
57099- 6 6 6 0 0 0 0 0 0 0 0 0
57100- 0 0 0 0 0 0 0 0 0 0 0 0
57101- 0 0 0 0 0 0 0 0 0 0 0 0
57102- 0 0 0 0 0 0 6 6 6 18 18 18
57103- 50 50 50 158 118 36 192 133 9 200 144 11
57104-216 158 10 219 162 10 224 166 10 226 170 11
57105-230 174 11 236 178 12 239 182 13 239 182 13
57106-242 186 14 246 186 14 246 190 14 246 190 14
57107-246 190 14 246 190 14 246 190 14 246 190 14
57108-246 186 14 230 174 11 210 150 10 163 110 8
57109-104 69 6 10 10 10 2 2 6 2 2 6
57110- 2 2 6 2 2 6 2 2 6 2 2 6
57111- 2 2 6 2 2 6 2 2 6 2 2 6
57112- 2 2 6 2 2 6 2 2 6 2 2 6
57113- 2 2 6 6 6 6 91 60 6 167 114 7
57114-206 145 10 230 174 11 242 186 14 246 190 14
57115-246 190 14 246 190 14 246 186 14 242 186 14
57116-239 182 13 230 174 11 224 166 10 213 154 11
57117-180 133 36 124 112 88 86 86 86 58 58 58
57118- 38 38 38 22 22 22 10 10 10 6 6 6
57119- 0 0 0 0 0 0 0 0 0 0 0 0
57120- 0 0 0 0 0 0 0 0 0 0 0 0
57121- 0 0 0 0 0 0 0 0 0 0 0 0
57122- 0 0 0 0 0 0 0 0 0 14 14 14
57123- 34 34 34 70 70 70 138 110 50 158 118 36
57124-167 114 7 180 123 7 192 133 9 197 138 11
57125-200 144 11 206 145 10 213 154 11 219 162 10
57126-224 166 10 230 174 11 239 182 13 242 186 14
57127-246 186 14 246 186 14 246 186 14 246 186 14
57128-239 182 13 216 158 10 185 133 11 152 99 6
57129-104 69 6 18 14 6 2 2 6 2 2 6
57130- 2 2 6 2 2 6 2 2 6 2 2 6
57131- 2 2 6 2 2 6 2 2 6 2 2 6
57132- 2 2 6 2 2 6 2 2 6 2 2 6
57133- 2 2 6 6 6 6 80 54 7 152 99 6
57134-192 133 9 219 162 10 236 178 12 239 182 13
57135-246 186 14 242 186 14 239 182 13 236 178 12
57136-224 166 10 206 145 10 192 133 9 154 121 60
57137- 94 94 94 62 62 62 42 42 42 22 22 22
57138- 14 14 14 6 6 6 0 0 0 0 0 0
57139- 0 0 0 0 0 0 0 0 0 0 0 0
57140- 0 0 0 0 0 0 0 0 0 0 0 0
57141- 0 0 0 0 0 0 0 0 0 0 0 0
57142- 0 0 0 0 0 0 0 0 0 6 6 6
57143- 18 18 18 34 34 34 58 58 58 78 78 78
57144-101 98 89 124 112 88 142 110 46 156 107 11
57145-163 110 8 167 114 7 175 118 6 180 123 7
57146-185 133 11 197 138 11 210 150 10 219 162 10
57147-226 170 11 236 178 12 236 178 12 234 174 13
57148-219 162 10 197 138 11 163 110 8 130 83 6
57149- 91 60 6 10 10 10 2 2 6 2 2 6
57150- 18 18 18 38 38 38 38 38 38 38 38 38
57151- 38 38 38 38 38 38 38 38 38 38 38 38
57152- 38 38 38 38 38 38 26 26 26 2 2 6
57153- 2 2 6 6 6 6 70 47 6 137 92 6
57154-175 118 6 200 144 11 219 162 10 230 174 11
57155-234 174 13 230 174 11 219 162 10 210 150 10
57156-192 133 9 163 110 8 124 112 88 82 82 82
57157- 50 50 50 30 30 30 14 14 14 6 6 6
57158- 0 0 0 0 0 0 0 0 0 0 0 0
57159- 0 0 0 0 0 0 0 0 0 0 0 0
57160- 0 0 0 0 0 0 0 0 0 0 0 0
57161- 0 0 0 0 0 0 0 0 0 0 0 0
57162- 0 0 0 0 0 0 0 0 0 0 0 0
57163- 6 6 6 14 14 14 22 22 22 34 34 34
57164- 42 42 42 58 58 58 74 74 74 86 86 86
57165-101 98 89 122 102 70 130 98 46 121 87 25
57166-137 92 6 152 99 6 163 110 8 180 123 7
57167-185 133 11 197 138 11 206 145 10 200 144 11
57168-180 123 7 156 107 11 130 83 6 104 69 6
57169- 50 34 6 54 54 54 110 110 110 101 98 89
57170- 86 86 86 82 82 82 78 78 78 78 78 78
57171- 78 78 78 78 78 78 78 78 78 78 78 78
57172- 78 78 78 82 82 82 86 86 86 94 94 94
57173-106 106 106 101 101 101 86 66 34 124 80 6
57174-156 107 11 180 123 7 192 133 9 200 144 11
57175-206 145 10 200 144 11 192 133 9 175 118 6
57176-139 102 15 109 106 95 70 70 70 42 42 42
57177- 22 22 22 10 10 10 0 0 0 0 0 0
57178- 0 0 0 0 0 0 0 0 0 0 0 0
57179- 0 0 0 0 0 0 0 0 0 0 0 0
57180- 0 0 0 0 0 0 0 0 0 0 0 0
57181- 0 0 0 0 0 0 0 0 0 0 0 0
57182- 0 0 0 0 0 0 0 0 0 0 0 0
57183- 0 0 0 0 0 0 6 6 6 10 10 10
57184- 14 14 14 22 22 22 30 30 30 38 38 38
57185- 50 50 50 62 62 62 74 74 74 90 90 90
57186-101 98 89 112 100 78 121 87 25 124 80 6
57187-137 92 6 152 99 6 152 99 6 152 99 6
57188-138 86 6 124 80 6 98 70 6 86 66 30
57189-101 98 89 82 82 82 58 58 58 46 46 46
57190- 38 38 38 34 34 34 34 34 34 34 34 34
57191- 34 34 34 34 34 34 34 34 34 34 34 34
57192- 34 34 34 34 34 34 38 38 38 42 42 42
57193- 54 54 54 82 82 82 94 86 76 91 60 6
57194-134 86 6 156 107 11 167 114 7 175 118 6
57195-175 118 6 167 114 7 152 99 6 121 87 25
57196-101 98 89 62 62 62 34 34 34 18 18 18
57197- 6 6 6 0 0 0 0 0 0 0 0 0
57198- 0 0 0 0 0 0 0 0 0 0 0 0
57199- 0 0 0 0 0 0 0 0 0 0 0 0
57200- 0 0 0 0 0 0 0 0 0 0 0 0
57201- 0 0 0 0 0 0 0 0 0 0 0 0
57202- 0 0 0 0 0 0 0 0 0 0 0 0
57203- 0 0 0 0 0 0 0 0 0 0 0 0
57204- 0 0 0 6 6 6 6 6 6 10 10 10
57205- 18 18 18 22 22 22 30 30 30 42 42 42
57206- 50 50 50 66 66 66 86 86 86 101 98 89
57207-106 86 58 98 70 6 104 69 6 104 69 6
57208-104 69 6 91 60 6 82 62 34 90 90 90
57209- 62 62 62 38 38 38 22 22 22 14 14 14
57210- 10 10 10 10 10 10 10 10 10 10 10 10
57211- 10 10 10 10 10 10 6 6 6 10 10 10
57212- 10 10 10 10 10 10 10 10 10 14 14 14
57213- 22 22 22 42 42 42 70 70 70 89 81 66
57214- 80 54 7 104 69 6 124 80 6 137 92 6
57215-134 86 6 116 81 8 100 82 52 86 86 86
57216- 58 58 58 30 30 30 14 14 14 6 6 6
57217- 0 0 0 0 0 0 0 0 0 0 0 0
57218- 0 0 0 0 0 0 0 0 0 0 0 0
57219- 0 0 0 0 0 0 0 0 0 0 0 0
57220- 0 0 0 0 0 0 0 0 0 0 0 0
57221- 0 0 0 0 0 0 0 0 0 0 0 0
57222- 0 0 0 0 0 0 0 0 0 0 0 0
57223- 0 0 0 0 0 0 0 0 0 0 0 0
57224- 0 0 0 0 0 0 0 0 0 0 0 0
57225- 0 0 0 6 6 6 10 10 10 14 14 14
57226- 18 18 18 26 26 26 38 38 38 54 54 54
57227- 70 70 70 86 86 86 94 86 76 89 81 66
57228- 89 81 66 86 86 86 74 74 74 50 50 50
57229- 30 30 30 14 14 14 6 6 6 0 0 0
57230- 0 0 0 0 0 0 0 0 0 0 0 0
57231- 0 0 0 0 0 0 0 0 0 0 0 0
57232- 0 0 0 0 0 0 0 0 0 0 0 0
57233- 6 6 6 18 18 18 34 34 34 58 58 58
57234- 82 82 82 89 81 66 89 81 66 89 81 66
57235- 94 86 66 94 86 76 74 74 74 50 50 50
57236- 26 26 26 14 14 14 6 6 6 0 0 0
57237- 0 0 0 0 0 0 0 0 0 0 0 0
57238- 0 0 0 0 0 0 0 0 0 0 0 0
57239- 0 0 0 0 0 0 0 0 0 0 0 0
57240- 0 0 0 0 0 0 0 0 0 0 0 0
57241- 0 0 0 0 0 0 0 0 0 0 0 0
57242- 0 0 0 0 0 0 0 0 0 0 0 0
57243- 0 0 0 0 0 0 0 0 0 0 0 0
57244- 0 0 0 0 0 0 0 0 0 0 0 0
57245- 0 0 0 0 0 0 0 0 0 0 0 0
57246- 6 6 6 6 6 6 14 14 14 18 18 18
57247- 30 30 30 38 38 38 46 46 46 54 54 54
57248- 50 50 50 42 42 42 30 30 30 18 18 18
57249- 10 10 10 0 0 0 0 0 0 0 0 0
57250- 0 0 0 0 0 0 0 0 0 0 0 0
57251- 0 0 0 0 0 0 0 0 0 0 0 0
57252- 0 0 0 0 0 0 0 0 0 0 0 0
57253- 0 0 0 6 6 6 14 14 14 26 26 26
57254- 38 38 38 50 50 50 58 58 58 58 58 58
57255- 54 54 54 42 42 42 30 30 30 18 18 18
57256- 10 10 10 0 0 0 0 0 0 0 0 0
57257- 0 0 0 0 0 0 0 0 0 0 0 0
57258- 0 0 0 0 0 0 0 0 0 0 0 0
57259- 0 0 0 0 0 0 0 0 0 0 0 0
57260- 0 0 0 0 0 0 0 0 0 0 0 0
57261- 0 0 0 0 0 0 0 0 0 0 0 0
57262- 0 0 0 0 0 0 0 0 0 0 0 0
57263- 0 0 0 0 0 0 0 0 0 0 0 0
57264- 0 0 0 0 0 0 0 0 0 0 0 0
57265- 0 0 0 0 0 0 0 0 0 0 0 0
57266- 0 0 0 0 0 0 0 0 0 6 6 6
57267- 6 6 6 10 10 10 14 14 14 18 18 18
57268- 18 18 18 14 14 14 10 10 10 6 6 6
57269- 0 0 0 0 0 0 0 0 0 0 0 0
57270- 0 0 0 0 0 0 0 0 0 0 0 0
57271- 0 0 0 0 0 0 0 0 0 0 0 0
57272- 0 0 0 0 0 0 0 0 0 0 0 0
57273- 0 0 0 0 0 0 0 0 0 6 6 6
57274- 14 14 14 18 18 18 22 22 22 22 22 22
57275- 18 18 18 14 14 14 10 10 10 6 6 6
57276- 0 0 0 0 0 0 0 0 0 0 0 0
57277- 0 0 0 0 0 0 0 0 0 0 0 0
57278- 0 0 0 0 0 0 0 0 0 0 0 0
57279- 0 0 0 0 0 0 0 0 0 0 0 0
57280- 0 0 0 0 0 0 0 0 0 0 0 0
57281+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57284+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57285+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57288+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57292+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57293+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57294+4 4 4 4 4 4
57295+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57298+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57299+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57302+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57306+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57307+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57308+4 4 4 4 4 4
57309+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57312+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57313+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57316+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57320+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57321+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57322+4 4 4 4 4 4
57323+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57326+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57327+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57330+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57335+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57336+4 4 4 4 4 4
57337+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57340+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57344+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57349+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57350+4 4 4 4 4 4
57351+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57354+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57358+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57360+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57363+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57364+4 4 4 4 4 4
57365+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57366+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57367+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57368+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57369+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
57370+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
57371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57372+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57374+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
57375+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57376+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
57377+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57378+4 4 4 4 4 4
57379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57381+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57382+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57383+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
57384+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
57385+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57386+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57387+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57388+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
57389+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
57390+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
57391+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57392+4 4 4 4 4 4
57393+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57395+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57396+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57397+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
57398+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
57399+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57400+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57401+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57402+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
57403+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
57404+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
57405+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
57406+4 4 4 4 4 4
57407+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57408+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57409+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57410+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
57411+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
57412+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
57413+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
57414+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57415+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57416+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
57417+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
57418+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
57419+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
57420+4 4 4 4 4 4
57421+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57422+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57423+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57424+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
57425+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
57426+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
57427+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
57428+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
57429+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
57430+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
57431+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
57432+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
57433+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
57434+4 4 4 4 4 4
57435+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57436+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57437+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
57438+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
57439+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
57440+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
57441+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
57442+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
57443+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
57444+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
57445+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
57446+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
57447+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
57448+4 4 4 4 4 4
57449+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57450+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57451+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
57452+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
57453+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
57454+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
57455+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
57456+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
57457+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
57458+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
57459+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
57460+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
57461+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
57462+4 4 4 4 4 4
57463+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57464+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57465+4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
57466+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
57467+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
57468+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
57469+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
57470+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
57471+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
57472+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
57473+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
57474+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
57475+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
57476+4 4 4 4 4 4
57477+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57478+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57479+4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
57480+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
57481+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
57482+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
57483+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
57484+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
57485+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
57486+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
57487+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
57488+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
57489+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
57490+4 4 4 4 4 4
57491+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57492+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57493+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
57494+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
57495+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
57496+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
57497+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
57498+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
57499+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
57500+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
57501+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
57502+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
57503+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
57504+4 4 4 4 4 4
57505+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57506+4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
57507+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
57508+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
57509+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
57510+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
57511+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
57512+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
57513+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
57514+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
57515+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
57516+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
57517+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
57518+4 4 4 4 4 4
57519+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57520+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
57521+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
57522+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
57523+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
57524+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
57525+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
57526+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
57527+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
57528+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
57529+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
57530+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
57531+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
57532+0 0 0 4 4 4
57533+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
57534+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
57535+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
57536+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
57537+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
57538+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
57539+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
57540+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
57541+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
57542+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
57543+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
57544+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
57545+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
57546+2 0 0 0 0 0
57547+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
57548+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
57549+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
57550+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
57551+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
57552+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
57553+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
57554+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
57555+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
57556+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
57557+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
57558+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
57559+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
57560+37 38 37 0 0 0
57561+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57562+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
57563+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
57564+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
57565+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
57566+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
57567+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
57568+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
57569+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
57570+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
57571+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
57572+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
57573+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
57574+85 115 134 4 0 0
57575+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
57576+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
57577+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
57578+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
57579+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
57580+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
57581+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
57582+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
57583+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
57584+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
57585+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
57586+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
57587+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
57588+60 73 81 4 0 0
57589+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
57590+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
57591+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
57592+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
57593+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
57594+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
57595+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
57596+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
57597+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
57598+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
57599+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
57600+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
57601+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
57602+16 19 21 4 0 0
57603+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
57604+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
57605+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
57606+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
57607+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
57608+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
57609+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
57610+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
57611+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
57612+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
57613+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
57614+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
57615+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
57616+4 0 0 4 3 3
57617+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
57618+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
57619+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
57620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
57621+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
57622+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
57623+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
57624+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
57625+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
57626+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
57627+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
57628+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
57629+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
57630+3 2 2 4 4 4
57631+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
57632+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
57633+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
57634+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
57635+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
57636+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
57637+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
57638+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
57639+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
57640+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
57641+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
57642+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
57643+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
57644+4 4 4 4 4 4
57645+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
57646+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
57647+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
57648+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
57649+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
57650+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
57651+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
57652+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
57653+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
57654+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
57655+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
57656+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
57657+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
57658+4 4 4 4 4 4
57659+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
57660+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
57661+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
57662+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
57663+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
57664+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57665+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
57666+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
57667+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
57668+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
57669+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
57670+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
57671+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
57672+5 5 5 5 5 5
57673+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
57674+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
57675+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
57676+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
57677+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
57678+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57679+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
57680+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
57681+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
57682+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
57683+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
57684+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
57685+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
57686+5 5 5 4 4 4
57687+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
57688+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
57689+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
57690+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
57691+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57692+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
57693+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
57694+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
57695+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
57696+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
57697+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
57698+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
57699+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57700+4 4 4 4 4 4
57701+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
57702+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
57703+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
57704+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
57705+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
57706+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57707+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57708+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
57709+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
57710+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
57711+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
57712+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
57713+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57714+4 4 4 4 4 4
57715+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
57716+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
57717+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
57718+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
57719+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57720+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
57721+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
57722+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
57723+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
57724+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
57725+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
57726+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57727+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57728+4 4 4 4 4 4
57729+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
57730+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
57731+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
57732+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
57733+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57734+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57735+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
57736+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
57737+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
57738+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
57739+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
57740+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57741+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57742+4 4 4 4 4 4
57743+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
57744+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
57745+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
57746+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
57747+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57748+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
57749+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
57750+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
57751+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
57752+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
57753+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57754+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57755+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57756+4 4 4 4 4 4
57757+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
57758+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
57759+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
57760+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
57761+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
57762+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
57763+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
57764+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
57765+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
57766+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
57767+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
57768+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57769+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57770+4 4 4 4 4 4
57771+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
57772+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
57773+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
57774+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
57775+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
57776+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
57777+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
57778+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
57779+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
57780+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
57781+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
57782+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57783+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57784+4 4 4 4 4 4
57785+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
57786+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
57787+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
57788+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57789+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
57790+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
57791+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
57792+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
57793+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
57794+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
57795+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57796+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57797+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57798+4 4 4 4 4 4
57799+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
57800+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
57801+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
57802+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57803+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57804+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
57805+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
57806+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
57807+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
57808+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
57809+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57810+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57811+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57812+4 4 4 4 4 4
57813+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
57814+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
57815+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57816+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
57817+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57818+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
57819+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
57820+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
57821+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
57822+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
57823+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57824+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57825+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57826+4 4 4 4 4 4
57827+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
57828+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
57829+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57830+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
57831+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57832+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
57833+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
57834+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
57835+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57836+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57837+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57838+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57839+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57840+4 4 4 4 4 4
57841+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57842+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
57843+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
57844+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
57845+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
57846+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
57847+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
57848+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
57849+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57850+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57851+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57852+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57853+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57854+4 4 4 4 4 4
57855+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
57856+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
57857+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
57858+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
57859+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57860+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
57861+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
57862+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
57863+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57864+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57865+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57866+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57867+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57868+4 4 4 4 4 4
57869+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
57870+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
57871+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57872+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
57873+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
57874+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
57875+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
57876+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
57877+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57878+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57879+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57880+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57881+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57882+4 4 4 4 4 4
57883+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
57884+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
57885+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57886+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
57887+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
57888+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
57889+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
57890+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
57891+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
57892+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57893+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57894+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57895+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57896+4 4 4 4 4 4
57897+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57898+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
57899+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
57900+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
57901+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
57902+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
57903+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
57904+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
57905+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57906+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57907+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57908+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57909+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57910+4 4 4 4 4 4
57911+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
57912+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
57913+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57914+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
57915+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
57916+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
57917+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
57918+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
57919+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
57920+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57921+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57922+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57923+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57924+4 4 4 4 4 4
57925+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
57926+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
57927+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
57928+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
57929+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
57930+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
57931+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
57932+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
57933+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57934+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57935+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57936+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57937+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57938+4 4 4 4 4 4
57939+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57940+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
57941+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
57942+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
57943+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
57944+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
57945+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
57946+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
57947+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57948+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57949+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57950+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57951+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57952+4 4 4 4 4 4
57953+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57954+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
57955+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
57956+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
57957+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
57958+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
57959+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57960+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
57961+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
57962+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57963+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57964+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57965+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57966+4 4 4 4 4 4
57967+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57968+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
57969+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
57970+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
57971+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
57972+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
57973+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
57974+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
57975+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
57976+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57977+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
57978+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
57980+4 4 4 4 4 4
57981+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
57982+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
57983+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
57984+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
57985+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
57986+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
57987+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
57988+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
57989+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
57990+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
57991+0 0 0 3 3 3 5 5 5 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
57995+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
57996+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
57997+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
57998+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
57999+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
58000+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
58001+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
58002+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
58003+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
58004+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58005+0 0 0 3 3 3 5 5 5 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
58009+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
58010+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
58011+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
58012+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
58013+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
58014+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
58015+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
58016+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
58017+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
58018+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58019+0 0 0 3 3 3 5 5 5 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
58023+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
58024+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
58025+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
58026+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
58027+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
58028+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
58029+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
58030+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
58031+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
58032+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
58033+0 0 0 3 3 3 5 5 5 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
58037+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
58038+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
58039+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
58040+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
58041+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
58042+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
58043+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
58044+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
58045+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
58046+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
58047+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58048+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58049+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58050+4 4 4 4 4 4
58051+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
58052+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
58053+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
58054+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
58055+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
58056+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
58057+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
58058+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
58059+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
58060+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
58061+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58062+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58063+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58064+4 4 4 4 4 4
58065+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
58066+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
58067+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
58068+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
58069+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
58070+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
58071+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58072+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
58073+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
58074+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
58075+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58076+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58077+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58078+4 4 4 4 4 4
58079+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
58080+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
58081+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
58082+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
58083+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
58084+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
58085+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
58086+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
58087+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
58088+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
58089+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58090+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58091+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58092+4 4 4 4 4 4
58093+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
58094+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
58095+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58096+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
58097+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
58098+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
58099+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
58100+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
58101+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
58102+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
58103+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58105+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58106+4 4 4 4 4 4
58107+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58108+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
58109+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
58110+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
58111+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
58112+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
58113+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
58114+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
58115+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
58116+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58117+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58119+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58120+4 4 4 4 4 4
58121+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
58122+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
58123+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
58124+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
58125+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
58126+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
58127+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
58128+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
58129+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
58130+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
58131+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58133+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58134+4 4 4 4 4 4
58135+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
58136+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
58137+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
58138+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
58139+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
58140+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
58141+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
58142+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
58143+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
58144+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58145+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58147+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58148+4 4 4 4 4 4
58149+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
58150+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58151+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
58152+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
58153+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
58154+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
58155+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
58156+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
58157+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
58158+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58159+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58161+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58162+4 4 4 4 4 4
58163+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
58164+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
58165+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
58166+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
58167+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
58168+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
58169+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
58170+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
58171+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
58172+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58173+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58175+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58176+4 4 4 4 4 4
58177+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58178+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
58179+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
58180+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
58181+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
58182+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
58183+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
58184+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
58185+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58186+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58187+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58189+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58190+4 4 4 4 4 4
58191+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
58192+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
58193+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58194+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
58195+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
58196+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
58197+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
58198+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
58199+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58200+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58201+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58203+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58204+4 4 4 4 4 4
58205+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58206+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
58207+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
58208+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
58209+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
58210+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
58211+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
58212+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
58213+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58214+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58215+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58217+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58218+4 4 4 4 4 4
58219+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58220+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
58221+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58222+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
58223+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
58224+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
58225+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
58226+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
58227+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58228+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58229+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58231+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58232+4 4 4 4 4 4
58233+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58234+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
58235+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
58236+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
58237+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
58238+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
58239+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
58240+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
58241+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58242+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58245+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58246+4 4 4 4 4 4
58247+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58248+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
58249+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
58250+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58251+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
58252+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
58253+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
58254+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58255+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58256+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58259+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58260+4 4 4 4 4 4
58261+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58262+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58263+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58264+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
58265+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
58266+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
58267+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
58268+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
58269+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58270+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58273+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58274+4 4 4 4 4 4
58275+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58276+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58277+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58278+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58279+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
58280+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
58281+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
58282+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58283+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58284+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58285+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58287+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58288+4 4 4 4 4 4
58289+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58290+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58291+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58292+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
58293+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
58294+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
58295+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
58296+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58297+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58298+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58299+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58301+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58302+4 4 4 4 4 4
58303+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58304+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58305+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58306+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
58307+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
58308+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
58309+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
58310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58311+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58312+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58313+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58315+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58316+4 4 4 4 4 4
58317+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58318+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58319+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58320+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
58321+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
58322+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
58323+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
58324+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58325+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58326+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58327+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58329+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58330+4 4 4 4 4 4
58331+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58332+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58333+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58334+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
58335+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
58336+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
58337+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
58338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58339+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58340+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58343+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58344+4 4 4 4 4 4
58345+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58346+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58347+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58348+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58349+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
58350+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
58351+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
58352+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58353+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58354+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58357+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58358+4 4 4 4 4 4
58359+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58360+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58361+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58362+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58363+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
58364+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
58365+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58366+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58367+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58368+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58369+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58371+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58372+4 4 4 4 4 4
58373+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58374+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58375+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58376+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58377+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
58378+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
58379+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58380+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58381+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58382+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58385+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58386+4 4 4 4 4 4
58387+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58388+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58390+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58391+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
58392+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
58393+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58394+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58395+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58396+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58399+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
58400+4 4 4 4 4 4
58401diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
58402index fef20db..d28b1ab 100644
58403--- a/drivers/xen/xenfs/xenstored.c
58404+++ b/drivers/xen/xenfs/xenstored.c
58405@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
58406 static int xsd_kva_open(struct inode *inode, struct file *file)
58407 {
58408 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
58409+#ifdef CONFIG_GRKERNSEC_HIDESYM
58410+ NULL);
58411+#else
58412 xen_store_interface);
58413+#endif
58414+
58415 if (!file->private_data)
58416 return -ENOMEM;
58417 return 0;
58418diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
58419index cc1cfae..41158ad 100644
58420--- a/fs/9p/vfs_addr.c
58421+++ b/fs/9p/vfs_addr.c
58422@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
58423
58424 retval = v9fs_file_write_internal(inode,
58425 v9inode->writeback_fid,
58426- (__force const char __user *)buffer,
58427+ (const char __force_user *)buffer,
58428 len, &offset, 0);
58429 if (retval > 0)
58430 retval = 0;
58431diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
58432index 7fa4f7a..a7ebf8c 100644
58433--- a/fs/9p/vfs_inode.c
58434+++ b/fs/9p/vfs_inode.c
58435@@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
58436 void
58437 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
58438 {
58439- char *s = nd_get_link(nd);
58440+ const char *s = nd_get_link(nd);
58441
58442 p9_debug(P9_DEBUG_VFS, " %s %s\n",
58443 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
58444diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
58445index 370b24c..ff0be7b 100644
58446--- a/fs/Kconfig.binfmt
58447+++ b/fs/Kconfig.binfmt
58448@@ -103,7 +103,7 @@ config HAVE_AOUT
58449
58450 config BINFMT_AOUT
58451 tristate "Kernel support for a.out and ECOFF binaries"
58452- depends on HAVE_AOUT
58453+ depends on HAVE_AOUT && BROKEN
58454 ---help---
58455 A.out (Assembler.OUTput) is a set of formats for libraries and
58456 executables used in the earliest versions of UNIX. Linux used
58457diff --git a/fs/afs/inode.c b/fs/afs/inode.c
58458index 2946712..f737435 100644
58459--- a/fs/afs/inode.c
58460+++ b/fs/afs/inode.c
58461@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58462 struct afs_vnode *vnode;
58463 struct super_block *sb;
58464 struct inode *inode;
58465- static atomic_t afs_autocell_ino;
58466+ static atomic_unchecked_t afs_autocell_ino;
58467
58468 _enter("{%x:%u},%*.*s,",
58469 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
58470@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
58471 data.fid.unique = 0;
58472 data.fid.vnode = 0;
58473
58474- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
58475+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
58476 afs_iget5_autocell_test, afs_iget5_set,
58477 &data);
58478 if (!inode) {
58479diff --git a/fs/aio.c b/fs/aio.c
58480index 7337500..2058af6 100644
58481--- a/fs/aio.c
58482+++ b/fs/aio.c
58483@@ -380,7 +380,7 @@ static int aio_setup_ring(struct kioctx *ctx)
58484 size += sizeof(struct io_event) * nr_events;
58485
58486 nr_pages = PFN_UP(size);
58487- if (nr_pages < 0)
58488+ if (nr_pages <= 0)
58489 return -EINVAL;
58490
58491 file = aio_private_file(ctx, nr_pages);
58492diff --git a/fs/attr.c b/fs/attr.c
58493index 6530ced..4a827e2 100644
58494--- a/fs/attr.c
58495+++ b/fs/attr.c
58496@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
58497 unsigned long limit;
58498
58499 limit = rlimit(RLIMIT_FSIZE);
58500+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
58501 if (limit != RLIM_INFINITY && offset > limit)
58502 goto out_sig;
58503 if (offset > inode->i_sb->s_maxbytes)
58504diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
58505index 116fd38..c04182da 100644
58506--- a/fs/autofs4/waitq.c
58507+++ b/fs/autofs4/waitq.c
58508@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
58509 {
58510 unsigned long sigpipe, flags;
58511 mm_segment_t fs;
58512- const char *data = (const char *)addr;
58513+ const char __user *data = (const char __force_user *)addr;
58514 ssize_t wr = 0;
58515
58516 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
58517@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
58518 return 1;
58519 }
58520
58521+#ifdef CONFIG_GRKERNSEC_HIDESYM
58522+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
58523+#endif
58524+
58525 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58526 enum autofs_notify notify)
58527 {
58528@@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
58529
58530 /* If this is a direct mount request create a dummy name */
58531 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
58532+#ifdef CONFIG_GRKERNSEC_HIDESYM
58533+ /* this name does get written to userland via autofs4_write() */
58534+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
58535+#else
58536 qstr.len = sprintf(name, "%p", dentry);
58537+#endif
58538 else {
58539 qstr.len = autofs4_getpath(sbi, dentry, &name);
58540 if (!qstr.len) {
58541diff --git a/fs/befs/endian.h b/fs/befs/endian.h
58542index 2722387..56059b5 100644
58543--- a/fs/befs/endian.h
58544+++ b/fs/befs/endian.h
58545@@ -11,7 +11,7 @@
58546
58547 #include <asm/byteorder.h>
58548
58549-static inline u64
58550+static inline u64 __intentional_overflow(-1)
58551 fs64_to_cpu(const struct super_block *sb, fs64 n)
58552 {
58553 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58554@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
58555 return (__force fs64)cpu_to_be64(n);
58556 }
58557
58558-static inline u32
58559+static inline u32 __intentional_overflow(-1)
58560 fs32_to_cpu(const struct super_block *sb, fs32 n)
58561 {
58562 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58563@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
58564 return (__force fs32)cpu_to_be32(n);
58565 }
58566
58567-static inline u16
58568+static inline u16 __intentional_overflow(-1)
58569 fs16_to_cpu(const struct super_block *sb, fs16 n)
58570 {
58571 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
58572diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
58573index ca0ba15..0fa3257 100644
58574--- a/fs/binfmt_aout.c
58575+++ b/fs/binfmt_aout.c
58576@@ -16,6 +16,7 @@
58577 #include <linux/string.h>
58578 #include <linux/fs.h>
58579 #include <linux/file.h>
58580+#include <linux/security.h>
58581 #include <linux/stat.h>
58582 #include <linux/fcntl.h>
58583 #include <linux/ptrace.h>
58584@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
58585 #endif
58586 # define START_STACK(u) ((void __user *)u.start_stack)
58587
58588+ memset(&dump, 0, sizeof(dump));
58589+
58590 fs = get_fs();
58591 set_fs(KERNEL_DS);
58592 has_dumped = 1;
58593@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
58594
58595 /* If the size of the dump file exceeds the rlimit, then see what would happen
58596 if we wrote the stack, but not the data area. */
58597+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
58598 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
58599 dump.u_dsize = 0;
58600
58601 /* Make sure we have enough room to write the stack and data areas. */
58602+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
58603 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
58604 dump.u_ssize = 0;
58605
58606@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
58607 rlim = rlimit(RLIMIT_DATA);
58608 if (rlim >= RLIM_INFINITY)
58609 rlim = ~0;
58610+
58611+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
58612 if (ex.a_data + ex.a_bss > rlim)
58613 return -ENOMEM;
58614
58615@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
58616
58617 install_exec_creds(bprm);
58618
58619+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58620+ current->mm->pax_flags = 0UL;
58621+#endif
58622+
58623+#ifdef CONFIG_PAX_PAGEEXEC
58624+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
58625+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
58626+
58627+#ifdef CONFIG_PAX_EMUTRAMP
58628+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
58629+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
58630+#endif
58631+
58632+#ifdef CONFIG_PAX_MPROTECT
58633+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
58634+ current->mm->pax_flags |= MF_PAX_MPROTECT;
58635+#endif
58636+
58637+ }
58638+#endif
58639+
58640 if (N_MAGIC(ex) == OMAGIC) {
58641 unsigned long text_addr, map_size;
58642 loff_t pos;
58643@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
58644 }
58645
58646 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
58647- PROT_READ | PROT_WRITE | PROT_EXEC,
58648+ PROT_READ | PROT_WRITE,
58649 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
58650 fd_offset + ex.a_text);
58651 if (error != N_DATADDR(ex)) {
58652diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
58653index 3892c1a..4e27c04 100644
58654--- a/fs/binfmt_elf.c
58655+++ b/fs/binfmt_elf.c
58656@@ -34,6 +34,7 @@
58657 #include <linux/utsname.h>
58658 #include <linux/coredump.h>
58659 #include <linux/sched.h>
58660+#include <linux/xattr.h>
58661 #include <asm/uaccess.h>
58662 #include <asm/param.h>
58663 #include <asm/page.h>
58664@@ -47,7 +48,7 @@
58665
58666 static int load_elf_binary(struct linux_binprm *bprm);
58667 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
58668- int, int, unsigned long);
58669+ int, int, unsigned long) __intentional_overflow(-1);
58670
58671 #ifdef CONFIG_USELIB
58672 static int load_elf_library(struct file *);
58673@@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
58674 #define elf_core_dump NULL
58675 #endif
58676
58677+#ifdef CONFIG_PAX_MPROTECT
58678+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
58679+#endif
58680+
58681+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58682+static void elf_handle_mmap(struct file *file);
58683+#endif
58684+
58685 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
58686 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
58687 #else
58688@@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
58689 .load_binary = load_elf_binary,
58690 .load_shlib = load_elf_library,
58691 .core_dump = elf_core_dump,
58692+
58693+#ifdef CONFIG_PAX_MPROTECT
58694+ .handle_mprotect= elf_handle_mprotect,
58695+#endif
58696+
58697+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58698+ .handle_mmap = elf_handle_mmap,
58699+#endif
58700+
58701 .min_coredump = ELF_EXEC_PAGESIZE,
58702 };
58703
58704@@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
58705
58706 static int set_brk(unsigned long start, unsigned long end)
58707 {
58708+ unsigned long e = end;
58709+
58710 start = ELF_PAGEALIGN(start);
58711 end = ELF_PAGEALIGN(end);
58712 if (end > start) {
58713@@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
58714 if (BAD_ADDR(addr))
58715 return addr;
58716 }
58717- current->mm->start_brk = current->mm->brk = end;
58718+ current->mm->start_brk = current->mm->brk = e;
58719 return 0;
58720 }
58721
58722@@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58723 elf_addr_t __user *u_rand_bytes;
58724 const char *k_platform = ELF_PLATFORM;
58725 const char *k_base_platform = ELF_BASE_PLATFORM;
58726- unsigned char k_rand_bytes[16];
58727+ u32 k_rand_bytes[4];
58728 int items;
58729 elf_addr_t *elf_info;
58730 int ei_index = 0;
58731 const struct cred *cred = current_cred();
58732 struct vm_area_struct *vma;
58733+ unsigned long saved_auxv[AT_VECTOR_SIZE];
58734
58735 /*
58736 * In some cases (e.g. Hyper-Threading), we want to avoid L1
58737@@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58738 * Generate 16 random bytes for userspace PRNG seeding.
58739 */
58740 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
58741- u_rand_bytes = (elf_addr_t __user *)
58742- STACK_ALLOC(p, sizeof(k_rand_bytes));
58743+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
58744+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
58745+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
58746+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
58747+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
58748+ u_rand_bytes = (elf_addr_t __user *) p;
58749 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
58750 return -EFAULT;
58751
58752@@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
58753 return -EFAULT;
58754 current->mm->env_end = p;
58755
58756+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
58757+
58758 /* Put the elf_info on the stack in the right place. */
58759 sp = (elf_addr_t __user *)envp + 1;
58760- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
58761+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
58762 return -EFAULT;
58763 return 0;
58764 }
58765@@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
58766 an ELF header */
58767
58768 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58769- struct file *interpreter, unsigned long *interp_map_addr,
58770- unsigned long no_base)
58771+ struct file *interpreter, unsigned long no_base)
58772 {
58773 struct elf_phdr *elf_phdata;
58774 struct elf_phdr *eppnt;
58775- unsigned long load_addr = 0;
58776+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
58777 int load_addr_set = 0;
58778 unsigned long last_bss = 0, elf_bss = 0;
58779- unsigned long error = ~0UL;
58780+ unsigned long error = -EINVAL;
58781 unsigned long total_size;
58782 int retval, i, size;
58783
58784@@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58785 goto out_close;
58786 }
58787
58788+#ifdef CONFIG_PAX_SEGMEXEC
58789+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
58790+ pax_task_size = SEGMEXEC_TASK_SIZE;
58791+#endif
58792+
58793 eppnt = elf_phdata;
58794 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
58795 if (eppnt->p_type == PT_LOAD) {
58796@@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58797 map_addr = elf_map(interpreter, load_addr + vaddr,
58798 eppnt, elf_prot, elf_type, total_size);
58799 total_size = 0;
58800- if (!*interp_map_addr)
58801- *interp_map_addr = map_addr;
58802 error = map_addr;
58803 if (BAD_ADDR(map_addr))
58804 goto out_close;
58805@@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58806 k = load_addr + eppnt->p_vaddr;
58807 if (BAD_ADDR(k) ||
58808 eppnt->p_filesz > eppnt->p_memsz ||
58809- eppnt->p_memsz > TASK_SIZE ||
58810- TASK_SIZE - eppnt->p_memsz < k) {
58811+ eppnt->p_memsz > pax_task_size ||
58812+ pax_task_size - eppnt->p_memsz < k) {
58813 error = -ENOMEM;
58814 goto out_close;
58815 }
58816@@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
58817 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
58818
58819 /* Map the last of the bss segment */
58820- error = vm_brk(elf_bss, last_bss - elf_bss);
58821- if (BAD_ADDR(error))
58822- goto out_close;
58823+ if (last_bss > elf_bss) {
58824+ error = vm_brk(elf_bss, last_bss - elf_bss);
58825+ if (BAD_ADDR(error))
58826+ goto out_close;
58827+ }
58828 }
58829
58830 error = load_addr;
58831@@ -543,6 +574,336 @@ out:
58832 return error;
58833 }
58834
58835+#ifdef CONFIG_PAX_PT_PAX_FLAGS
58836+#ifdef CONFIG_PAX_SOFTMODE
58837+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
58838+{
58839+ unsigned long pax_flags = 0UL;
58840+
58841+#ifdef CONFIG_PAX_PAGEEXEC
58842+ if (elf_phdata->p_flags & PF_PAGEEXEC)
58843+ pax_flags |= MF_PAX_PAGEEXEC;
58844+#endif
58845+
58846+#ifdef CONFIG_PAX_SEGMEXEC
58847+ if (elf_phdata->p_flags & PF_SEGMEXEC)
58848+ pax_flags |= MF_PAX_SEGMEXEC;
58849+#endif
58850+
58851+#ifdef CONFIG_PAX_EMUTRAMP
58852+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58853+ pax_flags |= MF_PAX_EMUTRAMP;
58854+#endif
58855+
58856+#ifdef CONFIG_PAX_MPROTECT
58857+ if (elf_phdata->p_flags & PF_MPROTECT)
58858+ pax_flags |= MF_PAX_MPROTECT;
58859+#endif
58860+
58861+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58862+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
58863+ pax_flags |= MF_PAX_RANDMMAP;
58864+#endif
58865+
58866+ return pax_flags;
58867+}
58868+#endif
58869+
58870+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
58871+{
58872+ unsigned long pax_flags = 0UL;
58873+
58874+#ifdef CONFIG_PAX_PAGEEXEC
58875+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
58876+ pax_flags |= MF_PAX_PAGEEXEC;
58877+#endif
58878+
58879+#ifdef CONFIG_PAX_SEGMEXEC
58880+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
58881+ pax_flags |= MF_PAX_SEGMEXEC;
58882+#endif
58883+
58884+#ifdef CONFIG_PAX_EMUTRAMP
58885+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
58886+ pax_flags |= MF_PAX_EMUTRAMP;
58887+#endif
58888+
58889+#ifdef CONFIG_PAX_MPROTECT
58890+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
58891+ pax_flags |= MF_PAX_MPROTECT;
58892+#endif
58893+
58894+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58895+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
58896+ pax_flags |= MF_PAX_RANDMMAP;
58897+#endif
58898+
58899+ return pax_flags;
58900+}
58901+#endif
58902+
58903+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
58904+#ifdef CONFIG_PAX_SOFTMODE
58905+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
58906+{
58907+ unsigned long pax_flags = 0UL;
58908+
58909+#ifdef CONFIG_PAX_PAGEEXEC
58910+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
58911+ pax_flags |= MF_PAX_PAGEEXEC;
58912+#endif
58913+
58914+#ifdef CONFIG_PAX_SEGMEXEC
58915+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
58916+ pax_flags |= MF_PAX_SEGMEXEC;
58917+#endif
58918+
58919+#ifdef CONFIG_PAX_EMUTRAMP
58920+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
58921+ pax_flags |= MF_PAX_EMUTRAMP;
58922+#endif
58923+
58924+#ifdef CONFIG_PAX_MPROTECT
58925+ if (pax_flags_softmode & MF_PAX_MPROTECT)
58926+ pax_flags |= MF_PAX_MPROTECT;
58927+#endif
58928+
58929+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58930+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
58931+ pax_flags |= MF_PAX_RANDMMAP;
58932+#endif
58933+
58934+ return pax_flags;
58935+}
58936+#endif
58937+
58938+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
58939+{
58940+ unsigned long pax_flags = 0UL;
58941+
58942+#ifdef CONFIG_PAX_PAGEEXEC
58943+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
58944+ pax_flags |= MF_PAX_PAGEEXEC;
58945+#endif
58946+
58947+#ifdef CONFIG_PAX_SEGMEXEC
58948+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
58949+ pax_flags |= MF_PAX_SEGMEXEC;
58950+#endif
58951+
58952+#ifdef CONFIG_PAX_EMUTRAMP
58953+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
58954+ pax_flags |= MF_PAX_EMUTRAMP;
58955+#endif
58956+
58957+#ifdef CONFIG_PAX_MPROTECT
58958+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
58959+ pax_flags |= MF_PAX_MPROTECT;
58960+#endif
58961+
58962+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
58963+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
58964+ pax_flags |= MF_PAX_RANDMMAP;
58965+#endif
58966+
58967+ return pax_flags;
58968+}
58969+#endif
58970+
58971+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
58972+static unsigned long pax_parse_defaults(void)
58973+{
58974+ unsigned long pax_flags = 0UL;
58975+
58976+#ifdef CONFIG_PAX_SOFTMODE
58977+ if (pax_softmode)
58978+ return pax_flags;
58979+#endif
58980+
58981+#ifdef CONFIG_PAX_PAGEEXEC
58982+ pax_flags |= MF_PAX_PAGEEXEC;
58983+#endif
58984+
58985+#ifdef CONFIG_PAX_SEGMEXEC
58986+ pax_flags |= MF_PAX_SEGMEXEC;
58987+#endif
58988+
58989+#ifdef CONFIG_PAX_MPROTECT
58990+ pax_flags |= MF_PAX_MPROTECT;
58991+#endif
58992+
58993+#ifdef CONFIG_PAX_RANDMMAP
58994+ if (randomize_va_space)
58995+ pax_flags |= MF_PAX_RANDMMAP;
58996+#endif
58997+
58998+ return pax_flags;
58999+}
59000+
59001+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
59002+{
59003+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
59004+
59005+#ifdef CONFIG_PAX_EI_PAX
59006+
59007+#ifdef CONFIG_PAX_SOFTMODE
59008+ if (pax_softmode)
59009+ return pax_flags;
59010+#endif
59011+
59012+ pax_flags = 0UL;
59013+
59014+#ifdef CONFIG_PAX_PAGEEXEC
59015+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
59016+ pax_flags |= MF_PAX_PAGEEXEC;
59017+#endif
59018+
59019+#ifdef CONFIG_PAX_SEGMEXEC
59020+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
59021+ pax_flags |= MF_PAX_SEGMEXEC;
59022+#endif
59023+
59024+#ifdef CONFIG_PAX_EMUTRAMP
59025+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
59026+ pax_flags |= MF_PAX_EMUTRAMP;
59027+#endif
59028+
59029+#ifdef CONFIG_PAX_MPROTECT
59030+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
59031+ pax_flags |= MF_PAX_MPROTECT;
59032+#endif
59033+
59034+#ifdef CONFIG_PAX_ASLR
59035+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
59036+ pax_flags |= MF_PAX_RANDMMAP;
59037+#endif
59038+
59039+#endif
59040+
59041+ return pax_flags;
59042+
59043+}
59044+
59045+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
59046+{
59047+
59048+#ifdef CONFIG_PAX_PT_PAX_FLAGS
59049+ unsigned long i;
59050+
59051+ for (i = 0UL; i < elf_ex->e_phnum; i++)
59052+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
59053+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
59054+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
59055+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
59056+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
59057+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
59058+ return PAX_PARSE_FLAGS_FALLBACK;
59059+
59060+#ifdef CONFIG_PAX_SOFTMODE
59061+ if (pax_softmode)
59062+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
59063+ else
59064+#endif
59065+
59066+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
59067+ break;
59068+ }
59069+#endif
59070+
59071+ return PAX_PARSE_FLAGS_FALLBACK;
59072+}
59073+
59074+static unsigned long pax_parse_xattr_pax(struct file * const file)
59075+{
59076+
59077+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
59078+ ssize_t xattr_size, i;
59079+ unsigned char xattr_value[sizeof("pemrs") - 1];
59080+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
59081+
59082+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
59083+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
59084+ return PAX_PARSE_FLAGS_FALLBACK;
59085+
59086+ for (i = 0; i < xattr_size; i++)
59087+ switch (xattr_value[i]) {
59088+ default:
59089+ return PAX_PARSE_FLAGS_FALLBACK;
59090+
59091+#define parse_flag(option1, option2, flag) \
59092+ case option1: \
59093+ if (pax_flags_hardmode & MF_PAX_##flag) \
59094+ return PAX_PARSE_FLAGS_FALLBACK;\
59095+ pax_flags_hardmode |= MF_PAX_##flag; \
59096+ break; \
59097+ case option2: \
59098+ if (pax_flags_softmode & MF_PAX_##flag) \
59099+ return PAX_PARSE_FLAGS_FALLBACK;\
59100+ pax_flags_softmode |= MF_PAX_##flag; \
59101+ break;
59102+
59103+ parse_flag('p', 'P', PAGEEXEC);
59104+ parse_flag('e', 'E', EMUTRAMP);
59105+ parse_flag('m', 'M', MPROTECT);
59106+ parse_flag('r', 'R', RANDMMAP);
59107+ parse_flag('s', 'S', SEGMEXEC);
59108+
59109+#undef parse_flag
59110+ }
59111+
59112+ if (pax_flags_hardmode & pax_flags_softmode)
59113+ return PAX_PARSE_FLAGS_FALLBACK;
59114+
59115+#ifdef CONFIG_PAX_SOFTMODE
59116+ if (pax_softmode)
59117+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
59118+ else
59119+#endif
59120+
59121+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
59122+#else
59123+ return PAX_PARSE_FLAGS_FALLBACK;
59124+#endif
59125+
59126+}
59127+
59128+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
59129+{
59130+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
59131+
59132+ pax_flags = pax_parse_defaults();
59133+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
59134+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
59135+ xattr_pax_flags = pax_parse_xattr_pax(file);
59136+
59137+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59138+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
59139+ pt_pax_flags != xattr_pax_flags)
59140+ return -EINVAL;
59141+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59142+ pax_flags = xattr_pax_flags;
59143+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59144+ pax_flags = pt_pax_flags;
59145+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
59146+ pax_flags = ei_pax_flags;
59147+
59148+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
59149+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59150+ if ((__supported_pte_mask & _PAGE_NX))
59151+ pax_flags &= ~MF_PAX_SEGMEXEC;
59152+ else
59153+ pax_flags &= ~MF_PAX_PAGEEXEC;
59154+ }
59155+#endif
59156+
59157+ if (0 > pax_check_flags(&pax_flags))
59158+ return -EINVAL;
59159+
59160+ current->mm->pax_flags = pax_flags;
59161+ return 0;
59162+}
59163+#endif
59164+
59165 /*
59166 * These are the functions used to load ELF style executables and shared
59167 * libraries. There is no binary dependent code anywhere else.
59168@@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
59169 {
59170 unsigned int random_variable = 0;
59171
59172+#ifdef CONFIG_PAX_RANDUSTACK
59173+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
59174+ return stack_top - current->mm->delta_stack;
59175+#endif
59176+
59177 if ((current->flags & PF_RANDOMIZE) &&
59178 !(current->personality & ADDR_NO_RANDOMIZE)) {
59179 random_variable = get_random_int() & STACK_RND_MASK;
59180@@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59181 unsigned long load_addr = 0, load_bias = 0;
59182 int load_addr_set = 0;
59183 char * elf_interpreter = NULL;
59184- unsigned long error;
59185+ unsigned long error = 0;
59186 struct elf_phdr *elf_ppnt, *elf_phdata;
59187 unsigned long elf_bss, elf_brk;
59188 int retval, i;
59189@@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
59190 struct elfhdr elf_ex;
59191 struct elfhdr interp_elf_ex;
59192 } *loc;
59193+ unsigned long pax_task_size;
59194
59195 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
59196 if (!loc) {
59197@@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
59198 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
59199 may depend on the personality. */
59200 SET_PERSONALITY(loc->elf_ex);
59201+
59202+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59203+ current->mm->pax_flags = 0UL;
59204+#endif
59205+
59206+#ifdef CONFIG_PAX_DLRESOLVE
59207+ current->mm->call_dl_resolve = 0UL;
59208+#endif
59209+
59210+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
59211+ current->mm->call_syscall = 0UL;
59212+#endif
59213+
59214+#ifdef CONFIG_PAX_ASLR
59215+ current->mm->delta_mmap = 0UL;
59216+ current->mm->delta_stack = 0UL;
59217+#endif
59218+
59219+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
59220+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
59221+ send_sig(SIGKILL, current, 0);
59222+ goto out_free_dentry;
59223+ }
59224+#endif
59225+
59226+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
59227+ pax_set_initial_flags(bprm);
59228+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
59229+ if (pax_set_initial_flags_func)
59230+ (pax_set_initial_flags_func)(bprm);
59231+#endif
59232+
59233+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
59234+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
59235+ current->mm->context.user_cs_limit = PAGE_SIZE;
59236+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
59237+ }
59238+#endif
59239+
59240+#ifdef CONFIG_PAX_SEGMEXEC
59241+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
59242+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
59243+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
59244+ pax_task_size = SEGMEXEC_TASK_SIZE;
59245+ current->mm->def_flags |= VM_NOHUGEPAGE;
59246+ } else
59247+#endif
59248+
59249+ pax_task_size = TASK_SIZE;
59250+
59251+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
59252+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59253+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
59254+ put_cpu();
59255+ }
59256+#endif
59257+
59258+#ifdef CONFIG_PAX_ASLR
59259+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59260+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
59261+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
59262+ }
59263+#endif
59264+
59265+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59266+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
59267+ executable_stack = EXSTACK_DISABLE_X;
59268+ current->personality &= ~READ_IMPLIES_EXEC;
59269+ } else
59270+#endif
59271+
59272 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
59273 current->personality |= READ_IMPLIES_EXEC;
59274
59275@@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
59276 #else
59277 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
59278 #endif
59279+
59280+#ifdef CONFIG_PAX_RANDMMAP
59281+ /* PaX: randomize base address at the default exe base if requested */
59282+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
59283+#ifdef CONFIG_SPARC64
59284+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
59285+#else
59286+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
59287+#endif
59288+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
59289+ elf_flags |= MAP_FIXED;
59290+ }
59291+#endif
59292+
59293 }
59294
59295 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
59296@@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
59297 * allowed task size. Note that p_filesz must always be
59298 * <= p_memsz so it is only necessary to check p_memsz.
59299 */
59300- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59301- elf_ppnt->p_memsz > TASK_SIZE ||
59302- TASK_SIZE - elf_ppnt->p_memsz < k) {
59303+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
59304+ elf_ppnt->p_memsz > pax_task_size ||
59305+ pax_task_size - elf_ppnt->p_memsz < k) {
59306 /* set_brk can never work. Avoid overflows. */
59307 send_sig(SIGKILL, current, 0);
59308 retval = -EINVAL;
59309@@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
59310 goto out_free_dentry;
59311 }
59312 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
59313- send_sig(SIGSEGV, current, 0);
59314- retval = -EFAULT; /* Nobody gets to see this, but.. */
59315- goto out_free_dentry;
59316+ /*
59317+ * This bss-zeroing can fail if the ELF
59318+ * file specifies odd protections. So
59319+ * we don't check the return value
59320+ */
59321 }
59322
59323+#ifdef CONFIG_PAX_RANDMMAP
59324+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
59325+ unsigned long start, size, flags;
59326+ vm_flags_t vm_flags;
59327+
59328+ start = ELF_PAGEALIGN(elf_brk);
59329+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
59330+ flags = MAP_FIXED | MAP_PRIVATE;
59331+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
59332+
59333+ down_write(&current->mm->mmap_sem);
59334+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
59335+ retval = -ENOMEM;
59336+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
59337+// if (current->personality & ADDR_NO_RANDOMIZE)
59338+// vm_flags |= VM_READ | VM_MAYREAD;
59339+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
59340+ retval = IS_ERR_VALUE(start) ? start : 0;
59341+ }
59342+ up_write(&current->mm->mmap_sem);
59343+ if (retval == 0)
59344+ retval = set_brk(start + size, start + size + PAGE_SIZE);
59345+ if (retval < 0) {
59346+ send_sig(SIGKILL, current, 0);
59347+ goto out_free_dentry;
59348+ }
59349+ }
59350+#endif
59351+
59352 if (elf_interpreter) {
59353- unsigned long interp_map_addr = 0;
59354-
59355 elf_entry = load_elf_interp(&loc->interp_elf_ex,
59356 interpreter,
59357- &interp_map_addr,
59358 load_bias);
59359 if (!IS_ERR((void *)elf_entry)) {
59360 /*
59361@@ -1130,7 +1610,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
59362 * Decide what to dump of a segment, part, all or none.
59363 */
59364 static unsigned long vma_dump_size(struct vm_area_struct *vma,
59365- unsigned long mm_flags)
59366+ unsigned long mm_flags, long signr)
59367 {
59368 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
59369
59370@@ -1168,7 +1648,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
59371 if (vma->vm_file == NULL)
59372 return 0;
59373
59374- if (FILTER(MAPPED_PRIVATE))
59375+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
59376 goto whole;
59377
59378 /*
59379@@ -1375,9 +1855,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
59380 {
59381 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
59382 int i = 0;
59383- do
59384+ do {
59385 i += 2;
59386- while (auxv[i - 2] != AT_NULL);
59387+ } while (auxv[i - 2] != AT_NULL);
59388 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
59389 }
59390
59391@@ -1386,7 +1866,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
59392 {
59393 mm_segment_t old_fs = get_fs();
59394 set_fs(KERNEL_DS);
59395- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
59396+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
59397 set_fs(old_fs);
59398 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
59399 }
59400@@ -2010,14 +2490,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
59401 }
59402
59403 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
59404- unsigned long mm_flags)
59405+ struct coredump_params *cprm)
59406 {
59407 struct vm_area_struct *vma;
59408 size_t size = 0;
59409
59410 for (vma = first_vma(current, gate_vma); vma != NULL;
59411 vma = next_vma(vma, gate_vma))
59412- size += vma_dump_size(vma, mm_flags);
59413+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59414 return size;
59415 }
59416
59417@@ -2108,7 +2588,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59418
59419 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
59420
59421- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
59422+ offset += elf_core_vma_data_size(gate_vma, cprm);
59423 offset += elf_core_extra_data_size();
59424 e_shoff = offset;
59425
59426@@ -2136,7 +2616,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59427 phdr.p_offset = offset;
59428 phdr.p_vaddr = vma->vm_start;
59429 phdr.p_paddr = 0;
59430- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
59431+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59432 phdr.p_memsz = vma->vm_end - vma->vm_start;
59433 offset += phdr.p_filesz;
59434 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
59435@@ -2169,7 +2649,7 @@ static int elf_core_dump(struct coredump_params *cprm)
59436 unsigned long addr;
59437 unsigned long end;
59438
59439- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
59440+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
59441
59442 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
59443 struct page *page;
59444@@ -2210,6 +2690,167 @@ out:
59445
59446 #endif /* CONFIG_ELF_CORE */
59447
59448+#ifdef CONFIG_PAX_MPROTECT
59449+/* PaX: non-PIC ELF libraries need relocations on their executable segments
59450+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
59451+ * we'll remove VM_MAYWRITE for good on RELRO segments.
59452+ *
59453+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
59454+ * basis because we want to allow the common case and not the special ones.
59455+ */
59456+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
59457+{
59458+ struct elfhdr elf_h;
59459+ struct elf_phdr elf_p;
59460+ unsigned long i;
59461+ unsigned long oldflags;
59462+ bool is_textrel_rw, is_textrel_rx, is_relro;
59463+
59464+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
59465+ return;
59466+
59467+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
59468+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
59469+
59470+#ifdef CONFIG_PAX_ELFRELOCS
59471+ /* possible TEXTREL */
59472+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
59473+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
59474+#else
59475+ is_textrel_rw = false;
59476+ is_textrel_rx = false;
59477+#endif
59478+
59479+ /* possible RELRO */
59480+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
59481+
59482+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
59483+ return;
59484+
59485+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59486+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59487+
59488+#ifdef CONFIG_PAX_ETEXECRELOCS
59489+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59490+#else
59491+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
59492+#endif
59493+
59494+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
59495+ !elf_check_arch(&elf_h) ||
59496+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59497+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59498+ return;
59499+
59500+ for (i = 0UL; i < elf_h.e_phnum; i++) {
59501+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59502+ return;
59503+ switch (elf_p.p_type) {
59504+ case PT_DYNAMIC:
59505+ if (!is_textrel_rw && !is_textrel_rx)
59506+ continue;
59507+ i = 0UL;
59508+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
59509+ elf_dyn dyn;
59510+
59511+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
59512+ break;
59513+ if (dyn.d_tag == DT_NULL)
59514+ break;
59515+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
59516+ gr_log_textrel(vma);
59517+ if (is_textrel_rw)
59518+ vma->vm_flags |= VM_MAYWRITE;
59519+ else
59520+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
59521+ vma->vm_flags &= ~VM_MAYWRITE;
59522+ break;
59523+ }
59524+ i++;
59525+ }
59526+ is_textrel_rw = false;
59527+ is_textrel_rx = false;
59528+ continue;
59529+
59530+ case PT_GNU_RELRO:
59531+ if (!is_relro)
59532+ continue;
59533+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
59534+ vma->vm_flags &= ~VM_MAYWRITE;
59535+ is_relro = false;
59536+ continue;
59537+
59538+#ifdef CONFIG_PAX_PT_PAX_FLAGS
59539+ case PT_PAX_FLAGS: {
59540+ const char *msg_mprotect = "", *msg_emutramp = "";
59541+ char *buffer_lib, *buffer_exe;
59542+
59543+ if (elf_p.p_flags & PF_NOMPROTECT)
59544+ msg_mprotect = "MPROTECT disabled";
59545+
59546+#ifdef CONFIG_PAX_EMUTRAMP
59547+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
59548+ msg_emutramp = "EMUTRAMP enabled";
59549+#endif
59550+
59551+ if (!msg_mprotect[0] && !msg_emutramp[0])
59552+ continue;
59553+
59554+ if (!printk_ratelimit())
59555+ continue;
59556+
59557+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
59558+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
59559+ if (buffer_lib && buffer_exe) {
59560+ char *path_lib, *path_exe;
59561+
59562+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
59563+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
59564+
59565+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
59566+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
59567+
59568+ }
59569+ free_page((unsigned long)buffer_exe);
59570+ free_page((unsigned long)buffer_lib);
59571+ continue;
59572+ }
59573+#endif
59574+
59575+ }
59576+ }
59577+}
59578+#endif
59579+
59580+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59581+
59582+extern int grsec_enable_log_rwxmaps;
59583+
59584+static void elf_handle_mmap(struct file *file)
59585+{
59586+ struct elfhdr elf_h;
59587+ struct elf_phdr elf_p;
59588+ unsigned long i;
59589+
59590+ if (!grsec_enable_log_rwxmaps)
59591+ return;
59592+
59593+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
59594+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
59595+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
59596+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
59597+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
59598+ return;
59599+
59600+ for (i = 0UL; i < elf_h.e_phnum; i++) {
59601+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
59602+ return;
59603+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
59604+ gr_log_ptgnustack(file);
59605+ }
59606+}
59607+#endif
59608+
59609 static int __init init_elf_binfmt(void)
59610 {
59611 register_binfmt(&elf_format);
59612diff --git a/fs/block_dev.c b/fs/block_dev.c
59613index 6d72746..536d1db 100644
59614--- a/fs/block_dev.c
59615+++ b/fs/block_dev.c
59616@@ -701,7 +701,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
59617 else if (bdev->bd_contains == bdev)
59618 return true; /* is a whole device which isn't held */
59619
59620- else if (whole->bd_holder == bd_may_claim)
59621+ else if (whole->bd_holder == (void *)bd_may_claim)
59622 return true; /* is a partition of a device that is being partitioned */
59623 else if (whole->bd_holder != NULL)
59624 return false; /* is a partition of a held device */
59625diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
59626index 44ee5d2..8b23e53 100644
59627--- a/fs/btrfs/ctree.c
59628+++ b/fs/btrfs/ctree.c
59629@@ -1184,9 +1184,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
59630 free_extent_buffer(buf);
59631 add_root_to_dirty_list(root);
59632 } else {
59633- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
59634- parent_start = parent->start;
59635- else
59636+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
59637+ if (parent)
59638+ parent_start = parent->start;
59639+ else
59640+ parent_start = 0;
59641+ } else
59642 parent_start = 0;
59643
59644 WARN_ON(trans->transid != btrfs_header_generation(parent));
59645diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
59646index a2e90f8..5135e5f 100644
59647--- a/fs/btrfs/delayed-inode.c
59648+++ b/fs/btrfs/delayed-inode.c
59649@@ -462,7 +462,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
59650
59651 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
59652 {
59653- int seq = atomic_inc_return(&delayed_root->items_seq);
59654+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
59655 if ((atomic_dec_return(&delayed_root->items) <
59656 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
59657 waitqueue_active(&delayed_root->wait))
59658@@ -1412,7 +1412,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
59659
59660 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
59661 {
59662- int val = atomic_read(&delayed_root->items_seq);
59663+ int val = atomic_read_unchecked(&delayed_root->items_seq);
59664
59665 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
59666 return 1;
59667@@ -1436,7 +1436,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
59668 int seq;
59669 int ret;
59670
59671- seq = atomic_read(&delayed_root->items_seq);
59672+ seq = atomic_read_unchecked(&delayed_root->items_seq);
59673
59674 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
59675 if (ret)
59676diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
59677index f70119f..ab5894d 100644
59678--- a/fs/btrfs/delayed-inode.h
59679+++ b/fs/btrfs/delayed-inode.h
59680@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
59681 */
59682 struct list_head prepare_list;
59683 atomic_t items; /* for delayed items */
59684- atomic_t items_seq; /* for delayed items */
59685+ atomic_unchecked_t items_seq; /* for delayed items */
59686 int nodes; /* for delayed nodes */
59687 wait_queue_head_t wait;
59688 };
59689@@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
59690 struct btrfs_delayed_root *delayed_root)
59691 {
59692 atomic_set(&delayed_root->items, 0);
59693- atomic_set(&delayed_root->items_seq, 0);
59694+ atomic_set_unchecked(&delayed_root->items_seq, 0);
59695 delayed_root->nodes = 0;
59696 spin_lock_init(&delayed_root->lock);
59697 init_waitqueue_head(&delayed_root->wait);
59698diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
59699index b765d41..5a8b0c3 100644
59700--- a/fs/btrfs/ioctl.c
59701+++ b/fs/btrfs/ioctl.c
59702@@ -3975,9 +3975,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59703 for (i = 0; i < num_types; i++) {
59704 struct btrfs_space_info *tmp;
59705
59706+ /* Don't copy in more than we allocated */
59707 if (!slot_count)
59708 break;
59709
59710+ slot_count--;
59711+
59712 info = NULL;
59713 rcu_read_lock();
59714 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
59715@@ -3999,10 +4002,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
59716 memcpy(dest, &space, sizeof(space));
59717 dest++;
59718 space_args.total_spaces++;
59719- slot_count--;
59720 }
59721- if (!slot_count)
59722- break;
59723 }
59724 up_read(&info->groups_sem);
59725 }
59726diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
59727index c4124de..d7613eb6 100644
59728--- a/fs/btrfs/super.c
59729+++ b/fs/btrfs/super.c
59730@@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
59731 function, line, errstr);
59732 return;
59733 }
59734- ACCESS_ONCE(trans->transaction->aborted) = errno;
59735+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
59736 /* Wake up anybody who may be waiting on this transaction */
59737 wake_up(&root->fs_info->transaction_wait);
59738 wake_up(&root->fs_info->transaction_blocked_wait);
59739diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
59740index 12e5355..cdf30c6 100644
59741--- a/fs/btrfs/sysfs.c
59742+++ b/fs/btrfs/sysfs.c
59743@@ -475,7 +475,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
59744 for (set = 0; set < FEAT_MAX; set++) {
59745 int i;
59746 struct attribute *attrs[2];
59747- struct attribute_group agroup = {
59748+ attribute_group_no_const agroup = {
59749 .name = "features",
59750 .attrs = attrs,
59751 };
59752diff --git a/fs/btrfs/tree-log.h b/fs/btrfs/tree-log.h
59753index e2e798a..f454c18 100644
59754--- a/fs/btrfs/tree-log.h
59755+++ b/fs/btrfs/tree-log.h
59756@@ -41,7 +41,7 @@ static inline void btrfs_init_log_ctx(struct btrfs_log_ctx *ctx)
59757 static inline void btrfs_set_log_full_commit(struct btrfs_fs_info *fs_info,
59758 struct btrfs_trans_handle *trans)
59759 {
59760- ACCESS_ONCE(fs_info->last_trans_log_full_commit) = trans->transid;
59761+ ACCESS_ONCE_RW(fs_info->last_trans_log_full_commit) = trans->transid;
59762 }
59763
59764 static inline int btrfs_need_log_full_commit(struct btrfs_fs_info *fs_info,
59765diff --git a/fs/buffer.c b/fs/buffer.c
59766index 72daaa5..60ffeb9 100644
59767--- a/fs/buffer.c
59768+++ b/fs/buffer.c
59769@@ -3432,7 +3432,7 @@ void __init buffer_init(void)
59770 bh_cachep = kmem_cache_create("buffer_head",
59771 sizeof(struct buffer_head), 0,
59772 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
59773- SLAB_MEM_SPREAD),
59774+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
59775 NULL);
59776
59777 /*
59778diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
59779index fbb08e9..0fda764 100644
59780--- a/fs/cachefiles/bind.c
59781+++ b/fs/cachefiles/bind.c
59782@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
59783 args);
59784
59785 /* start by checking things over */
59786- ASSERT(cache->fstop_percent >= 0 &&
59787- cache->fstop_percent < cache->fcull_percent &&
59788+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
59789 cache->fcull_percent < cache->frun_percent &&
59790 cache->frun_percent < 100);
59791
59792- ASSERT(cache->bstop_percent >= 0 &&
59793- cache->bstop_percent < cache->bcull_percent &&
59794+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
59795 cache->bcull_percent < cache->brun_percent &&
59796 cache->brun_percent < 100);
59797
59798diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
59799index ce1b115..4a6852c 100644
59800--- a/fs/cachefiles/daemon.c
59801+++ b/fs/cachefiles/daemon.c
59802@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
59803 if (n > buflen)
59804 return -EMSGSIZE;
59805
59806- if (copy_to_user(_buffer, buffer, n) != 0)
59807+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
59808 return -EFAULT;
59809
59810 return n;
59811@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
59812 if (test_bit(CACHEFILES_DEAD, &cache->flags))
59813 return -EIO;
59814
59815- if (datalen < 0 || datalen > PAGE_SIZE - 1)
59816+ if (datalen > PAGE_SIZE - 1)
59817 return -EOPNOTSUPP;
59818
59819 /* drag the command string into the kernel so we can parse it */
59820@@ -385,7 +385,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
59821 if (args[0] != '%' || args[1] != '\0')
59822 return -EINVAL;
59823
59824- if (fstop < 0 || fstop >= cache->fcull_percent)
59825+ if (fstop >= cache->fcull_percent)
59826 return cachefiles_daemon_range_error(cache, args);
59827
59828 cache->fstop_percent = fstop;
59829@@ -457,7 +457,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
59830 if (args[0] != '%' || args[1] != '\0')
59831 return -EINVAL;
59832
59833- if (bstop < 0 || bstop >= cache->bcull_percent)
59834+ if (bstop >= cache->bcull_percent)
59835 return cachefiles_daemon_range_error(cache, args);
59836
59837 cache->bstop_percent = bstop;
59838diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
59839index 8c52472..c4e3a69 100644
59840--- a/fs/cachefiles/internal.h
59841+++ b/fs/cachefiles/internal.h
59842@@ -66,7 +66,7 @@ struct cachefiles_cache {
59843 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
59844 struct rb_root active_nodes; /* active nodes (can't be culled) */
59845 rwlock_t active_lock; /* lock for active_nodes */
59846- atomic_t gravecounter; /* graveyard uniquifier */
59847+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
59848 unsigned frun_percent; /* when to stop culling (% files) */
59849 unsigned fcull_percent; /* when to start culling (% files) */
59850 unsigned fstop_percent; /* when to stop allocating (% files) */
59851@@ -178,19 +178,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
59852 * proc.c
59853 */
59854 #ifdef CONFIG_CACHEFILES_HISTOGRAM
59855-extern atomic_t cachefiles_lookup_histogram[HZ];
59856-extern atomic_t cachefiles_mkdir_histogram[HZ];
59857-extern atomic_t cachefiles_create_histogram[HZ];
59858+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59859+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59860+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
59861
59862 extern int __init cachefiles_proc_init(void);
59863 extern void cachefiles_proc_cleanup(void);
59864 static inline
59865-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
59866+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
59867 {
59868 unsigned long jif = jiffies - start_jif;
59869 if (jif >= HZ)
59870 jif = HZ - 1;
59871- atomic_inc(&histogram[jif]);
59872+ atomic_inc_unchecked(&histogram[jif]);
59873 }
59874
59875 #else
59876diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
59877index dad7d95..07475af 100644
59878--- a/fs/cachefiles/namei.c
59879+++ b/fs/cachefiles/namei.c
59880@@ -312,7 +312,7 @@ try_again:
59881 /* first step is to make up a grave dentry in the graveyard */
59882 sprintf(nbuffer, "%08x%08x",
59883 (uint32_t) get_seconds(),
59884- (uint32_t) atomic_inc_return(&cache->gravecounter));
59885+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
59886
59887 /* do the multiway lock magic */
59888 trap = lock_rename(cache->graveyard, dir);
59889diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
59890index eccd339..4c1d995 100644
59891--- a/fs/cachefiles/proc.c
59892+++ b/fs/cachefiles/proc.c
59893@@ -14,9 +14,9 @@
59894 #include <linux/seq_file.h>
59895 #include "internal.h"
59896
59897-atomic_t cachefiles_lookup_histogram[HZ];
59898-atomic_t cachefiles_mkdir_histogram[HZ];
59899-atomic_t cachefiles_create_histogram[HZ];
59900+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
59901+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
59902+atomic_unchecked_t cachefiles_create_histogram[HZ];
59903
59904 /*
59905 * display the latency histogram
59906@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
59907 return 0;
59908 default:
59909 index = (unsigned long) v - 3;
59910- x = atomic_read(&cachefiles_lookup_histogram[index]);
59911- y = atomic_read(&cachefiles_mkdir_histogram[index]);
59912- z = atomic_read(&cachefiles_create_histogram[index]);
59913+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
59914+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
59915+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
59916 if (x == 0 && y == 0 && z == 0)
59917 return 0;
59918
59919diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
59920index 25e745b..220e604 100644
59921--- a/fs/cachefiles/rdwr.c
59922+++ b/fs/cachefiles/rdwr.c
59923@@ -937,7 +937,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
59924 old_fs = get_fs();
59925 set_fs(KERNEL_DS);
59926 ret = file->f_op->write(
59927- file, (const void __user *) data, len, &pos);
59928+ file, (const void __force_user *) data, len, &pos);
59929 set_fs(old_fs);
59930 kunmap(page);
59931 file_end_write(file);
59932diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
59933index c29d6ae..719b9bb 100644
59934--- a/fs/ceph/dir.c
59935+++ b/fs/ceph/dir.c
59936@@ -129,6 +129,8 @@ static int __dcache_readdir(struct file *file, struct dir_context *ctx,
59937 struct dentry *dentry, *last;
59938 struct ceph_dentry_info *di;
59939 int err = 0;
59940+ char d_name[DNAME_INLINE_LEN];
59941+ const unsigned char *name;
59942
59943 /* claim ref on last dentry we returned */
59944 last = fi->dentry;
59945@@ -192,7 +194,12 @@ more:
59946
59947 dout(" %llu (%llu) dentry %p %.*s %p\n", di->offset, ctx->pos,
59948 dentry, dentry->d_name.len, dentry->d_name.name, dentry->d_inode);
59949- if (!dir_emit(ctx, dentry->d_name.name,
59950+ name = dentry->d_name.name;
59951+ if (name == dentry->d_iname) {
59952+ memcpy(d_name, name, dentry->d_name.len);
59953+ name = d_name;
59954+ }
59955+ if (!dir_emit(ctx, name,
59956 dentry->d_name.len,
59957 ceph_translate_ino(dentry->d_sb, dentry->d_inode->i_ino),
59958 dentry->d_inode->i_mode >> 12)) {
59959@@ -250,7 +257,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
59960 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
59961 struct ceph_mds_client *mdsc = fsc->mdsc;
59962 unsigned frag = fpos_frag(ctx->pos);
59963- int off = fpos_off(ctx->pos);
59964+ unsigned int off = fpos_off(ctx->pos);
59965 int err;
59966 u32 ftype;
59967 struct ceph_mds_reply_info_parsed *rinfo;
59968diff --git a/fs/ceph/ioctl.c b/fs/ceph/ioctl.c
59969index a822a6e..4644256 100644
59970--- a/fs/ceph/ioctl.c
59971+++ b/fs/ceph/ioctl.c
59972@@ -41,7 +41,7 @@ static long __validate_layout(struct ceph_mds_client *mdsc,
59973 /* validate striping parameters */
59974 if ((l->object_size & ~PAGE_MASK) ||
59975 (l->stripe_unit & ~PAGE_MASK) ||
59976- (l->stripe_unit != 0 &&
59977+ ((unsigned)l->stripe_unit != 0 &&
59978 ((unsigned)l->object_size % (unsigned)l->stripe_unit)))
59979 return -EINVAL;
59980
59981diff --git a/fs/ceph/super.c b/fs/ceph/super.c
59982index f6e1237..796ffd1 100644
59983--- a/fs/ceph/super.c
59984+++ b/fs/ceph/super.c
59985@@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
59986 /*
59987 * construct our own bdi so we can control readahead, etc.
59988 */
59989-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
59990+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
59991
59992 static int ceph_register_bdi(struct super_block *sb,
59993 struct ceph_fs_client *fsc)
59994@@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
59995 default_backing_dev_info.ra_pages;
59996
59997 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
59998- atomic_long_inc_return(&bdi_seq));
59999+ atomic_long_inc_return_unchecked(&bdi_seq));
60000 if (!err)
60001 sb->s_bdi = &fsc->backing_dev_info;
60002 return err;
60003diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
60004index 44ec726..bcb06a3 100644
60005--- a/fs/cifs/cifs_debug.c
60006+++ b/fs/cifs/cifs_debug.c
60007@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
60008
60009 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
60010 #ifdef CONFIG_CIFS_STATS2
60011- atomic_set(&totBufAllocCount, 0);
60012- atomic_set(&totSmBufAllocCount, 0);
60013+ atomic_set_unchecked(&totBufAllocCount, 0);
60014+ atomic_set_unchecked(&totSmBufAllocCount, 0);
60015 #endif /* CONFIG_CIFS_STATS2 */
60016 spin_lock(&cifs_tcp_ses_lock);
60017 list_for_each(tmp1, &cifs_tcp_ses_list) {
60018@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
60019 tcon = list_entry(tmp3,
60020 struct cifs_tcon,
60021 tcon_list);
60022- atomic_set(&tcon->num_smbs_sent, 0);
60023+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
60024 if (server->ops->clear_stats)
60025 server->ops->clear_stats(tcon);
60026 }
60027@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
60028 smBufAllocCount.counter, cifs_min_small);
60029 #ifdef CONFIG_CIFS_STATS2
60030 seq_printf(m, "Total Large %d Small %d Allocations\n",
60031- atomic_read(&totBufAllocCount),
60032- atomic_read(&totSmBufAllocCount));
60033+ atomic_read_unchecked(&totBufAllocCount),
60034+ atomic_read_unchecked(&totSmBufAllocCount));
60035 #endif /* CONFIG_CIFS_STATS2 */
60036
60037 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
60038@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
60039 if (tcon->need_reconnect)
60040 seq_puts(m, "\tDISCONNECTED ");
60041 seq_printf(m, "\nSMBs: %d",
60042- atomic_read(&tcon->num_smbs_sent));
60043+ atomic_read_unchecked(&tcon->num_smbs_sent));
60044 if (server->ops->print_stats)
60045 server->ops->print_stats(m, tcon);
60046 }
60047diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
60048index 889b984..fcb8431 100644
60049--- a/fs/cifs/cifsfs.c
60050+++ b/fs/cifs/cifsfs.c
60051@@ -1092,7 +1092,7 @@ cifs_init_request_bufs(void)
60052 */
60053 cifs_req_cachep = kmem_cache_create("cifs_request",
60054 CIFSMaxBufSize + max_hdr_size, 0,
60055- SLAB_HWCACHE_ALIGN, NULL);
60056+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
60057 if (cifs_req_cachep == NULL)
60058 return -ENOMEM;
60059
60060@@ -1119,7 +1119,7 @@ cifs_init_request_bufs(void)
60061 efficient to alloc 1 per page off the slab compared to 17K (5page)
60062 alloc of large cifs buffers even when page debugging is on */
60063 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
60064- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
60065+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
60066 NULL);
60067 if (cifs_sm_req_cachep == NULL) {
60068 mempool_destroy(cifs_req_poolp);
60069@@ -1204,8 +1204,8 @@ init_cifs(void)
60070 atomic_set(&bufAllocCount, 0);
60071 atomic_set(&smBufAllocCount, 0);
60072 #ifdef CONFIG_CIFS_STATS2
60073- atomic_set(&totBufAllocCount, 0);
60074- atomic_set(&totSmBufAllocCount, 0);
60075+ atomic_set_unchecked(&totBufAllocCount, 0);
60076+ atomic_set_unchecked(&totSmBufAllocCount, 0);
60077 #endif /* CONFIG_CIFS_STATS2 */
60078
60079 atomic_set(&midCount, 0);
60080diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
60081index 25b8392..01e46dc 100644
60082--- a/fs/cifs/cifsglob.h
60083+++ b/fs/cifs/cifsglob.h
60084@@ -821,35 +821,35 @@ struct cifs_tcon {
60085 __u16 Flags; /* optional support bits */
60086 enum statusEnum tidStatus;
60087 #ifdef CONFIG_CIFS_STATS
60088- atomic_t num_smbs_sent;
60089+ atomic_unchecked_t num_smbs_sent;
60090 union {
60091 struct {
60092- atomic_t num_writes;
60093- atomic_t num_reads;
60094- atomic_t num_flushes;
60095- atomic_t num_oplock_brks;
60096- atomic_t num_opens;
60097- atomic_t num_closes;
60098- atomic_t num_deletes;
60099- atomic_t num_mkdirs;
60100- atomic_t num_posixopens;
60101- atomic_t num_posixmkdirs;
60102- atomic_t num_rmdirs;
60103- atomic_t num_renames;
60104- atomic_t num_t2renames;
60105- atomic_t num_ffirst;
60106- atomic_t num_fnext;
60107- atomic_t num_fclose;
60108- atomic_t num_hardlinks;
60109- atomic_t num_symlinks;
60110- atomic_t num_locks;
60111- atomic_t num_acl_get;
60112- atomic_t num_acl_set;
60113+ atomic_unchecked_t num_writes;
60114+ atomic_unchecked_t num_reads;
60115+ atomic_unchecked_t num_flushes;
60116+ atomic_unchecked_t num_oplock_brks;
60117+ atomic_unchecked_t num_opens;
60118+ atomic_unchecked_t num_closes;
60119+ atomic_unchecked_t num_deletes;
60120+ atomic_unchecked_t num_mkdirs;
60121+ atomic_unchecked_t num_posixopens;
60122+ atomic_unchecked_t num_posixmkdirs;
60123+ atomic_unchecked_t num_rmdirs;
60124+ atomic_unchecked_t num_renames;
60125+ atomic_unchecked_t num_t2renames;
60126+ atomic_unchecked_t num_ffirst;
60127+ atomic_unchecked_t num_fnext;
60128+ atomic_unchecked_t num_fclose;
60129+ atomic_unchecked_t num_hardlinks;
60130+ atomic_unchecked_t num_symlinks;
60131+ atomic_unchecked_t num_locks;
60132+ atomic_unchecked_t num_acl_get;
60133+ atomic_unchecked_t num_acl_set;
60134 } cifs_stats;
60135 #ifdef CONFIG_CIFS_SMB2
60136 struct {
60137- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60138- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60139+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
60140+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
60141 } smb2_stats;
60142 #endif /* CONFIG_CIFS_SMB2 */
60143 } stats;
60144@@ -1190,7 +1190,7 @@ convert_delimiter(char *path, char delim)
60145 }
60146
60147 #ifdef CONFIG_CIFS_STATS
60148-#define cifs_stats_inc atomic_inc
60149+#define cifs_stats_inc atomic_inc_unchecked
60150
60151 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
60152 unsigned int bytes)
60153@@ -1557,8 +1557,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
60154 /* Various Debug counters */
60155 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
60156 #ifdef CONFIG_CIFS_STATS2
60157-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
60158-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
60159+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
60160+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
60161 #endif
60162 GLOBAL_EXTERN atomic_t smBufAllocCount;
60163 GLOBAL_EXTERN atomic_t midCount;
60164diff --git a/fs/cifs/file.c b/fs/cifs/file.c
60165index 5f29354..359bc0d 100644
60166--- a/fs/cifs/file.c
60167+++ b/fs/cifs/file.c
60168@@ -2056,10 +2056,14 @@ static int cifs_writepages(struct address_space *mapping,
60169 index = mapping->writeback_index; /* Start from prev offset */
60170 end = -1;
60171 } else {
60172- index = wbc->range_start >> PAGE_CACHE_SHIFT;
60173- end = wbc->range_end >> PAGE_CACHE_SHIFT;
60174- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
60175+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
60176 range_whole = true;
60177+ index = 0;
60178+ end = ULONG_MAX;
60179+ } else {
60180+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
60181+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
60182+ }
60183 scanned = true;
60184 }
60185 server = cifs_sb_master_tcon(cifs_sb)->ses->server;
60186diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
60187index b7415d5..3984ec0 100644
60188--- a/fs/cifs/misc.c
60189+++ b/fs/cifs/misc.c
60190@@ -170,7 +170,7 @@ cifs_buf_get(void)
60191 memset(ret_buf, 0, buf_size + 3);
60192 atomic_inc(&bufAllocCount);
60193 #ifdef CONFIG_CIFS_STATS2
60194- atomic_inc(&totBufAllocCount);
60195+ atomic_inc_unchecked(&totBufAllocCount);
60196 #endif /* CONFIG_CIFS_STATS2 */
60197 }
60198
60199@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
60200 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
60201 atomic_inc(&smBufAllocCount);
60202 #ifdef CONFIG_CIFS_STATS2
60203- atomic_inc(&totSmBufAllocCount);
60204+ atomic_inc_unchecked(&totSmBufAllocCount);
60205 #endif /* CONFIG_CIFS_STATS2 */
60206
60207 }
60208diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
60209index 52131d8..fd79e97 100644
60210--- a/fs/cifs/smb1ops.c
60211+++ b/fs/cifs/smb1ops.c
60212@@ -626,27 +626,27 @@ static void
60213 cifs_clear_stats(struct cifs_tcon *tcon)
60214 {
60215 #ifdef CONFIG_CIFS_STATS
60216- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
60217- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
60218- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
60219- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60220- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
60221- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
60222- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60223- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
60224- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
60225- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
60226- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
60227- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
60228- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
60229- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
60230- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
60231- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
60232- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
60233- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
60234- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
60235- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
60236- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
60237+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
60238+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
60239+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
60240+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
60241+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
60242+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
60243+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
60244+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
60245+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
60246+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
60247+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
60248+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
60249+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
60250+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
60251+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
60252+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
60253+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
60254+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
60255+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
60256+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
60257+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
60258 #endif
60259 }
60260
60261@@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60262 {
60263 #ifdef CONFIG_CIFS_STATS
60264 seq_printf(m, " Oplocks breaks: %d",
60265- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
60266+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
60267 seq_printf(m, "\nReads: %d Bytes: %llu",
60268- atomic_read(&tcon->stats.cifs_stats.num_reads),
60269+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
60270 (long long)(tcon->bytes_read));
60271 seq_printf(m, "\nWrites: %d Bytes: %llu",
60272- atomic_read(&tcon->stats.cifs_stats.num_writes),
60273+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
60274 (long long)(tcon->bytes_written));
60275 seq_printf(m, "\nFlushes: %d",
60276- atomic_read(&tcon->stats.cifs_stats.num_flushes));
60277+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
60278 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
60279- atomic_read(&tcon->stats.cifs_stats.num_locks),
60280- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
60281- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
60282+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
60283+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
60284+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
60285 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
60286- atomic_read(&tcon->stats.cifs_stats.num_opens),
60287- atomic_read(&tcon->stats.cifs_stats.num_closes),
60288- atomic_read(&tcon->stats.cifs_stats.num_deletes));
60289+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
60290+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
60291+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
60292 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
60293- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
60294- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
60295+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
60296+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
60297 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
60298- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
60299- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
60300+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
60301+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
60302 seq_printf(m, "\nRenames: %d T2 Renames %d",
60303- atomic_read(&tcon->stats.cifs_stats.num_renames),
60304- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
60305+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
60306+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
60307 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
60308- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
60309- atomic_read(&tcon->stats.cifs_stats.num_fnext),
60310- atomic_read(&tcon->stats.cifs_stats.num_fclose));
60311+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
60312+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
60313+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
60314 #endif
60315 }
60316
60317diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
60318index f522193..586121b 100644
60319--- a/fs/cifs/smb2ops.c
60320+++ b/fs/cifs/smb2ops.c
60321@@ -414,8 +414,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
60322 #ifdef CONFIG_CIFS_STATS
60323 int i;
60324 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
60325- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60326- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60327+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
60328+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
60329 }
60330 #endif
60331 }
60332@@ -455,65 +455,65 @@ static void
60333 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
60334 {
60335 #ifdef CONFIG_CIFS_STATS
60336- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60337- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60338+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
60339+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
60340 seq_printf(m, "\nNegotiates: %d sent %d failed",
60341- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
60342- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
60343+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
60344+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
60345 seq_printf(m, "\nSessionSetups: %d sent %d failed",
60346- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
60347- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
60348+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
60349+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
60350 seq_printf(m, "\nLogoffs: %d sent %d failed",
60351- atomic_read(&sent[SMB2_LOGOFF_HE]),
60352- atomic_read(&failed[SMB2_LOGOFF_HE]));
60353+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
60354+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
60355 seq_printf(m, "\nTreeConnects: %d sent %d failed",
60356- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
60357- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
60358+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
60359+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
60360 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
60361- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
60362- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
60363+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
60364+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
60365 seq_printf(m, "\nCreates: %d sent %d failed",
60366- atomic_read(&sent[SMB2_CREATE_HE]),
60367- atomic_read(&failed[SMB2_CREATE_HE]));
60368+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
60369+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
60370 seq_printf(m, "\nCloses: %d sent %d failed",
60371- atomic_read(&sent[SMB2_CLOSE_HE]),
60372- atomic_read(&failed[SMB2_CLOSE_HE]));
60373+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
60374+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
60375 seq_printf(m, "\nFlushes: %d sent %d failed",
60376- atomic_read(&sent[SMB2_FLUSH_HE]),
60377- atomic_read(&failed[SMB2_FLUSH_HE]));
60378+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
60379+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
60380 seq_printf(m, "\nReads: %d sent %d failed",
60381- atomic_read(&sent[SMB2_READ_HE]),
60382- atomic_read(&failed[SMB2_READ_HE]));
60383+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
60384+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
60385 seq_printf(m, "\nWrites: %d sent %d failed",
60386- atomic_read(&sent[SMB2_WRITE_HE]),
60387- atomic_read(&failed[SMB2_WRITE_HE]));
60388+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
60389+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
60390 seq_printf(m, "\nLocks: %d sent %d failed",
60391- atomic_read(&sent[SMB2_LOCK_HE]),
60392- atomic_read(&failed[SMB2_LOCK_HE]));
60393+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
60394+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
60395 seq_printf(m, "\nIOCTLs: %d sent %d failed",
60396- atomic_read(&sent[SMB2_IOCTL_HE]),
60397- atomic_read(&failed[SMB2_IOCTL_HE]));
60398+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
60399+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
60400 seq_printf(m, "\nCancels: %d sent %d failed",
60401- atomic_read(&sent[SMB2_CANCEL_HE]),
60402- atomic_read(&failed[SMB2_CANCEL_HE]));
60403+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
60404+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
60405 seq_printf(m, "\nEchos: %d sent %d failed",
60406- atomic_read(&sent[SMB2_ECHO_HE]),
60407- atomic_read(&failed[SMB2_ECHO_HE]));
60408+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
60409+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
60410 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
60411- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
60412- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
60413+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
60414+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
60415 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
60416- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
60417- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
60418+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
60419+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
60420 seq_printf(m, "\nQueryInfos: %d sent %d failed",
60421- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
60422- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
60423+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
60424+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
60425 seq_printf(m, "\nSetInfos: %d sent %d failed",
60426- atomic_read(&sent[SMB2_SET_INFO_HE]),
60427- atomic_read(&failed[SMB2_SET_INFO_HE]));
60428+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
60429+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
60430 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
60431- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
60432- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
60433+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
60434+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
60435 #endif
60436 }
60437
60438diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
60439index 74b3a66..0c709f3 100644
60440--- a/fs/cifs/smb2pdu.c
60441+++ b/fs/cifs/smb2pdu.c
60442@@ -2143,8 +2143,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
60443 default:
60444 cifs_dbg(VFS, "info level %u isn't supported\n",
60445 srch_inf->info_level);
60446- rc = -EINVAL;
60447- goto qdir_exit;
60448+ return -EINVAL;
60449 }
60450
60451 req->FileIndex = cpu_to_le32(index);
60452diff --git a/fs/coda/cache.c b/fs/coda/cache.c
60453index 278f8fd..e69c52d 100644
60454--- a/fs/coda/cache.c
60455+++ b/fs/coda/cache.c
60456@@ -24,7 +24,7 @@
60457 #include "coda_linux.h"
60458 #include "coda_cache.h"
60459
60460-static atomic_t permission_epoch = ATOMIC_INIT(0);
60461+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
60462
60463 /* replace or extend an acl cache hit */
60464 void coda_cache_enter(struct inode *inode, int mask)
60465@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
60466 struct coda_inode_info *cii = ITOC(inode);
60467
60468 spin_lock(&cii->c_lock);
60469- cii->c_cached_epoch = atomic_read(&permission_epoch);
60470+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
60471 if (!uid_eq(cii->c_uid, current_fsuid())) {
60472 cii->c_uid = current_fsuid();
60473 cii->c_cached_perm = mask;
60474@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
60475 {
60476 struct coda_inode_info *cii = ITOC(inode);
60477 spin_lock(&cii->c_lock);
60478- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
60479+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
60480 spin_unlock(&cii->c_lock);
60481 }
60482
60483 /* remove all acl caches */
60484 void coda_cache_clear_all(struct super_block *sb)
60485 {
60486- atomic_inc(&permission_epoch);
60487+ atomic_inc_unchecked(&permission_epoch);
60488 }
60489
60490
60491@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
60492 spin_lock(&cii->c_lock);
60493 hit = (mask & cii->c_cached_perm) == mask &&
60494 uid_eq(cii->c_uid, current_fsuid()) &&
60495- cii->c_cached_epoch == atomic_read(&permission_epoch);
60496+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
60497 spin_unlock(&cii->c_lock);
60498
60499 return hit;
60500diff --git a/fs/compat.c b/fs/compat.c
60501index 66d3d3c..9c10175 100644
60502--- a/fs/compat.c
60503+++ b/fs/compat.c
60504@@ -54,7 +54,7 @@
60505 #include <asm/ioctls.h>
60506 #include "internal.h"
60507
60508-int compat_log = 1;
60509+int compat_log = 0;
60510
60511 int compat_printk(const char *fmt, ...)
60512 {
60513@@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
60514
60515 set_fs(KERNEL_DS);
60516 /* The __user pointer cast is valid because of the set_fs() */
60517- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
60518+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
60519 set_fs(oldfs);
60520 /* truncating is ok because it's a user address */
60521 if (!ret)
60522@@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
60523 goto out;
60524
60525 ret = -EINVAL;
60526- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
60527+ if (nr_segs > UIO_MAXIOV)
60528 goto out;
60529 if (nr_segs > fast_segs) {
60530 ret = -ENOMEM;
60531@@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
60532 struct compat_readdir_callback {
60533 struct dir_context ctx;
60534 struct compat_old_linux_dirent __user *dirent;
60535+ struct file * file;
60536 int result;
60537 };
60538
60539@@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
60540 buf->result = -EOVERFLOW;
60541 return -EOVERFLOW;
60542 }
60543+
60544+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60545+ return 0;
60546+
60547 buf->result++;
60548 dirent = buf->dirent;
60549 if (!access_ok(VERIFY_WRITE, dirent,
60550@@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
60551 if (!f.file)
60552 return -EBADF;
60553
60554+ buf.file = f.file;
60555 error = iterate_dir(f.file, &buf.ctx);
60556 if (buf.result)
60557 error = buf.result;
60558@@ -917,6 +923,7 @@ struct compat_getdents_callback {
60559 struct dir_context ctx;
60560 struct compat_linux_dirent __user *current_dir;
60561 struct compat_linux_dirent __user *previous;
60562+ struct file * file;
60563 int count;
60564 int error;
60565 };
60566@@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
60567 buf->error = -EOVERFLOW;
60568 return -EOVERFLOW;
60569 }
60570+
60571+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60572+ return 0;
60573+
60574 dirent = buf->previous;
60575 if (dirent) {
60576 if (__put_user(offset, &dirent->d_off))
60577@@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
60578 if (!f.file)
60579 return -EBADF;
60580
60581+ buf.file = f.file;
60582 error = iterate_dir(f.file, &buf.ctx);
60583 if (error >= 0)
60584 error = buf.error;
60585@@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
60586 struct dir_context ctx;
60587 struct linux_dirent64 __user *current_dir;
60588 struct linux_dirent64 __user *previous;
60589+ struct file * file;
60590 int count;
60591 int error;
60592 };
60593@@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
60594 buf->error = -EINVAL; /* only used if we fail.. */
60595 if (reclen > buf->count)
60596 return -EINVAL;
60597+
60598+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
60599+ return 0;
60600+
60601 dirent = buf->previous;
60602
60603 if (dirent) {
60604@@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
60605 if (!f.file)
60606 return -EBADF;
60607
60608+ buf.file = f.file;
60609 error = iterate_dir(f.file, &buf.ctx);
60610 if (error >= 0)
60611 error = buf.error;
60612diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
60613index 4d24d17..4f8c09e 100644
60614--- a/fs/compat_binfmt_elf.c
60615+++ b/fs/compat_binfmt_elf.c
60616@@ -30,11 +30,13 @@
60617 #undef elf_phdr
60618 #undef elf_shdr
60619 #undef elf_note
60620+#undef elf_dyn
60621 #undef elf_addr_t
60622 #define elfhdr elf32_hdr
60623 #define elf_phdr elf32_phdr
60624 #define elf_shdr elf32_shdr
60625 #define elf_note elf32_note
60626+#define elf_dyn Elf32_Dyn
60627 #define elf_addr_t Elf32_Addr
60628
60629 /*
60630diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
60631index afec645..9c65620 100644
60632--- a/fs/compat_ioctl.c
60633+++ b/fs/compat_ioctl.c
60634@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
60635 return -EFAULT;
60636 if (__get_user(udata, &ss32->iomem_base))
60637 return -EFAULT;
60638- ss.iomem_base = compat_ptr(udata);
60639+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
60640 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
60641 __get_user(ss.port_high, &ss32->port_high))
60642 return -EFAULT;
60643@@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
60644 for (i = 0; i < nmsgs; i++) {
60645 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
60646 return -EFAULT;
60647- if (get_user(datap, &umsgs[i].buf) ||
60648- put_user(compat_ptr(datap), &tmsgs[i].buf))
60649+ if (get_user(datap, (compat_caddr_t __user *)&umsgs[i].buf) ||
60650+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
60651 return -EFAULT;
60652 }
60653 return sys_ioctl(fd, cmd, (unsigned long)tdata);
60654@@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
60655 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
60656 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
60657 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
60658- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
60659+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
60660 return -EFAULT;
60661
60662 return ioctl_preallocate(file, p);
60663@@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
60664 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
60665 {
60666 unsigned int a, b;
60667- a = *(unsigned int *)p;
60668- b = *(unsigned int *)q;
60669+ a = *(const unsigned int *)p;
60670+ b = *(const unsigned int *)q;
60671 if (a > b)
60672 return 1;
60673 if (a < b)
60674diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
60675index 668dcab..daebcd6 100644
60676--- a/fs/configfs/dir.c
60677+++ b/fs/configfs/dir.c
60678@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60679 }
60680 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
60681 struct configfs_dirent *next;
60682- const char *name;
60683+ const unsigned char * name;
60684+ char d_name[sizeof(next->s_dentry->d_iname)];
60685 int len;
60686 struct inode *inode = NULL;
60687
60688@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
60689 continue;
60690
60691 name = configfs_get_name(next);
60692- len = strlen(name);
60693+ if (next->s_dentry && name == next->s_dentry->d_iname) {
60694+ len = next->s_dentry->d_name.len;
60695+ memcpy(d_name, name, len);
60696+ name = d_name;
60697+ } else
60698+ len = strlen(name);
60699
60700 /*
60701 * We'll have a dentry and an inode for
60702diff --git a/fs/coredump.c b/fs/coredump.c
60703index a93f7e6..d58bcbe 100644
60704--- a/fs/coredump.c
60705+++ b/fs/coredump.c
60706@@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
60707 struct pipe_inode_info *pipe = file->private_data;
60708
60709 pipe_lock(pipe);
60710- pipe->readers++;
60711- pipe->writers--;
60712+ atomic_inc(&pipe->readers);
60713+ atomic_dec(&pipe->writers);
60714 wake_up_interruptible_sync(&pipe->wait);
60715 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
60716 pipe_unlock(pipe);
60717@@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
60718 * We actually want wait_event_freezable() but then we need
60719 * to clear TIF_SIGPENDING and improve dump_interrupted().
60720 */
60721- wait_event_interruptible(pipe->wait, pipe->readers == 1);
60722+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
60723
60724 pipe_lock(pipe);
60725- pipe->readers--;
60726- pipe->writers++;
60727+ atomic_dec(&pipe->readers);
60728+ atomic_inc(&pipe->writers);
60729 pipe_unlock(pipe);
60730 }
60731
60732@@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
60733 struct files_struct *displaced;
60734 bool need_nonrelative = false;
60735 bool core_dumped = false;
60736- static atomic_t core_dump_count = ATOMIC_INIT(0);
60737+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
60738+ long signr = siginfo->si_signo;
60739+ int dumpable;
60740 struct coredump_params cprm = {
60741 .siginfo = siginfo,
60742 .regs = signal_pt_regs(),
60743@@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
60744 .mm_flags = mm->flags,
60745 };
60746
60747- audit_core_dumps(siginfo->si_signo);
60748+ audit_core_dumps(signr);
60749+
60750+ dumpable = __get_dumpable(cprm.mm_flags);
60751+
60752+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
60753+ gr_handle_brute_attach(dumpable);
60754
60755 binfmt = mm->binfmt;
60756 if (!binfmt || !binfmt->core_dump)
60757 goto fail;
60758- if (!__get_dumpable(cprm.mm_flags))
60759+ if (!dumpable)
60760 goto fail;
60761
60762 cred = prepare_creds();
60763@@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
60764 need_nonrelative = true;
60765 }
60766
60767- retval = coredump_wait(siginfo->si_signo, &core_state);
60768+ retval = coredump_wait(signr, &core_state);
60769 if (retval < 0)
60770 goto fail_creds;
60771
60772@@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
60773 }
60774 cprm.limit = RLIM_INFINITY;
60775
60776- dump_count = atomic_inc_return(&core_dump_count);
60777+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
60778 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
60779 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
60780 task_tgid_vnr(current), current->comm);
60781@@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
60782 } else {
60783 struct inode *inode;
60784
60785+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
60786+
60787 if (cprm.limit < binfmt->min_coredump)
60788 goto fail_unlock;
60789
60790@@ -673,7 +682,7 @@ close_fail:
60791 filp_close(cprm.file, NULL);
60792 fail_dropcount:
60793 if (ispipe)
60794- atomic_dec(&core_dump_count);
60795+ atomic_dec_unchecked(&core_dump_count);
60796 fail_unlock:
60797 kfree(cn.corename);
60798 coredump_finish(mm, core_dumped);
60799@@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
60800 struct file *file = cprm->file;
60801 loff_t pos = file->f_pos;
60802 ssize_t n;
60803+
60804+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
60805 if (cprm->written + nr > cprm->limit)
60806 return 0;
60807 while (nr) {
60808diff --git a/fs/dcache.c b/fs/dcache.c
60809index 34b40be8..2003532 100644
60810--- a/fs/dcache.c
60811+++ b/fs/dcache.c
60812@@ -478,7 +478,7 @@ static void __dentry_kill(struct dentry *dentry)
60813 * dentry_iput drops the locks, at which point nobody (except
60814 * transient RCU lookups) can reach this dentry.
60815 */
60816- BUG_ON((int)dentry->d_lockref.count > 0);
60817+ BUG_ON((int)__lockref_read(&dentry->d_lockref) > 0);
60818 this_cpu_dec(nr_dentry);
60819 if (dentry->d_op && dentry->d_op->d_release)
60820 dentry->d_op->d_release(dentry);
60821@@ -531,7 +531,7 @@ static inline struct dentry *lock_parent(struct dentry *dentry)
60822 struct dentry *parent = dentry->d_parent;
60823 if (IS_ROOT(dentry))
60824 return NULL;
60825- if (unlikely((int)dentry->d_lockref.count < 0))
60826+ if (unlikely((int)__lockref_read(&dentry->d_lockref) < 0))
60827 return NULL;
60828 if (likely(spin_trylock(&parent->d_lock)))
60829 return parent;
60830@@ -608,7 +608,7 @@ repeat:
60831 dentry->d_flags |= DCACHE_REFERENCED;
60832 dentry_lru_add(dentry);
60833
60834- dentry->d_lockref.count--;
60835+ __lockref_dec(&dentry->d_lockref);
60836 spin_unlock(&dentry->d_lock);
60837 return;
60838
60839@@ -663,7 +663,7 @@ int d_invalidate(struct dentry * dentry)
60840 * We also need to leave mountpoints alone,
60841 * directory or not.
60842 */
60843- if (dentry->d_lockref.count > 1 && dentry->d_inode) {
60844+ if (__lockref_read(&dentry->d_lockref) > 1 && dentry->d_inode) {
60845 if (S_ISDIR(dentry->d_inode->i_mode) || d_mountpoint(dentry)) {
60846 spin_unlock(&dentry->d_lock);
60847 return -EBUSY;
60848@@ -679,7 +679,7 @@ EXPORT_SYMBOL(d_invalidate);
60849 /* This must be called with d_lock held */
60850 static inline void __dget_dlock(struct dentry *dentry)
60851 {
60852- dentry->d_lockref.count++;
60853+ __lockref_inc(&dentry->d_lockref);
60854 }
60855
60856 static inline void __dget(struct dentry *dentry)
60857@@ -720,8 +720,8 @@ repeat:
60858 goto repeat;
60859 }
60860 rcu_read_unlock();
60861- BUG_ON(!ret->d_lockref.count);
60862- ret->d_lockref.count++;
60863+ BUG_ON(!__lockref_read(&ret->d_lockref));
60864+ __lockref_inc(&ret->d_lockref);
60865 spin_unlock(&ret->d_lock);
60866 return ret;
60867 }
60868@@ -798,7 +798,7 @@ restart:
60869 spin_lock(&inode->i_lock);
60870 hlist_for_each_entry(dentry, &inode->i_dentry, d_alias) {
60871 spin_lock(&dentry->d_lock);
60872- if (!dentry->d_lockref.count) {
60873+ if (!__lockref_read(&dentry->d_lockref)) {
60874 /*
60875 * inform the fs via d_prune that this dentry
60876 * is about to be unhashed and destroyed.
60877@@ -841,7 +841,7 @@ static void shrink_dentry_list(struct list_head *list)
60878 * We found an inuse dentry which was not removed from
60879 * the LRU because of laziness during lookup. Do not free it.
60880 */
60881- if ((int)dentry->d_lockref.count > 0) {
60882+ if ((int)__lockref_read(&dentry->d_lockref) > 0) {
60883 spin_unlock(&dentry->d_lock);
60884 if (parent)
60885 spin_unlock(&parent->d_lock);
60886@@ -879,8 +879,8 @@ static void shrink_dentry_list(struct list_head *list)
60887 dentry = parent;
60888 while (dentry && !lockref_put_or_lock(&dentry->d_lockref)) {
60889 parent = lock_parent(dentry);
60890- if (dentry->d_lockref.count != 1) {
60891- dentry->d_lockref.count--;
60892+ if (__lockref_read(&dentry->d_lockref) != 1) {
60893+ __lockref_inc(&dentry->d_lockref);
60894 spin_unlock(&dentry->d_lock);
60895 if (parent)
60896 spin_unlock(&parent->d_lock);
60897@@ -920,7 +920,7 @@ dentry_lru_isolate(struct list_head *item, spinlock_t *lru_lock, void *arg)
60898 * counts, just remove them from the LRU. Otherwise give them
60899 * another pass through the LRU.
60900 */
60901- if (dentry->d_lockref.count) {
60902+ if (__lockref_read(&dentry->d_lockref) > 0) {
60903 d_lru_isolate(dentry);
60904 spin_unlock(&dentry->d_lock);
60905 return LRU_REMOVED;
60906@@ -1149,6 +1149,7 @@ out_unlock:
60907 return;
60908
60909 rename_retry:
60910+ done_seqretry(&rename_lock, seq);
60911 if (!retry)
60912 return;
60913 seq = 1;
60914@@ -1255,7 +1256,7 @@ static enum d_walk_ret select_collect(void *_data, struct dentry *dentry)
60915 } else {
60916 if (dentry->d_flags & DCACHE_LRU_LIST)
60917 d_lru_del(dentry);
60918- if (!dentry->d_lockref.count) {
60919+ if (!__lockref_read(&dentry->d_lockref)) {
60920 d_shrink_add(dentry, &data->dispose);
60921 data->found++;
60922 }
60923@@ -1303,7 +1304,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60924 return D_WALK_CONTINUE;
60925
60926 /* root with refcount 1 is fine */
60927- if (dentry == _data && dentry->d_lockref.count == 1)
60928+ if (dentry == _data && __lockref_read(&dentry->d_lockref) == 1)
60929 return D_WALK_CONTINUE;
60930
60931 printk(KERN_ERR "BUG: Dentry %p{i=%lx,n=%pd} "
60932@@ -1312,7 +1313,7 @@ static enum d_walk_ret umount_check(void *_data, struct dentry *dentry)
60933 dentry->d_inode ?
60934 dentry->d_inode->i_ino : 0UL,
60935 dentry,
60936- dentry->d_lockref.count,
60937+ __lockref_read(&dentry->d_lockref),
60938 dentry->d_sb->s_type->name,
60939 dentry->d_sb->s_id);
60940 WARN_ON(1);
60941@@ -1438,7 +1439,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60942 */
60943 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
60944 if (name->len > DNAME_INLINE_LEN-1) {
60945- dname = kmalloc(name->len + 1, GFP_KERNEL);
60946+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
60947 if (!dname) {
60948 kmem_cache_free(dentry_cache, dentry);
60949 return NULL;
60950@@ -1456,7 +1457,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
60951 smp_wmb();
60952 dentry->d_name.name = dname;
60953
60954- dentry->d_lockref.count = 1;
60955+ __lockref_set(&dentry->d_lockref, 1);
60956 dentry->d_flags = 0;
60957 spin_lock_init(&dentry->d_lock);
60958 seqcount_init(&dentry->d_seq);
60959@@ -2196,7 +2197,7 @@ struct dentry *__d_lookup(const struct dentry *parent, const struct qstr *name)
60960 goto next;
60961 }
60962
60963- dentry->d_lockref.count++;
60964+ __lockref_inc(&dentry->d_lockref);
60965 found = dentry;
60966 spin_unlock(&dentry->d_lock);
60967 break;
60968@@ -2295,7 +2296,7 @@ again:
60969 spin_lock(&dentry->d_lock);
60970 inode = dentry->d_inode;
60971 isdir = S_ISDIR(inode->i_mode);
60972- if (dentry->d_lockref.count == 1) {
60973+ if (__lockref_read(&dentry->d_lockref) == 1) {
60974 if (!spin_trylock(&inode->i_lock)) {
60975 spin_unlock(&dentry->d_lock);
60976 cpu_relax();
60977@@ -3307,7 +3308,7 @@ static enum d_walk_ret d_genocide_kill(void *data, struct dentry *dentry)
60978
60979 if (!(dentry->d_flags & DCACHE_GENOCIDE)) {
60980 dentry->d_flags |= DCACHE_GENOCIDE;
60981- dentry->d_lockref.count--;
60982+ __lockref_dec(&dentry->d_lockref);
60983 }
60984 }
60985 return D_WALK_CONTINUE;
60986@@ -3423,7 +3424,8 @@ void __init vfs_caches_init(unsigned long mempages)
60987 mempages -= reserve;
60988
60989 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
60990- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
60991+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
60992+ SLAB_NO_SANITIZE, NULL);
60993
60994 dcache_init();
60995 inode_init();
60996diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
60997index 1e3b99d..6512101 100644
60998--- a/fs/debugfs/inode.c
60999+++ b/fs/debugfs/inode.c
61000@@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
61001 */
61002 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
61003 {
61004+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
61005+ return __create_file(name, S_IFDIR | S_IRWXU,
61006+#else
61007 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
61008+#endif
61009 parent, NULL, NULL);
61010 }
61011 EXPORT_SYMBOL_GPL(debugfs_create_dir);
61012diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
61013index 57ee4c5..ecb13b0 100644
61014--- a/fs/ecryptfs/inode.c
61015+++ b/fs/ecryptfs/inode.c
61016@@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
61017 old_fs = get_fs();
61018 set_fs(get_ds());
61019 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
61020- (char __user *)lower_buf,
61021+ (char __force_user *)lower_buf,
61022 PATH_MAX);
61023 set_fs(old_fs);
61024 if (rc < 0)
61025diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
61026index e4141f2..d8263e8 100644
61027--- a/fs/ecryptfs/miscdev.c
61028+++ b/fs/ecryptfs/miscdev.c
61029@@ -304,7 +304,7 @@ check_list:
61030 goto out_unlock_msg_ctx;
61031 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
61032 if (msg_ctx->msg) {
61033- if (copy_to_user(&buf[i], packet_length, packet_length_size))
61034+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
61035 goto out_unlock_msg_ctx;
61036 i += packet_length_size;
61037 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
61038diff --git a/fs/exec.c b/fs/exec.c
61039index a2b42a9..1e924b3 100644
61040--- a/fs/exec.c
61041+++ b/fs/exec.c
61042@@ -56,8 +56,20 @@
61043 #include <linux/pipe_fs_i.h>
61044 #include <linux/oom.h>
61045 #include <linux/compat.h>
61046+#include <linux/random.h>
61047+#include <linux/seq_file.h>
61048+#include <linux/coredump.h>
61049+#include <linux/mman.h>
61050+
61051+#ifdef CONFIG_PAX_REFCOUNT
61052+#include <linux/kallsyms.h>
61053+#include <linux/kdebug.h>
61054+#endif
61055+
61056+#include <trace/events/fs.h>
61057
61058 #include <asm/uaccess.h>
61059+#include <asm/sections.h>
61060 #include <asm/mmu_context.h>
61061 #include <asm/tlb.h>
61062
61063@@ -66,19 +78,34 @@
61064
61065 #include <trace/events/sched.h>
61066
61067+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
61068+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
61069+{
61070+ 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");
61071+}
61072+#endif
61073+
61074+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
61075+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
61076+EXPORT_SYMBOL(pax_set_initial_flags_func);
61077+#endif
61078+
61079 int suid_dumpable = 0;
61080
61081 static LIST_HEAD(formats);
61082 static DEFINE_RWLOCK(binfmt_lock);
61083
61084+extern int gr_process_kernel_exec_ban(void);
61085+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
61086+
61087 void __register_binfmt(struct linux_binfmt * fmt, int insert)
61088 {
61089 BUG_ON(!fmt);
61090 if (WARN_ON(!fmt->load_binary))
61091 return;
61092 write_lock(&binfmt_lock);
61093- insert ? list_add(&fmt->lh, &formats) :
61094- list_add_tail(&fmt->lh, &formats);
61095+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
61096+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
61097 write_unlock(&binfmt_lock);
61098 }
61099
61100@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
61101 void unregister_binfmt(struct linux_binfmt * fmt)
61102 {
61103 write_lock(&binfmt_lock);
61104- list_del(&fmt->lh);
61105+ pax_list_del((struct list_head *)&fmt->lh);
61106 write_unlock(&binfmt_lock);
61107 }
61108
61109@@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61110 int write)
61111 {
61112 struct page *page;
61113- int ret;
61114
61115-#ifdef CONFIG_STACK_GROWSUP
61116- if (write) {
61117- ret = expand_downwards(bprm->vma, pos);
61118- if (ret < 0)
61119- return NULL;
61120- }
61121-#endif
61122- ret = get_user_pages(current, bprm->mm, pos,
61123- 1, write, 1, &page, NULL);
61124- if (ret <= 0)
61125+ if (0 > expand_downwards(bprm->vma, pos))
61126+ return NULL;
61127+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
61128 return NULL;
61129
61130 if (write) {
61131@@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
61132 if (size <= ARG_MAX)
61133 return page;
61134
61135+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61136+ // only allow 512KB for argv+env on suid/sgid binaries
61137+ // to prevent easy ASLR exhaustion
61138+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
61139+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
61140+ (size > (512 * 1024))) {
61141+ put_page(page);
61142+ return NULL;
61143+ }
61144+#endif
61145+
61146 /*
61147 * Limit to 1/4-th the stack size for the argv+env strings.
61148 * This ensures that:
61149@@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61150 vma->vm_end = STACK_TOP_MAX;
61151 vma->vm_start = vma->vm_end - PAGE_SIZE;
61152 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
61153+
61154+#ifdef CONFIG_PAX_SEGMEXEC
61155+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
61156+#endif
61157+
61158 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
61159 INIT_LIST_HEAD(&vma->anon_vma_chain);
61160
61161@@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
61162 mm->stack_vm = mm->total_vm = 1;
61163 up_write(&mm->mmap_sem);
61164 bprm->p = vma->vm_end - sizeof(void *);
61165+
61166+#ifdef CONFIG_PAX_RANDUSTACK
61167+ if (randomize_va_space)
61168+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
61169+#endif
61170+
61171 return 0;
61172 err:
61173 up_write(&mm->mmap_sem);
61174@@ -395,7 +436,7 @@ struct user_arg_ptr {
61175 } ptr;
61176 };
61177
61178-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61179+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61180 {
61181 const char __user *native;
61182
61183@@ -404,14 +445,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
61184 compat_uptr_t compat;
61185
61186 if (get_user(compat, argv.ptr.compat + nr))
61187- return ERR_PTR(-EFAULT);
61188+ return (const char __force_user *)ERR_PTR(-EFAULT);
61189
61190 return compat_ptr(compat);
61191 }
61192 #endif
61193
61194 if (get_user(native, argv.ptr.native + nr))
61195- return ERR_PTR(-EFAULT);
61196+ return (const char __force_user *)ERR_PTR(-EFAULT);
61197
61198 return native;
61199 }
61200@@ -430,7 +471,7 @@ static int count(struct user_arg_ptr argv, int max)
61201 if (!p)
61202 break;
61203
61204- if (IS_ERR(p))
61205+ if (IS_ERR((const char __force_kernel *)p))
61206 return -EFAULT;
61207
61208 if (i >= max)
61209@@ -465,7 +506,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
61210
61211 ret = -EFAULT;
61212 str = get_user_arg_ptr(argv, argc);
61213- if (IS_ERR(str))
61214+ if (IS_ERR((const char __force_kernel *)str))
61215 goto out;
61216
61217 len = strnlen_user(str, MAX_ARG_STRLEN);
61218@@ -547,7 +588,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
61219 int r;
61220 mm_segment_t oldfs = get_fs();
61221 struct user_arg_ptr argv = {
61222- .ptr.native = (const char __user *const __user *)__argv,
61223+ .ptr.native = (const char __user * const __force_user *)__argv,
61224 };
61225
61226 set_fs(KERNEL_DS);
61227@@ -582,7 +623,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61228 unsigned long new_end = old_end - shift;
61229 struct mmu_gather tlb;
61230
61231- BUG_ON(new_start > new_end);
61232+ if (new_start >= new_end || new_start < mmap_min_addr)
61233+ return -ENOMEM;
61234
61235 /*
61236 * ensure there are no vmas between where we want to go
61237@@ -591,6 +633,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
61238 if (vma != find_vma(mm, new_start))
61239 return -EFAULT;
61240
61241+#ifdef CONFIG_PAX_SEGMEXEC
61242+ BUG_ON(pax_find_mirror_vma(vma));
61243+#endif
61244+
61245 /*
61246 * cover the whole range: [new_start, old_end)
61247 */
61248@@ -671,10 +717,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61249 stack_top = arch_align_stack(stack_top);
61250 stack_top = PAGE_ALIGN(stack_top);
61251
61252- if (unlikely(stack_top < mmap_min_addr) ||
61253- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
61254- return -ENOMEM;
61255-
61256 stack_shift = vma->vm_end - stack_top;
61257
61258 bprm->p -= stack_shift;
61259@@ -686,8 +728,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
61260 bprm->exec -= stack_shift;
61261
61262 down_write(&mm->mmap_sem);
61263+
61264+ /* Move stack pages down in memory. */
61265+ if (stack_shift) {
61266+ ret = shift_arg_pages(vma, stack_shift);
61267+ if (ret)
61268+ goto out_unlock;
61269+ }
61270+
61271 vm_flags = VM_STACK_FLAGS;
61272
61273+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61274+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
61275+ vm_flags &= ~VM_EXEC;
61276+
61277+#ifdef CONFIG_PAX_MPROTECT
61278+ if (mm->pax_flags & MF_PAX_MPROTECT)
61279+ vm_flags &= ~VM_MAYEXEC;
61280+#endif
61281+
61282+ }
61283+#endif
61284+
61285 /*
61286 * Adjust stack execute permissions; explicitly enable for
61287 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
61288@@ -706,13 +768,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
61289 goto out_unlock;
61290 BUG_ON(prev != vma);
61291
61292- /* Move stack pages down in memory. */
61293- if (stack_shift) {
61294- ret = shift_arg_pages(vma, stack_shift);
61295- if (ret)
61296- goto out_unlock;
61297- }
61298-
61299 /* mprotect_fixup is overkill to remove the temporary stack flags */
61300 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
61301
61302@@ -736,6 +791,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
61303 #endif
61304 current->mm->start_stack = bprm->p;
61305 ret = expand_stack(vma, stack_base);
61306+
61307+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
61308+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
61309+ unsigned long size;
61310+ vm_flags_t vm_flags;
61311+
61312+ size = STACK_TOP - vma->vm_end;
61313+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
61314+
61315+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
61316+
61317+#ifdef CONFIG_X86
61318+ if (!ret) {
61319+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
61320+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
61321+ }
61322+#endif
61323+
61324+ }
61325+#endif
61326+
61327 if (ret)
61328 ret = -EFAULT;
61329
61330@@ -771,6 +847,8 @@ static struct file *do_open_exec(struct filename *name)
61331
61332 fsnotify_open(file);
61333
61334+ trace_open_exec(name->name);
61335+
61336 err = deny_write_access(file);
61337 if (err)
61338 goto exit;
61339@@ -800,7 +878,7 @@ int kernel_read(struct file *file, loff_t offset,
61340 old_fs = get_fs();
61341 set_fs(get_ds());
61342 /* The cast to a user pointer is valid due to the set_fs() */
61343- result = vfs_read(file, (void __user *)addr, count, &pos);
61344+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
61345 set_fs(old_fs);
61346 return result;
61347 }
61348@@ -845,6 +923,7 @@ static int exec_mmap(struct mm_struct *mm)
61349 tsk->mm = mm;
61350 tsk->active_mm = mm;
61351 activate_mm(active_mm, mm);
61352+ populate_stack();
61353 tsk->mm->vmacache_seqnum = 0;
61354 vmacache_flush(tsk);
61355 task_unlock(tsk);
61356@@ -1243,7 +1322,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
61357 }
61358 rcu_read_unlock();
61359
61360- if (p->fs->users > n_fs)
61361+ if (atomic_read(&p->fs->users) > n_fs)
61362 bprm->unsafe |= LSM_UNSAFE_SHARE;
61363 else
61364 p->fs->in_exec = 1;
61365@@ -1419,6 +1498,31 @@ static int exec_binprm(struct linux_binprm *bprm)
61366 return ret;
61367 }
61368
61369+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61370+static DEFINE_PER_CPU(u64, exec_counter);
61371+static int __init init_exec_counters(void)
61372+{
61373+ unsigned int cpu;
61374+
61375+ for_each_possible_cpu(cpu) {
61376+ per_cpu(exec_counter, cpu) = (u64)cpu;
61377+ }
61378+
61379+ return 0;
61380+}
61381+early_initcall(init_exec_counters);
61382+static inline void increment_exec_counter(void)
61383+{
61384+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
61385+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
61386+}
61387+#else
61388+static inline void increment_exec_counter(void) {}
61389+#endif
61390+
61391+extern void gr_handle_exec_args(struct linux_binprm *bprm,
61392+ struct user_arg_ptr argv);
61393+
61394 /*
61395 * sys_execve() executes a new program.
61396 */
61397@@ -1426,6 +1530,11 @@ static int do_execve_common(struct filename *filename,
61398 struct user_arg_ptr argv,
61399 struct user_arg_ptr envp)
61400 {
61401+#ifdef CONFIG_GRKERNSEC
61402+ struct file *old_exec_file;
61403+ struct acl_subject_label *old_acl;
61404+ struct rlimit old_rlim[RLIM_NLIMITS];
61405+#endif
61406 struct linux_binprm *bprm;
61407 struct file *file;
61408 struct files_struct *displaced;
61409@@ -1434,6 +1543,8 @@ static int do_execve_common(struct filename *filename,
61410 if (IS_ERR(filename))
61411 return PTR_ERR(filename);
61412
61413+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
61414+
61415 /*
61416 * We move the actual failure in case of RLIMIT_NPROC excess from
61417 * set*uid() to execve() because too many poorly written programs
61418@@ -1471,11 +1582,21 @@ static int do_execve_common(struct filename *filename,
61419 if (IS_ERR(file))
61420 goto out_unmark;
61421
61422+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
61423+ retval = -EPERM;
61424+ goto out_unmark;
61425+ }
61426+
61427 sched_exec();
61428
61429 bprm->file = file;
61430 bprm->filename = bprm->interp = filename->name;
61431
61432+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
61433+ retval = -EACCES;
61434+ goto out_unmark;
61435+ }
61436+
61437 retval = bprm_mm_init(bprm);
61438 if (retval)
61439 goto out_unmark;
61440@@ -1492,24 +1613,70 @@ static int do_execve_common(struct filename *filename,
61441 if (retval < 0)
61442 goto out;
61443
61444+#ifdef CONFIG_GRKERNSEC
61445+ old_acl = current->acl;
61446+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
61447+ old_exec_file = current->exec_file;
61448+ get_file(file);
61449+ current->exec_file = file;
61450+#endif
61451+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61452+ /* limit suid stack to 8MB
61453+ * we saved the old limits above and will restore them if this exec fails
61454+ */
61455+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
61456+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
61457+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
61458+#endif
61459+
61460+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
61461+ retval = -EPERM;
61462+ goto out_fail;
61463+ }
61464+
61465+ if (!gr_tpe_allow(file)) {
61466+ retval = -EACCES;
61467+ goto out_fail;
61468+ }
61469+
61470+ if (gr_check_crash_exec(file)) {
61471+ retval = -EACCES;
61472+ goto out_fail;
61473+ }
61474+
61475+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
61476+ bprm->unsafe);
61477+ if (retval < 0)
61478+ goto out_fail;
61479+
61480 retval = copy_strings_kernel(1, &bprm->filename, bprm);
61481 if (retval < 0)
61482- goto out;
61483+ goto out_fail;
61484
61485 bprm->exec = bprm->p;
61486 retval = copy_strings(bprm->envc, envp, bprm);
61487 if (retval < 0)
61488- goto out;
61489+ goto out_fail;
61490
61491 retval = copy_strings(bprm->argc, argv, bprm);
61492 if (retval < 0)
61493- goto out;
61494+ goto out_fail;
61495+
61496+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
61497+
61498+ gr_handle_exec_args(bprm, argv);
61499
61500 retval = exec_binprm(bprm);
61501 if (retval < 0)
61502- goto out;
61503+ goto out_fail;
61504+#ifdef CONFIG_GRKERNSEC
61505+ if (old_exec_file)
61506+ fput(old_exec_file);
61507+#endif
61508
61509 /* execve succeeded */
61510+
61511+ increment_exec_counter();
61512 current->fs->in_exec = 0;
61513 current->in_execve = 0;
61514 acct_update_integrals(current);
61515@@ -1520,6 +1687,14 @@ static int do_execve_common(struct filename *filename,
61516 put_files_struct(displaced);
61517 return retval;
61518
61519+out_fail:
61520+#ifdef CONFIG_GRKERNSEC
61521+ current->acl = old_acl;
61522+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
61523+ fput(current->exec_file);
61524+ current->exec_file = old_exec_file;
61525+#endif
61526+
61527 out:
61528 if (bprm->mm) {
61529 acct_arg_size(bprm, 0);
61530@@ -1611,3 +1786,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
61531 return compat_do_execve(getname(filename), argv, envp);
61532 }
61533 #endif
61534+
61535+int pax_check_flags(unsigned long *flags)
61536+{
61537+ int retval = 0;
61538+
61539+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
61540+ if (*flags & MF_PAX_SEGMEXEC)
61541+ {
61542+ *flags &= ~MF_PAX_SEGMEXEC;
61543+ retval = -EINVAL;
61544+ }
61545+#endif
61546+
61547+ if ((*flags & MF_PAX_PAGEEXEC)
61548+
61549+#ifdef CONFIG_PAX_PAGEEXEC
61550+ && (*flags & MF_PAX_SEGMEXEC)
61551+#endif
61552+
61553+ )
61554+ {
61555+ *flags &= ~MF_PAX_PAGEEXEC;
61556+ retval = -EINVAL;
61557+ }
61558+
61559+ if ((*flags & MF_PAX_MPROTECT)
61560+
61561+#ifdef CONFIG_PAX_MPROTECT
61562+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61563+#endif
61564+
61565+ )
61566+ {
61567+ *flags &= ~MF_PAX_MPROTECT;
61568+ retval = -EINVAL;
61569+ }
61570+
61571+ if ((*flags & MF_PAX_EMUTRAMP)
61572+
61573+#ifdef CONFIG_PAX_EMUTRAMP
61574+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
61575+#endif
61576+
61577+ )
61578+ {
61579+ *flags &= ~MF_PAX_EMUTRAMP;
61580+ retval = -EINVAL;
61581+ }
61582+
61583+ return retval;
61584+}
61585+
61586+EXPORT_SYMBOL(pax_check_flags);
61587+
61588+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
61589+char *pax_get_path(const struct path *path, char *buf, int buflen)
61590+{
61591+ char *pathname = d_path(path, buf, buflen);
61592+
61593+ if (IS_ERR(pathname))
61594+ goto toolong;
61595+
61596+ pathname = mangle_path(buf, pathname, "\t\n\\");
61597+ if (!pathname)
61598+ goto toolong;
61599+
61600+ *pathname = 0;
61601+ return buf;
61602+
61603+toolong:
61604+ return "<path too long>";
61605+}
61606+EXPORT_SYMBOL(pax_get_path);
61607+
61608+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
61609+{
61610+ struct task_struct *tsk = current;
61611+ struct mm_struct *mm = current->mm;
61612+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
61613+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
61614+ char *path_exec = NULL;
61615+ char *path_fault = NULL;
61616+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
61617+ siginfo_t info = { };
61618+
61619+ if (buffer_exec && buffer_fault) {
61620+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
61621+
61622+ down_read(&mm->mmap_sem);
61623+ vma = mm->mmap;
61624+ while (vma && (!vma_exec || !vma_fault)) {
61625+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
61626+ vma_exec = vma;
61627+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
61628+ vma_fault = vma;
61629+ vma = vma->vm_next;
61630+ }
61631+ if (vma_exec)
61632+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
61633+ if (vma_fault) {
61634+ start = vma_fault->vm_start;
61635+ end = vma_fault->vm_end;
61636+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
61637+ if (vma_fault->vm_file)
61638+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
61639+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
61640+ path_fault = "<heap>";
61641+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
61642+ path_fault = "<stack>";
61643+ else
61644+ path_fault = "<anonymous mapping>";
61645+ }
61646+ up_read(&mm->mmap_sem);
61647+ }
61648+ if (tsk->signal->curr_ip)
61649+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
61650+ else
61651+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
61652+ 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),
61653+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
61654+ free_page((unsigned long)buffer_exec);
61655+ free_page((unsigned long)buffer_fault);
61656+ pax_report_insns(regs, pc, sp);
61657+ info.si_signo = SIGKILL;
61658+ info.si_errno = 0;
61659+ info.si_code = SI_KERNEL;
61660+ info.si_pid = 0;
61661+ info.si_uid = 0;
61662+ do_coredump(&info);
61663+}
61664+#endif
61665+
61666+#ifdef CONFIG_PAX_REFCOUNT
61667+void pax_report_refcount_overflow(struct pt_regs *regs)
61668+{
61669+ if (current->signal->curr_ip)
61670+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
61671+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
61672+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61673+ else
61674+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
61675+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
61676+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
61677+ preempt_disable();
61678+ show_regs(regs);
61679+ preempt_enable();
61680+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
61681+}
61682+#endif
61683+
61684+#ifdef CONFIG_PAX_USERCOPY
61685+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
61686+static noinline int check_stack_object(const void *obj, unsigned long len)
61687+{
61688+ const void * const stack = task_stack_page(current);
61689+ const void * const stackend = stack + THREAD_SIZE;
61690+
61691+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61692+ const void *frame = NULL;
61693+ const void *oldframe;
61694+#endif
61695+
61696+ if (obj + len < obj)
61697+ return -1;
61698+
61699+ if (obj + len <= stack || stackend <= obj)
61700+ return 0;
61701+
61702+ if (obj < stack || stackend < obj + len)
61703+ return -1;
61704+
61705+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
61706+ oldframe = __builtin_frame_address(1);
61707+ if (oldframe)
61708+ frame = __builtin_frame_address(2);
61709+ /*
61710+ low ----------------------------------------------> high
61711+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
61712+ ^----------------^
61713+ allow copies only within here
61714+ */
61715+ while (stack <= frame && frame < stackend) {
61716+ /* if obj + len extends past the last frame, this
61717+ check won't pass and the next frame will be 0,
61718+ causing us to bail out and correctly report
61719+ the copy as invalid
61720+ */
61721+ if (obj + len <= frame)
61722+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
61723+ oldframe = frame;
61724+ frame = *(const void * const *)frame;
61725+ }
61726+ return -1;
61727+#else
61728+ return 1;
61729+#endif
61730+}
61731+
61732+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
61733+{
61734+ if (current->signal->curr_ip)
61735+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61736+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61737+ else
61738+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
61739+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
61740+ dump_stack();
61741+ gr_handle_kernel_exploit();
61742+ do_group_exit(SIGKILL);
61743+}
61744+#endif
61745+
61746+#ifdef CONFIG_PAX_USERCOPY
61747+
61748+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
61749+{
61750+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
61751+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
61752+#ifdef CONFIG_MODULES
61753+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
61754+#else
61755+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
61756+#endif
61757+
61758+#else
61759+ unsigned long textlow = (unsigned long)_stext;
61760+ unsigned long texthigh = (unsigned long)_etext;
61761+
61762+#ifdef CONFIG_X86_64
61763+ /* check against linear mapping as well */
61764+ if (high > (unsigned long)__va(__pa(textlow)) &&
61765+ low < (unsigned long)__va(__pa(texthigh)))
61766+ return true;
61767+#endif
61768+
61769+#endif
61770+
61771+ if (high <= textlow || low >= texthigh)
61772+ return false;
61773+ else
61774+ return true;
61775+}
61776+#endif
61777+
61778+void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
61779+{
61780+#ifdef CONFIG_PAX_USERCOPY
61781+ const char *type;
61782+#endif
61783+
61784+#ifndef CONFIG_STACK_GROWSUP
61785+ unsigned long stackstart = (unsigned long)task_stack_page(current);
61786+ unsigned long currentsp = (unsigned long)&stackstart;
61787+ if (unlikely((currentsp < stackstart + 512 ||
61788+ currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
61789+ BUG();
61790+#endif
61791+
61792+#ifndef CONFIG_PAX_USERCOPY_DEBUG
61793+ if (const_size)
61794+ return;
61795+#endif
61796+
61797+#ifdef CONFIG_PAX_USERCOPY
61798+ if (!n)
61799+ return;
61800+
61801+ type = check_heap_object(ptr, n);
61802+ if (!type) {
61803+ int ret = check_stack_object(ptr, n);
61804+ if (ret == 1 || ret == 2)
61805+ return;
61806+ if (ret == 0) {
61807+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
61808+ type = "<kernel text>";
61809+ else
61810+ return;
61811+ } else
61812+ type = "<process stack>";
61813+ }
61814+
61815+ pax_report_usercopy(ptr, n, to_user, type);
61816+#endif
61817+
61818+}
61819+EXPORT_SYMBOL(__check_object_size);
61820+
61821+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
61822+void pax_track_stack(void)
61823+{
61824+ unsigned long sp = (unsigned long)&sp;
61825+ if (sp < current_thread_info()->lowest_stack &&
61826+ sp > (unsigned long)task_stack_page(current))
61827+ current_thread_info()->lowest_stack = sp;
61828+ if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
61829+ BUG();
61830+}
61831+EXPORT_SYMBOL(pax_track_stack);
61832+#endif
61833+
61834+#ifdef CONFIG_PAX_SIZE_OVERFLOW
61835+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
61836+{
61837+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
61838+ dump_stack();
61839+ do_group_exit(SIGKILL);
61840+}
61841+EXPORT_SYMBOL(report_size_overflow);
61842+#endif
61843diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
61844index 9f9992b..8b59411 100644
61845--- a/fs/ext2/balloc.c
61846+++ b/fs/ext2/balloc.c
61847@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
61848
61849 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61850 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61851- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61852+ if (free_blocks < root_blocks + 1 &&
61853 !uid_eq(sbi->s_resuid, current_fsuid()) &&
61854 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61855- !in_group_p (sbi->s_resgid))) {
61856+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61857 return 0;
61858 }
61859 return 1;
61860diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
61861index 9142614..97484fa 100644
61862--- a/fs/ext2/xattr.c
61863+++ b/fs/ext2/xattr.c
61864@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
61865 struct buffer_head *bh = NULL;
61866 struct ext2_xattr_entry *entry;
61867 char *end;
61868- size_t rest = buffer_size;
61869+ size_t rest = buffer_size, total_size = 0;
61870 int error;
61871
61872 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
61873@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
61874 buffer += size;
61875 }
61876 rest -= size;
61877+ total_size += size;
61878 }
61879 }
61880- error = buffer_size - rest; /* total size */
61881+ error = total_size;
61882
61883 cleanup:
61884 brelse(bh);
61885diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
61886index 158b5d4..2432610 100644
61887--- a/fs/ext3/balloc.c
61888+++ b/fs/ext3/balloc.c
61889@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
61890
61891 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
61892 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
61893- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
61894+ if (free_blocks < root_blocks + 1 &&
61895 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
61896 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
61897- !in_group_p (sbi->s_resgid))) {
61898+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
61899 return 0;
61900 }
61901 return 1;
61902diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
61903index c6874be..f8a6ae8 100644
61904--- a/fs/ext3/xattr.c
61905+++ b/fs/ext3/xattr.c
61906@@ -330,7 +330,7 @@ static int
61907 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61908 char *buffer, size_t buffer_size)
61909 {
61910- size_t rest = buffer_size;
61911+ size_t rest = buffer_size, total_size = 0;
61912
61913 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
61914 const struct xattr_handler *handler =
61915@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
61916 buffer += size;
61917 }
61918 rest -= size;
61919+ total_size += size;
61920 }
61921 }
61922- return buffer_size - rest;
61923+ return total_size;
61924 }
61925
61926 static int
61927diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
61928index e069155..b825b08 100644
61929--- a/fs/ext4/balloc.c
61930+++ b/fs/ext4/balloc.c
61931@@ -557,8 +557,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
61932 /* Hm, nope. Are (enough) root reserved clusters available? */
61933 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
61934 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
61935- capable(CAP_SYS_RESOURCE) ||
61936- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
61937+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
61938+ capable_nolog(CAP_SYS_RESOURCE)) {
61939
61940 if (free_clusters >= (nclusters + dirty_clusters +
61941 resv_clusters))
61942diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
61943index 96ac9d3..1c30e7e6 100644
61944--- a/fs/ext4/ext4.h
61945+++ b/fs/ext4/ext4.h
61946@@ -1275,19 +1275,19 @@ struct ext4_sb_info {
61947 unsigned long s_mb_last_start;
61948
61949 /* stats for buddy allocator */
61950- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
61951- atomic_t s_bal_success; /* we found long enough chunks */
61952- atomic_t s_bal_allocated; /* in blocks */
61953- atomic_t s_bal_ex_scanned; /* total extents scanned */
61954- atomic_t s_bal_goals; /* goal hits */
61955- atomic_t s_bal_breaks; /* too long searches */
61956- atomic_t s_bal_2orders; /* 2^order hits */
61957+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
61958+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
61959+ atomic_unchecked_t s_bal_allocated; /* in blocks */
61960+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
61961+ atomic_unchecked_t s_bal_goals; /* goal hits */
61962+ atomic_unchecked_t s_bal_breaks; /* too long searches */
61963+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
61964 spinlock_t s_bal_lock;
61965 unsigned long s_mb_buddies_generated;
61966 unsigned long long s_mb_generation_time;
61967- atomic_t s_mb_lost_chunks;
61968- atomic_t s_mb_preallocated;
61969- atomic_t s_mb_discarded;
61970+ atomic_unchecked_t s_mb_lost_chunks;
61971+ atomic_unchecked_t s_mb_preallocated;
61972+ atomic_unchecked_t s_mb_discarded;
61973 atomic_t s_lock_busy;
61974
61975 /* locality groups */
61976diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
61977index 8b0f9ef..cb9f620 100644
61978--- a/fs/ext4/mballoc.c
61979+++ b/fs/ext4/mballoc.c
61980@@ -1901,7 +1901,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
61981 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
61982
61983 if (EXT4_SB(sb)->s_mb_stats)
61984- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
61985+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
61986
61987 break;
61988 }
61989@@ -2211,7 +2211,7 @@ repeat:
61990 ac->ac_status = AC_STATUS_CONTINUE;
61991 ac->ac_flags |= EXT4_MB_HINT_FIRST;
61992 cr = 3;
61993- atomic_inc(&sbi->s_mb_lost_chunks);
61994+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
61995 goto repeat;
61996 }
61997 }
61998@@ -2717,25 +2717,25 @@ int ext4_mb_release(struct super_block *sb)
61999 if (sbi->s_mb_stats) {
62000 ext4_msg(sb, KERN_INFO,
62001 "mballoc: %u blocks %u reqs (%u success)",
62002- atomic_read(&sbi->s_bal_allocated),
62003- atomic_read(&sbi->s_bal_reqs),
62004- atomic_read(&sbi->s_bal_success));
62005+ atomic_read_unchecked(&sbi->s_bal_allocated),
62006+ atomic_read_unchecked(&sbi->s_bal_reqs),
62007+ atomic_read_unchecked(&sbi->s_bal_success));
62008 ext4_msg(sb, KERN_INFO,
62009 "mballoc: %u extents scanned, %u goal hits, "
62010 "%u 2^N hits, %u breaks, %u lost",
62011- atomic_read(&sbi->s_bal_ex_scanned),
62012- atomic_read(&sbi->s_bal_goals),
62013- atomic_read(&sbi->s_bal_2orders),
62014- atomic_read(&sbi->s_bal_breaks),
62015- atomic_read(&sbi->s_mb_lost_chunks));
62016+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
62017+ atomic_read_unchecked(&sbi->s_bal_goals),
62018+ atomic_read_unchecked(&sbi->s_bal_2orders),
62019+ atomic_read_unchecked(&sbi->s_bal_breaks),
62020+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
62021 ext4_msg(sb, KERN_INFO,
62022 "mballoc: %lu generated and it took %Lu",
62023 sbi->s_mb_buddies_generated,
62024 sbi->s_mb_generation_time);
62025 ext4_msg(sb, KERN_INFO,
62026 "mballoc: %u preallocated, %u discarded",
62027- atomic_read(&sbi->s_mb_preallocated),
62028- atomic_read(&sbi->s_mb_discarded));
62029+ atomic_read_unchecked(&sbi->s_mb_preallocated),
62030+ atomic_read_unchecked(&sbi->s_mb_discarded));
62031 }
62032
62033 free_percpu(sbi->s_locality_groups);
62034@@ -3192,16 +3192,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
62035 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
62036
62037 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
62038- atomic_inc(&sbi->s_bal_reqs);
62039- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62040+ atomic_inc_unchecked(&sbi->s_bal_reqs);
62041+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
62042 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
62043- atomic_inc(&sbi->s_bal_success);
62044- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
62045+ atomic_inc_unchecked(&sbi->s_bal_success);
62046+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
62047 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
62048 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
62049- atomic_inc(&sbi->s_bal_goals);
62050+ atomic_inc_unchecked(&sbi->s_bal_goals);
62051 if (ac->ac_found > sbi->s_mb_max_to_scan)
62052- atomic_inc(&sbi->s_bal_breaks);
62053+ atomic_inc_unchecked(&sbi->s_bal_breaks);
62054 }
62055
62056 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
62057@@ -3628,7 +3628,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
62058 trace_ext4_mb_new_inode_pa(ac, pa);
62059
62060 ext4_mb_use_inode_pa(ac, pa);
62061- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
62062+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
62063
62064 ei = EXT4_I(ac->ac_inode);
62065 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62066@@ -3688,7 +3688,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
62067 trace_ext4_mb_new_group_pa(ac, pa);
62068
62069 ext4_mb_use_group_pa(ac, pa);
62070- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62071+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
62072
62073 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
62074 lg = ac->ac_lg;
62075@@ -3777,7 +3777,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
62076 * from the bitmap and continue.
62077 */
62078 }
62079- atomic_add(free, &sbi->s_mb_discarded);
62080+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
62081
62082 return err;
62083 }
62084@@ -3795,7 +3795,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
62085 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
62086 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
62087 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
62088- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62089+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
62090 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
62091
62092 return 0;
62093diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
62094index 8313ca3..8a37d08 100644
62095--- a/fs/ext4/mmp.c
62096+++ b/fs/ext4/mmp.c
62097@@ -111,7 +111,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
62098 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
62099 const char *function, unsigned int line, const char *msg)
62100 {
62101- __ext4_warning(sb, function, line, msg);
62102+ __ext4_warning(sb, function, line, "%s", msg);
62103 __ext4_warning(sb, function, line,
62104 "MMP failure info: last update time: %llu, last update "
62105 "node: %s, last update device: %s\n",
62106diff --git a/fs/ext4/super.c b/fs/ext4/super.c
62107index b1f0ac7..77e9a05 100644
62108--- a/fs/ext4/super.c
62109+++ b/fs/ext4/super.c
62110@@ -1274,7 +1274,7 @@ static ext4_fsblk_t get_sb_block(void **data)
62111 }
62112
62113 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
62114-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62115+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
62116 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
62117
62118 #ifdef CONFIG_QUOTA
62119@@ -2454,7 +2454,7 @@ struct ext4_attr {
62120 int offset;
62121 int deprecated_val;
62122 } u;
62123-};
62124+} __do_const;
62125
62126 static int parse_strtoull(const char *buf,
62127 unsigned long long max, unsigned long long *value)
62128diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
62129index 2d1e5803..1b082d415 100644
62130--- a/fs/ext4/xattr.c
62131+++ b/fs/ext4/xattr.c
62132@@ -399,7 +399,7 @@ static int
62133 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62134 char *buffer, size_t buffer_size)
62135 {
62136- size_t rest = buffer_size;
62137+ size_t rest = buffer_size, total_size = 0;
62138
62139 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
62140 const struct xattr_handler *handler =
62141@@ -416,9 +416,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
62142 buffer += size;
62143 }
62144 rest -= size;
62145+ total_size += size;
62146 }
62147 }
62148- return buffer_size - rest;
62149+ return total_size;
62150 }
62151
62152 static int
62153diff --git a/fs/fcntl.c b/fs/fcntl.c
62154index 22d1c3d..600cf7e 100644
62155--- a/fs/fcntl.c
62156+++ b/fs/fcntl.c
62157@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
62158 if (err)
62159 return err;
62160
62161+ if (gr_handle_chroot_fowner(pid, type))
62162+ return -ENOENT;
62163+ if (gr_check_protected_task_fowner(pid, type))
62164+ return -EACCES;
62165+
62166 f_modown(filp, pid, type, force);
62167 return 0;
62168 }
62169diff --git a/fs/fhandle.c b/fs/fhandle.c
62170index 999ff5c..ac037c9 100644
62171--- a/fs/fhandle.c
62172+++ b/fs/fhandle.c
62173@@ -8,6 +8,7 @@
62174 #include <linux/fs_struct.h>
62175 #include <linux/fsnotify.h>
62176 #include <linux/personality.h>
62177+#include <linux/grsecurity.h>
62178 #include <asm/uaccess.h>
62179 #include "internal.h"
62180 #include "mount.h"
62181@@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
62182 } else
62183 retval = 0;
62184 /* copy the mount id */
62185- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
62186- sizeof(*mnt_id)) ||
62187+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
62188 copy_to_user(ufh, handle,
62189 sizeof(struct file_handle) + handle_bytes))
62190 retval = -EFAULT;
62191@@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
62192 * the directory. Ideally we would like CAP_DAC_SEARCH.
62193 * But we don't have that
62194 */
62195- if (!capable(CAP_DAC_READ_SEARCH)) {
62196+ if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
62197 retval = -EPERM;
62198 goto out_err;
62199 }
62200diff --git a/fs/file.c b/fs/file.c
62201index 66923fe..2849783 100644
62202--- a/fs/file.c
62203+++ b/fs/file.c
62204@@ -16,6 +16,7 @@
62205 #include <linux/slab.h>
62206 #include <linux/vmalloc.h>
62207 #include <linux/file.h>
62208+#include <linux/security.h>
62209 #include <linux/fdtable.h>
62210 #include <linux/bitops.h>
62211 #include <linux/interrupt.h>
62212@@ -139,7 +140,7 @@ out:
62213 * Return <0 error code on error; 1 on successful completion.
62214 * The files->file_lock should be held on entry, and will be held on exit.
62215 */
62216-static int expand_fdtable(struct files_struct *files, int nr)
62217+static int expand_fdtable(struct files_struct *files, unsigned int nr)
62218 __releases(files->file_lock)
62219 __acquires(files->file_lock)
62220 {
62221@@ -184,7 +185,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
62222 * expanded and execution may have blocked.
62223 * The files->file_lock should be held on entry, and will be held on exit.
62224 */
62225-static int expand_files(struct files_struct *files, int nr)
62226+static int expand_files(struct files_struct *files, unsigned int nr)
62227 {
62228 struct fdtable *fdt;
62229
62230@@ -799,6 +800,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
62231 if (!file)
62232 return __close_fd(files, fd);
62233
62234+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
62235 if (fd >= rlimit(RLIMIT_NOFILE))
62236 return -EBADF;
62237
62238@@ -825,6 +827,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
62239 if (unlikely(oldfd == newfd))
62240 return -EINVAL;
62241
62242+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
62243 if (newfd >= rlimit(RLIMIT_NOFILE))
62244 return -EBADF;
62245
62246@@ -880,6 +883,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
62247 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
62248 {
62249 int err;
62250+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
62251 if (from >= rlimit(RLIMIT_NOFILE))
62252 return -EINVAL;
62253 err = alloc_fd(from, flags);
62254diff --git a/fs/filesystems.c b/fs/filesystems.c
62255index 5797d45..7d7d79a 100644
62256--- a/fs/filesystems.c
62257+++ b/fs/filesystems.c
62258@@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
62259 int len = dot ? dot - name : strlen(name);
62260
62261 fs = __get_fs_type(name, len);
62262+#ifdef CONFIG_GRKERNSEC_MODHARDEN
62263+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
62264+#else
62265 if (!fs && (request_module("fs-%.*s", len, name) == 0))
62266+#endif
62267 fs = __get_fs_type(name, len);
62268
62269 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
62270diff --git a/fs/fs_struct.c b/fs/fs_struct.c
62271index 7dca743..543d620 100644
62272--- a/fs/fs_struct.c
62273+++ b/fs/fs_struct.c
62274@@ -4,6 +4,7 @@
62275 #include <linux/path.h>
62276 #include <linux/slab.h>
62277 #include <linux/fs_struct.h>
62278+#include <linux/grsecurity.h>
62279 #include "internal.h"
62280
62281 /*
62282@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
62283 write_seqcount_begin(&fs->seq);
62284 old_root = fs->root;
62285 fs->root = *path;
62286+ gr_set_chroot_entries(current, path);
62287 write_seqcount_end(&fs->seq);
62288 spin_unlock(&fs->lock);
62289 if (old_root.dentry)
62290@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
62291 int hits = 0;
62292 spin_lock(&fs->lock);
62293 write_seqcount_begin(&fs->seq);
62294+ /* this root replacement is only done by pivot_root,
62295+ leave grsec's chroot tagging alone for this task
62296+ so that a pivoted root isn't treated as a chroot
62297+ */
62298 hits += replace_path(&fs->root, old_root, new_root);
62299 hits += replace_path(&fs->pwd, old_root, new_root);
62300 write_seqcount_end(&fs->seq);
62301@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
62302 task_lock(tsk);
62303 spin_lock(&fs->lock);
62304 tsk->fs = NULL;
62305- kill = !--fs->users;
62306+ gr_clear_chroot_entries(tsk);
62307+ kill = !atomic_dec_return(&fs->users);
62308 spin_unlock(&fs->lock);
62309 task_unlock(tsk);
62310 if (kill)
62311@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62312 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
62313 /* We don't need to lock fs - think why ;-) */
62314 if (fs) {
62315- fs->users = 1;
62316+ atomic_set(&fs->users, 1);
62317 fs->in_exec = 0;
62318 spin_lock_init(&fs->lock);
62319 seqcount_init(&fs->seq);
62320@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
62321 spin_lock(&old->lock);
62322 fs->root = old->root;
62323 path_get(&fs->root);
62324+ /* instead of calling gr_set_chroot_entries here,
62325+ we call it from every caller of this function
62326+ */
62327 fs->pwd = old->pwd;
62328 path_get(&fs->pwd);
62329 spin_unlock(&old->lock);
62330@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
62331
62332 task_lock(current);
62333 spin_lock(&fs->lock);
62334- kill = !--fs->users;
62335+ kill = !atomic_dec_return(&fs->users);
62336 current->fs = new_fs;
62337+ gr_set_chroot_entries(current, &new_fs->root);
62338 spin_unlock(&fs->lock);
62339 task_unlock(current);
62340
62341@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
62342
62343 int current_umask(void)
62344 {
62345- return current->fs->umask;
62346+ return current->fs->umask | gr_acl_umask();
62347 }
62348 EXPORT_SYMBOL(current_umask);
62349
62350 /* to be mentioned only in INIT_TASK */
62351 struct fs_struct init_fs = {
62352- .users = 1,
62353+ .users = ATOMIC_INIT(1),
62354 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
62355 .seq = SEQCNT_ZERO(init_fs.seq),
62356 .umask = 0022,
62357diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
62358index 89acec7..a575262 100644
62359--- a/fs/fscache/cookie.c
62360+++ b/fs/fscache/cookie.c
62361@@ -19,7 +19,7 @@
62362
62363 struct kmem_cache *fscache_cookie_jar;
62364
62365-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
62366+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
62367
62368 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
62369 static int fscache_alloc_object(struct fscache_cache *cache,
62370@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
62371 parent ? (char *) parent->def->name : "<no-parent>",
62372 def->name, netfs_data, enable);
62373
62374- fscache_stat(&fscache_n_acquires);
62375+ fscache_stat_unchecked(&fscache_n_acquires);
62376
62377 /* if there's no parent cookie, then we don't create one here either */
62378 if (!parent) {
62379- fscache_stat(&fscache_n_acquires_null);
62380+ fscache_stat_unchecked(&fscache_n_acquires_null);
62381 _leave(" [no parent]");
62382 return NULL;
62383 }
62384@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62385 /* allocate and initialise a cookie */
62386 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
62387 if (!cookie) {
62388- fscache_stat(&fscache_n_acquires_oom);
62389+ fscache_stat_unchecked(&fscache_n_acquires_oom);
62390 _leave(" [ENOMEM]");
62391 return NULL;
62392 }
62393@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
62394
62395 switch (cookie->def->type) {
62396 case FSCACHE_COOKIE_TYPE_INDEX:
62397- fscache_stat(&fscache_n_cookie_index);
62398+ fscache_stat_unchecked(&fscache_n_cookie_index);
62399 break;
62400 case FSCACHE_COOKIE_TYPE_DATAFILE:
62401- fscache_stat(&fscache_n_cookie_data);
62402+ fscache_stat_unchecked(&fscache_n_cookie_data);
62403 break;
62404 default:
62405- fscache_stat(&fscache_n_cookie_special);
62406+ fscache_stat_unchecked(&fscache_n_cookie_special);
62407 break;
62408 }
62409
62410@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62411 } else {
62412 atomic_dec(&parent->n_children);
62413 __fscache_cookie_put(cookie);
62414- fscache_stat(&fscache_n_acquires_nobufs);
62415+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
62416 _leave(" = NULL");
62417 return NULL;
62418 }
62419@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
62420 }
62421 }
62422
62423- fscache_stat(&fscache_n_acquires_ok);
62424+ fscache_stat_unchecked(&fscache_n_acquires_ok);
62425 _leave(" = %p", cookie);
62426 return cookie;
62427 }
62428@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
62429 cache = fscache_select_cache_for_object(cookie->parent);
62430 if (!cache) {
62431 up_read(&fscache_addremove_sem);
62432- fscache_stat(&fscache_n_acquires_no_cache);
62433+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
62434 _leave(" = -ENOMEDIUM [no cache]");
62435 return -ENOMEDIUM;
62436 }
62437@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
62438 object = cache->ops->alloc_object(cache, cookie);
62439 fscache_stat_d(&fscache_n_cop_alloc_object);
62440 if (IS_ERR(object)) {
62441- fscache_stat(&fscache_n_object_no_alloc);
62442+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
62443 ret = PTR_ERR(object);
62444 goto error;
62445 }
62446
62447- fscache_stat(&fscache_n_object_alloc);
62448+ fscache_stat_unchecked(&fscache_n_object_alloc);
62449
62450- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
62451+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
62452
62453 _debug("ALLOC OBJ%x: %s {%lx}",
62454 object->debug_id, cookie->def->name, object->events);
62455@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
62456
62457 _enter("{%s}", cookie->def->name);
62458
62459- fscache_stat(&fscache_n_invalidates);
62460+ fscache_stat_unchecked(&fscache_n_invalidates);
62461
62462 /* Only permit invalidation of data files. Invalidating an index will
62463 * require the caller to release all its attachments to the tree rooted
62464@@ -476,10 +476,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
62465 {
62466 struct fscache_object *object;
62467
62468- fscache_stat(&fscache_n_updates);
62469+ fscache_stat_unchecked(&fscache_n_updates);
62470
62471 if (!cookie) {
62472- fscache_stat(&fscache_n_updates_null);
62473+ fscache_stat_unchecked(&fscache_n_updates_null);
62474 _leave(" [no cookie]");
62475 return;
62476 }
62477@@ -580,12 +580,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
62478 */
62479 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
62480 {
62481- fscache_stat(&fscache_n_relinquishes);
62482+ fscache_stat_unchecked(&fscache_n_relinquishes);
62483 if (retire)
62484- fscache_stat(&fscache_n_relinquishes_retire);
62485+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
62486
62487 if (!cookie) {
62488- fscache_stat(&fscache_n_relinquishes_null);
62489+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
62490 _leave(" [no cookie]");
62491 return;
62492 }
62493@@ -686,7 +686,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
62494 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
62495 goto inconsistent;
62496
62497- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
62498+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
62499
62500 __fscache_use_cookie(cookie);
62501 if (fscache_submit_op(object, op) < 0)
62502diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
62503index 7872a62..d91b19f 100644
62504--- a/fs/fscache/internal.h
62505+++ b/fs/fscache/internal.h
62506@@ -137,8 +137,8 @@ extern void fscache_operation_gc(struct work_struct *);
62507 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
62508 extern int fscache_wait_for_operation_activation(struct fscache_object *,
62509 struct fscache_operation *,
62510- atomic_t *,
62511- atomic_t *,
62512+ atomic_unchecked_t *,
62513+ atomic_unchecked_t *,
62514 void (*)(struct fscache_operation *));
62515 extern void fscache_invalidate_writes(struct fscache_cookie *);
62516
62517@@ -157,101 +157,101 @@ extern void fscache_proc_cleanup(void);
62518 * stats.c
62519 */
62520 #ifdef CONFIG_FSCACHE_STATS
62521-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62522-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62523+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
62524+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
62525
62526-extern atomic_t fscache_n_op_pend;
62527-extern atomic_t fscache_n_op_run;
62528-extern atomic_t fscache_n_op_enqueue;
62529-extern atomic_t fscache_n_op_deferred_release;
62530-extern atomic_t fscache_n_op_release;
62531-extern atomic_t fscache_n_op_gc;
62532-extern atomic_t fscache_n_op_cancelled;
62533-extern atomic_t fscache_n_op_rejected;
62534+extern atomic_unchecked_t fscache_n_op_pend;
62535+extern atomic_unchecked_t fscache_n_op_run;
62536+extern atomic_unchecked_t fscache_n_op_enqueue;
62537+extern atomic_unchecked_t fscache_n_op_deferred_release;
62538+extern atomic_unchecked_t fscache_n_op_release;
62539+extern atomic_unchecked_t fscache_n_op_gc;
62540+extern atomic_unchecked_t fscache_n_op_cancelled;
62541+extern atomic_unchecked_t fscache_n_op_rejected;
62542
62543-extern atomic_t fscache_n_attr_changed;
62544-extern atomic_t fscache_n_attr_changed_ok;
62545-extern atomic_t fscache_n_attr_changed_nobufs;
62546-extern atomic_t fscache_n_attr_changed_nomem;
62547-extern atomic_t fscache_n_attr_changed_calls;
62548+extern atomic_unchecked_t fscache_n_attr_changed;
62549+extern atomic_unchecked_t fscache_n_attr_changed_ok;
62550+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
62551+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
62552+extern atomic_unchecked_t fscache_n_attr_changed_calls;
62553
62554-extern atomic_t fscache_n_allocs;
62555-extern atomic_t fscache_n_allocs_ok;
62556-extern atomic_t fscache_n_allocs_wait;
62557-extern atomic_t fscache_n_allocs_nobufs;
62558-extern atomic_t fscache_n_allocs_intr;
62559-extern atomic_t fscache_n_allocs_object_dead;
62560-extern atomic_t fscache_n_alloc_ops;
62561-extern atomic_t fscache_n_alloc_op_waits;
62562+extern atomic_unchecked_t fscache_n_allocs;
62563+extern atomic_unchecked_t fscache_n_allocs_ok;
62564+extern atomic_unchecked_t fscache_n_allocs_wait;
62565+extern atomic_unchecked_t fscache_n_allocs_nobufs;
62566+extern atomic_unchecked_t fscache_n_allocs_intr;
62567+extern atomic_unchecked_t fscache_n_allocs_object_dead;
62568+extern atomic_unchecked_t fscache_n_alloc_ops;
62569+extern atomic_unchecked_t fscache_n_alloc_op_waits;
62570
62571-extern atomic_t fscache_n_retrievals;
62572-extern atomic_t fscache_n_retrievals_ok;
62573-extern atomic_t fscache_n_retrievals_wait;
62574-extern atomic_t fscache_n_retrievals_nodata;
62575-extern atomic_t fscache_n_retrievals_nobufs;
62576-extern atomic_t fscache_n_retrievals_intr;
62577-extern atomic_t fscache_n_retrievals_nomem;
62578-extern atomic_t fscache_n_retrievals_object_dead;
62579-extern atomic_t fscache_n_retrieval_ops;
62580-extern atomic_t fscache_n_retrieval_op_waits;
62581+extern atomic_unchecked_t fscache_n_retrievals;
62582+extern atomic_unchecked_t fscache_n_retrievals_ok;
62583+extern atomic_unchecked_t fscache_n_retrievals_wait;
62584+extern atomic_unchecked_t fscache_n_retrievals_nodata;
62585+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
62586+extern atomic_unchecked_t fscache_n_retrievals_intr;
62587+extern atomic_unchecked_t fscache_n_retrievals_nomem;
62588+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
62589+extern atomic_unchecked_t fscache_n_retrieval_ops;
62590+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
62591
62592-extern atomic_t fscache_n_stores;
62593-extern atomic_t fscache_n_stores_ok;
62594-extern atomic_t fscache_n_stores_again;
62595-extern atomic_t fscache_n_stores_nobufs;
62596-extern atomic_t fscache_n_stores_oom;
62597-extern atomic_t fscache_n_store_ops;
62598-extern atomic_t fscache_n_store_calls;
62599-extern atomic_t fscache_n_store_pages;
62600-extern atomic_t fscache_n_store_radix_deletes;
62601-extern atomic_t fscache_n_store_pages_over_limit;
62602+extern atomic_unchecked_t fscache_n_stores;
62603+extern atomic_unchecked_t fscache_n_stores_ok;
62604+extern atomic_unchecked_t fscache_n_stores_again;
62605+extern atomic_unchecked_t fscache_n_stores_nobufs;
62606+extern atomic_unchecked_t fscache_n_stores_oom;
62607+extern atomic_unchecked_t fscache_n_store_ops;
62608+extern atomic_unchecked_t fscache_n_store_calls;
62609+extern atomic_unchecked_t fscache_n_store_pages;
62610+extern atomic_unchecked_t fscache_n_store_radix_deletes;
62611+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
62612
62613-extern atomic_t fscache_n_store_vmscan_not_storing;
62614-extern atomic_t fscache_n_store_vmscan_gone;
62615-extern atomic_t fscache_n_store_vmscan_busy;
62616-extern atomic_t fscache_n_store_vmscan_cancelled;
62617-extern atomic_t fscache_n_store_vmscan_wait;
62618+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
62619+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
62620+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
62621+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
62622+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
62623
62624-extern atomic_t fscache_n_marks;
62625-extern atomic_t fscache_n_uncaches;
62626+extern atomic_unchecked_t fscache_n_marks;
62627+extern atomic_unchecked_t fscache_n_uncaches;
62628
62629-extern atomic_t fscache_n_acquires;
62630-extern atomic_t fscache_n_acquires_null;
62631-extern atomic_t fscache_n_acquires_no_cache;
62632-extern atomic_t fscache_n_acquires_ok;
62633-extern atomic_t fscache_n_acquires_nobufs;
62634-extern atomic_t fscache_n_acquires_oom;
62635+extern atomic_unchecked_t fscache_n_acquires;
62636+extern atomic_unchecked_t fscache_n_acquires_null;
62637+extern atomic_unchecked_t fscache_n_acquires_no_cache;
62638+extern atomic_unchecked_t fscache_n_acquires_ok;
62639+extern atomic_unchecked_t fscache_n_acquires_nobufs;
62640+extern atomic_unchecked_t fscache_n_acquires_oom;
62641
62642-extern atomic_t fscache_n_invalidates;
62643-extern atomic_t fscache_n_invalidates_run;
62644+extern atomic_unchecked_t fscache_n_invalidates;
62645+extern atomic_unchecked_t fscache_n_invalidates_run;
62646
62647-extern atomic_t fscache_n_updates;
62648-extern atomic_t fscache_n_updates_null;
62649-extern atomic_t fscache_n_updates_run;
62650+extern atomic_unchecked_t fscache_n_updates;
62651+extern atomic_unchecked_t fscache_n_updates_null;
62652+extern atomic_unchecked_t fscache_n_updates_run;
62653
62654-extern atomic_t fscache_n_relinquishes;
62655-extern atomic_t fscache_n_relinquishes_null;
62656-extern atomic_t fscache_n_relinquishes_waitcrt;
62657-extern atomic_t fscache_n_relinquishes_retire;
62658+extern atomic_unchecked_t fscache_n_relinquishes;
62659+extern atomic_unchecked_t fscache_n_relinquishes_null;
62660+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
62661+extern atomic_unchecked_t fscache_n_relinquishes_retire;
62662
62663-extern atomic_t fscache_n_cookie_index;
62664-extern atomic_t fscache_n_cookie_data;
62665-extern atomic_t fscache_n_cookie_special;
62666+extern atomic_unchecked_t fscache_n_cookie_index;
62667+extern atomic_unchecked_t fscache_n_cookie_data;
62668+extern atomic_unchecked_t fscache_n_cookie_special;
62669
62670-extern atomic_t fscache_n_object_alloc;
62671-extern atomic_t fscache_n_object_no_alloc;
62672-extern atomic_t fscache_n_object_lookups;
62673-extern atomic_t fscache_n_object_lookups_negative;
62674-extern atomic_t fscache_n_object_lookups_positive;
62675-extern atomic_t fscache_n_object_lookups_timed_out;
62676-extern atomic_t fscache_n_object_created;
62677-extern atomic_t fscache_n_object_avail;
62678-extern atomic_t fscache_n_object_dead;
62679+extern atomic_unchecked_t fscache_n_object_alloc;
62680+extern atomic_unchecked_t fscache_n_object_no_alloc;
62681+extern atomic_unchecked_t fscache_n_object_lookups;
62682+extern atomic_unchecked_t fscache_n_object_lookups_negative;
62683+extern atomic_unchecked_t fscache_n_object_lookups_positive;
62684+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
62685+extern atomic_unchecked_t fscache_n_object_created;
62686+extern atomic_unchecked_t fscache_n_object_avail;
62687+extern atomic_unchecked_t fscache_n_object_dead;
62688
62689-extern atomic_t fscache_n_checkaux_none;
62690-extern atomic_t fscache_n_checkaux_okay;
62691-extern atomic_t fscache_n_checkaux_update;
62692-extern atomic_t fscache_n_checkaux_obsolete;
62693+extern atomic_unchecked_t fscache_n_checkaux_none;
62694+extern atomic_unchecked_t fscache_n_checkaux_okay;
62695+extern atomic_unchecked_t fscache_n_checkaux_update;
62696+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
62697
62698 extern atomic_t fscache_n_cop_alloc_object;
62699 extern atomic_t fscache_n_cop_lookup_object;
62700@@ -276,6 +276,11 @@ static inline void fscache_stat(atomic_t *stat)
62701 atomic_inc(stat);
62702 }
62703
62704+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
62705+{
62706+ atomic_inc_unchecked(stat);
62707+}
62708+
62709 static inline void fscache_stat_d(atomic_t *stat)
62710 {
62711 atomic_dec(stat);
62712@@ -288,6 +293,7 @@ extern const struct file_operations fscache_stats_fops;
62713
62714 #define __fscache_stat(stat) (NULL)
62715 #define fscache_stat(stat) do {} while (0)
62716+#define fscache_stat_unchecked(stat) do {} while (0)
62717 #define fscache_stat_d(stat) do {} while (0)
62718 #endif
62719
62720diff --git a/fs/fscache/object.c b/fs/fscache/object.c
62721index da032da..0076ce7 100644
62722--- a/fs/fscache/object.c
62723+++ b/fs/fscache/object.c
62724@@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62725 _debug("LOOKUP \"%s\" in \"%s\"",
62726 cookie->def->name, object->cache->tag->name);
62727
62728- fscache_stat(&fscache_n_object_lookups);
62729+ fscache_stat_unchecked(&fscache_n_object_lookups);
62730 fscache_stat(&fscache_n_cop_lookup_object);
62731 ret = object->cache->ops->lookup_object(object);
62732 fscache_stat_d(&fscache_n_cop_lookup_object);
62733@@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
62734 if (ret == -ETIMEDOUT) {
62735 /* probably stuck behind another object, so move this one to
62736 * the back of the queue */
62737- fscache_stat(&fscache_n_object_lookups_timed_out);
62738+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
62739 _leave(" [timeout]");
62740 return NO_TRANSIT;
62741 }
62742@@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
62743 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
62744
62745 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62746- fscache_stat(&fscache_n_object_lookups_negative);
62747+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
62748
62749 /* Allow write requests to begin stacking up and read requests to begin
62750 * returning ENODATA.
62751@@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
62752 /* if we were still looking up, then we must have a positive lookup
62753 * result, in which case there may be data available */
62754 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
62755- fscache_stat(&fscache_n_object_lookups_positive);
62756+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
62757
62758 /* We do (presumably) have data */
62759 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
62760@@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
62761 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
62762 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
62763 } else {
62764- fscache_stat(&fscache_n_object_created);
62765+ fscache_stat_unchecked(&fscache_n_object_created);
62766 }
62767
62768 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
62769@@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
62770 fscache_stat_d(&fscache_n_cop_lookup_complete);
62771
62772 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
62773- fscache_stat(&fscache_n_object_avail);
62774+ fscache_stat_unchecked(&fscache_n_object_avail);
62775
62776 _leave("");
62777 return transit_to(JUMPSTART_DEPS);
62778@@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
62779
62780 /* this just shifts the object release to the work processor */
62781 fscache_put_object(object);
62782- fscache_stat(&fscache_n_object_dead);
62783+ fscache_stat_unchecked(&fscache_n_object_dead);
62784
62785 _leave("");
62786 return transit_to(OBJECT_DEAD);
62787@@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62788 enum fscache_checkaux result;
62789
62790 if (!object->cookie->def->check_aux) {
62791- fscache_stat(&fscache_n_checkaux_none);
62792+ fscache_stat_unchecked(&fscache_n_checkaux_none);
62793 return FSCACHE_CHECKAUX_OKAY;
62794 }
62795
62796@@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
62797 switch (result) {
62798 /* entry okay as is */
62799 case FSCACHE_CHECKAUX_OKAY:
62800- fscache_stat(&fscache_n_checkaux_okay);
62801+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
62802 break;
62803
62804 /* entry requires update */
62805 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
62806- fscache_stat(&fscache_n_checkaux_update);
62807+ fscache_stat_unchecked(&fscache_n_checkaux_update);
62808 break;
62809
62810 /* entry requires deletion */
62811 case FSCACHE_CHECKAUX_OBSOLETE:
62812- fscache_stat(&fscache_n_checkaux_obsolete);
62813+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
62814 break;
62815
62816 default:
62817@@ -993,7 +993,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
62818 {
62819 const struct fscache_state *s;
62820
62821- fscache_stat(&fscache_n_invalidates_run);
62822+ fscache_stat_unchecked(&fscache_n_invalidates_run);
62823 fscache_stat(&fscache_n_cop_invalidate_object);
62824 s = _fscache_invalidate_object(object, event);
62825 fscache_stat_d(&fscache_n_cop_invalidate_object);
62826@@ -1008,7 +1008,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
62827 {
62828 _enter("{OBJ%x},%d", object->debug_id, event);
62829
62830- fscache_stat(&fscache_n_updates_run);
62831+ fscache_stat_unchecked(&fscache_n_updates_run);
62832 fscache_stat(&fscache_n_cop_update_object);
62833 object->cache->ops->update_object(object);
62834 fscache_stat_d(&fscache_n_cop_update_object);
62835diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
62836index e7b87a0..a85d47a 100644
62837--- a/fs/fscache/operation.c
62838+++ b/fs/fscache/operation.c
62839@@ -17,7 +17,7 @@
62840 #include <linux/slab.h>
62841 #include "internal.h"
62842
62843-atomic_t fscache_op_debug_id;
62844+atomic_unchecked_t fscache_op_debug_id;
62845 EXPORT_SYMBOL(fscache_op_debug_id);
62846
62847 /**
62848@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
62849 ASSERTCMP(atomic_read(&op->usage), >, 0);
62850 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
62851
62852- fscache_stat(&fscache_n_op_enqueue);
62853+ fscache_stat_unchecked(&fscache_n_op_enqueue);
62854 switch (op->flags & FSCACHE_OP_TYPE) {
62855 case FSCACHE_OP_ASYNC:
62856 _debug("queue async");
62857@@ -72,7 +72,7 @@ static void fscache_run_op(struct fscache_object *object,
62858 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
62859 if (op->processor)
62860 fscache_enqueue_operation(op);
62861- fscache_stat(&fscache_n_op_run);
62862+ fscache_stat_unchecked(&fscache_n_op_run);
62863 }
62864
62865 /*
62866@@ -104,11 +104,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62867 if (object->n_in_progress > 0) {
62868 atomic_inc(&op->usage);
62869 list_add_tail(&op->pend_link, &object->pending_ops);
62870- fscache_stat(&fscache_n_op_pend);
62871+ fscache_stat_unchecked(&fscache_n_op_pend);
62872 } else if (!list_empty(&object->pending_ops)) {
62873 atomic_inc(&op->usage);
62874 list_add_tail(&op->pend_link, &object->pending_ops);
62875- fscache_stat(&fscache_n_op_pend);
62876+ fscache_stat_unchecked(&fscache_n_op_pend);
62877 fscache_start_operations(object);
62878 } else {
62879 ASSERTCMP(object->n_in_progress, ==, 0);
62880@@ -124,7 +124,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
62881 object->n_exclusive++; /* reads and writes must wait */
62882 atomic_inc(&op->usage);
62883 list_add_tail(&op->pend_link, &object->pending_ops);
62884- fscache_stat(&fscache_n_op_pend);
62885+ fscache_stat_unchecked(&fscache_n_op_pend);
62886 ret = 0;
62887 } else {
62888 /* If we're in any other state, there must have been an I/O
62889@@ -211,11 +211,11 @@ int fscache_submit_op(struct fscache_object *object,
62890 if (object->n_exclusive > 0) {
62891 atomic_inc(&op->usage);
62892 list_add_tail(&op->pend_link, &object->pending_ops);
62893- fscache_stat(&fscache_n_op_pend);
62894+ fscache_stat_unchecked(&fscache_n_op_pend);
62895 } else if (!list_empty(&object->pending_ops)) {
62896 atomic_inc(&op->usage);
62897 list_add_tail(&op->pend_link, &object->pending_ops);
62898- fscache_stat(&fscache_n_op_pend);
62899+ fscache_stat_unchecked(&fscache_n_op_pend);
62900 fscache_start_operations(object);
62901 } else {
62902 ASSERTCMP(object->n_exclusive, ==, 0);
62903@@ -227,10 +227,10 @@ int fscache_submit_op(struct fscache_object *object,
62904 object->n_ops++;
62905 atomic_inc(&op->usage);
62906 list_add_tail(&op->pend_link, &object->pending_ops);
62907- fscache_stat(&fscache_n_op_pend);
62908+ fscache_stat_unchecked(&fscache_n_op_pend);
62909 ret = 0;
62910 } else if (fscache_object_is_dying(object)) {
62911- fscache_stat(&fscache_n_op_rejected);
62912+ fscache_stat_unchecked(&fscache_n_op_rejected);
62913 op->state = FSCACHE_OP_ST_CANCELLED;
62914 ret = -ENOBUFS;
62915 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
62916@@ -309,7 +309,7 @@ int fscache_cancel_op(struct fscache_operation *op,
62917 ret = -EBUSY;
62918 if (op->state == FSCACHE_OP_ST_PENDING) {
62919 ASSERT(!list_empty(&op->pend_link));
62920- fscache_stat(&fscache_n_op_cancelled);
62921+ fscache_stat_unchecked(&fscache_n_op_cancelled);
62922 list_del_init(&op->pend_link);
62923 if (do_cancel)
62924 do_cancel(op);
62925@@ -341,7 +341,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
62926 while (!list_empty(&object->pending_ops)) {
62927 op = list_entry(object->pending_ops.next,
62928 struct fscache_operation, pend_link);
62929- fscache_stat(&fscache_n_op_cancelled);
62930+ fscache_stat_unchecked(&fscache_n_op_cancelled);
62931 list_del_init(&op->pend_link);
62932
62933 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
62934@@ -413,7 +413,7 @@ void fscache_put_operation(struct fscache_operation *op)
62935 op->state, ==, FSCACHE_OP_ST_CANCELLED);
62936 op->state = FSCACHE_OP_ST_DEAD;
62937
62938- fscache_stat(&fscache_n_op_release);
62939+ fscache_stat_unchecked(&fscache_n_op_release);
62940
62941 if (op->release) {
62942 op->release(op);
62943@@ -432,7 +432,7 @@ void fscache_put_operation(struct fscache_operation *op)
62944 * lock, and defer it otherwise */
62945 if (!spin_trylock(&object->lock)) {
62946 _debug("defer put");
62947- fscache_stat(&fscache_n_op_deferred_release);
62948+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
62949
62950 cache = object->cache;
62951 spin_lock(&cache->op_gc_list_lock);
62952@@ -485,7 +485,7 @@ void fscache_operation_gc(struct work_struct *work)
62953
62954 _debug("GC DEFERRED REL OBJ%x OP%x",
62955 object->debug_id, op->debug_id);
62956- fscache_stat(&fscache_n_op_gc);
62957+ fscache_stat_unchecked(&fscache_n_op_gc);
62958
62959 ASSERTCMP(atomic_read(&op->usage), ==, 0);
62960 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
62961diff --git a/fs/fscache/page.c b/fs/fscache/page.c
62962index de33b3f..8be4d29 100644
62963--- a/fs/fscache/page.c
62964+++ b/fs/fscache/page.c
62965@@ -74,7 +74,7 @@ try_again:
62966 val = radix_tree_lookup(&cookie->stores, page->index);
62967 if (!val) {
62968 rcu_read_unlock();
62969- fscache_stat(&fscache_n_store_vmscan_not_storing);
62970+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
62971 __fscache_uncache_page(cookie, page);
62972 return true;
62973 }
62974@@ -104,11 +104,11 @@ try_again:
62975 spin_unlock(&cookie->stores_lock);
62976
62977 if (xpage) {
62978- fscache_stat(&fscache_n_store_vmscan_cancelled);
62979- fscache_stat(&fscache_n_store_radix_deletes);
62980+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
62981+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
62982 ASSERTCMP(xpage, ==, page);
62983 } else {
62984- fscache_stat(&fscache_n_store_vmscan_gone);
62985+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
62986 }
62987
62988 wake_up_bit(&cookie->flags, 0);
62989@@ -123,11 +123,11 @@ page_busy:
62990 * sleeping on memory allocation, so we may need to impose a timeout
62991 * too. */
62992 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
62993- fscache_stat(&fscache_n_store_vmscan_busy);
62994+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
62995 return false;
62996 }
62997
62998- fscache_stat(&fscache_n_store_vmscan_wait);
62999+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
63000 if (!release_page_wait_timeout(cookie, page))
63001 _debug("fscache writeout timeout page: %p{%lx}",
63002 page, page->index);
63003@@ -156,7 +156,7 @@ static void fscache_end_page_write(struct fscache_object *object,
63004 FSCACHE_COOKIE_STORING_TAG);
63005 if (!radix_tree_tag_get(&cookie->stores, page->index,
63006 FSCACHE_COOKIE_PENDING_TAG)) {
63007- fscache_stat(&fscache_n_store_radix_deletes);
63008+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
63009 xpage = radix_tree_delete(&cookie->stores, page->index);
63010 }
63011 spin_unlock(&cookie->stores_lock);
63012@@ -177,7 +177,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
63013
63014 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
63015
63016- fscache_stat(&fscache_n_attr_changed_calls);
63017+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
63018
63019 if (fscache_object_is_active(object)) {
63020 fscache_stat(&fscache_n_cop_attr_changed);
63021@@ -204,11 +204,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63022
63023 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63024
63025- fscache_stat(&fscache_n_attr_changed);
63026+ fscache_stat_unchecked(&fscache_n_attr_changed);
63027
63028 op = kzalloc(sizeof(*op), GFP_KERNEL);
63029 if (!op) {
63030- fscache_stat(&fscache_n_attr_changed_nomem);
63031+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
63032 _leave(" = -ENOMEM");
63033 return -ENOMEM;
63034 }
63035@@ -230,7 +230,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
63036 if (fscache_submit_exclusive_op(object, op) < 0)
63037 goto nobufs_dec;
63038 spin_unlock(&cookie->lock);
63039- fscache_stat(&fscache_n_attr_changed_ok);
63040+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
63041 fscache_put_operation(op);
63042 _leave(" = 0");
63043 return 0;
63044@@ -242,7 +242,7 @@ nobufs:
63045 kfree(op);
63046 if (wake_cookie)
63047 __fscache_wake_unused_cookie(cookie);
63048- fscache_stat(&fscache_n_attr_changed_nobufs);
63049+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
63050 _leave(" = %d", -ENOBUFS);
63051 return -ENOBUFS;
63052 }
63053@@ -281,7 +281,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
63054 /* allocate a retrieval operation and attempt to submit it */
63055 op = kzalloc(sizeof(*op), GFP_NOIO);
63056 if (!op) {
63057- fscache_stat(&fscache_n_retrievals_nomem);
63058+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63059 return NULL;
63060 }
63061
63062@@ -311,12 +311,12 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
63063 return 0;
63064 }
63065
63066- fscache_stat(&fscache_n_retrievals_wait);
63067+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
63068
63069 jif = jiffies;
63070 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
63071 TASK_INTERRUPTIBLE) != 0) {
63072- fscache_stat(&fscache_n_retrievals_intr);
63073+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
63074 _leave(" = -ERESTARTSYS");
63075 return -ERESTARTSYS;
63076 }
63077@@ -345,8 +345,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
63078 */
63079 int fscache_wait_for_operation_activation(struct fscache_object *object,
63080 struct fscache_operation *op,
63081- atomic_t *stat_op_waits,
63082- atomic_t *stat_object_dead,
63083+ atomic_unchecked_t *stat_op_waits,
63084+ atomic_unchecked_t *stat_object_dead,
63085 void (*do_cancel)(struct fscache_operation *))
63086 {
63087 int ret;
63088@@ -356,7 +356,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63089
63090 _debug(">>> WT");
63091 if (stat_op_waits)
63092- fscache_stat(stat_op_waits);
63093+ fscache_stat_unchecked(stat_op_waits);
63094 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
63095 TASK_INTERRUPTIBLE) != 0) {
63096 ret = fscache_cancel_op(op, do_cancel);
63097@@ -373,7 +373,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
63098 check_if_dead:
63099 if (op->state == FSCACHE_OP_ST_CANCELLED) {
63100 if (stat_object_dead)
63101- fscache_stat(stat_object_dead);
63102+ fscache_stat_unchecked(stat_object_dead);
63103 _leave(" = -ENOBUFS [cancelled]");
63104 return -ENOBUFS;
63105 }
63106@@ -381,7 +381,7 @@ check_if_dead:
63107 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
63108 fscache_cancel_op(op, do_cancel);
63109 if (stat_object_dead)
63110- fscache_stat(stat_object_dead);
63111+ fscache_stat_unchecked(stat_object_dead);
63112 return -ENOBUFS;
63113 }
63114 return 0;
63115@@ -409,7 +409,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63116
63117 _enter("%p,%p,,,", cookie, page);
63118
63119- fscache_stat(&fscache_n_retrievals);
63120+ fscache_stat_unchecked(&fscache_n_retrievals);
63121
63122 if (hlist_empty(&cookie->backing_objects))
63123 goto nobufs;
63124@@ -451,7 +451,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63125 goto nobufs_unlock_dec;
63126 spin_unlock(&cookie->lock);
63127
63128- fscache_stat(&fscache_n_retrieval_ops);
63129+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
63130
63131 /* pin the netfs read context in case we need to do the actual netfs
63132 * read because we've encountered a cache read failure */
63133@@ -482,15 +482,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
63134
63135 error:
63136 if (ret == -ENOMEM)
63137- fscache_stat(&fscache_n_retrievals_nomem);
63138+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63139 else if (ret == -ERESTARTSYS)
63140- fscache_stat(&fscache_n_retrievals_intr);
63141+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
63142 else if (ret == -ENODATA)
63143- fscache_stat(&fscache_n_retrievals_nodata);
63144+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63145 else if (ret < 0)
63146- fscache_stat(&fscache_n_retrievals_nobufs);
63147+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63148 else
63149- fscache_stat(&fscache_n_retrievals_ok);
63150+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
63151
63152 fscache_put_retrieval(op);
63153 _leave(" = %d", ret);
63154@@ -505,7 +505,7 @@ nobufs_unlock:
63155 __fscache_wake_unused_cookie(cookie);
63156 kfree(op);
63157 nobufs:
63158- fscache_stat(&fscache_n_retrievals_nobufs);
63159+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63160 _leave(" = -ENOBUFS");
63161 return -ENOBUFS;
63162 }
63163@@ -544,7 +544,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63164
63165 _enter("%p,,%d,,,", cookie, *nr_pages);
63166
63167- fscache_stat(&fscache_n_retrievals);
63168+ fscache_stat_unchecked(&fscache_n_retrievals);
63169
63170 if (hlist_empty(&cookie->backing_objects))
63171 goto nobufs;
63172@@ -582,7 +582,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63173 goto nobufs_unlock_dec;
63174 spin_unlock(&cookie->lock);
63175
63176- fscache_stat(&fscache_n_retrieval_ops);
63177+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
63178
63179 /* pin the netfs read context in case we need to do the actual netfs
63180 * read because we've encountered a cache read failure */
63181@@ -613,15 +613,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
63182
63183 error:
63184 if (ret == -ENOMEM)
63185- fscache_stat(&fscache_n_retrievals_nomem);
63186+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
63187 else if (ret == -ERESTARTSYS)
63188- fscache_stat(&fscache_n_retrievals_intr);
63189+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
63190 else if (ret == -ENODATA)
63191- fscache_stat(&fscache_n_retrievals_nodata);
63192+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
63193 else if (ret < 0)
63194- fscache_stat(&fscache_n_retrievals_nobufs);
63195+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63196 else
63197- fscache_stat(&fscache_n_retrievals_ok);
63198+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
63199
63200 fscache_put_retrieval(op);
63201 _leave(" = %d", ret);
63202@@ -636,7 +636,7 @@ nobufs_unlock:
63203 if (wake_cookie)
63204 __fscache_wake_unused_cookie(cookie);
63205 nobufs:
63206- fscache_stat(&fscache_n_retrievals_nobufs);
63207+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
63208 _leave(" = -ENOBUFS");
63209 return -ENOBUFS;
63210 }
63211@@ -661,7 +661,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63212
63213 _enter("%p,%p,,,", cookie, page);
63214
63215- fscache_stat(&fscache_n_allocs);
63216+ fscache_stat_unchecked(&fscache_n_allocs);
63217
63218 if (hlist_empty(&cookie->backing_objects))
63219 goto nobufs;
63220@@ -695,7 +695,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63221 goto nobufs_unlock_dec;
63222 spin_unlock(&cookie->lock);
63223
63224- fscache_stat(&fscache_n_alloc_ops);
63225+ fscache_stat_unchecked(&fscache_n_alloc_ops);
63226
63227 ret = fscache_wait_for_operation_activation(
63228 object, &op->op,
63229@@ -712,11 +712,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
63230
63231 error:
63232 if (ret == -ERESTARTSYS)
63233- fscache_stat(&fscache_n_allocs_intr);
63234+ fscache_stat_unchecked(&fscache_n_allocs_intr);
63235 else if (ret < 0)
63236- fscache_stat(&fscache_n_allocs_nobufs);
63237+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63238 else
63239- fscache_stat(&fscache_n_allocs_ok);
63240+ fscache_stat_unchecked(&fscache_n_allocs_ok);
63241
63242 fscache_put_retrieval(op);
63243 _leave(" = %d", ret);
63244@@ -730,7 +730,7 @@ nobufs_unlock:
63245 if (wake_cookie)
63246 __fscache_wake_unused_cookie(cookie);
63247 nobufs:
63248- fscache_stat(&fscache_n_allocs_nobufs);
63249+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
63250 _leave(" = -ENOBUFS");
63251 return -ENOBUFS;
63252 }
63253@@ -806,7 +806,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63254
63255 spin_lock(&cookie->stores_lock);
63256
63257- fscache_stat(&fscache_n_store_calls);
63258+ fscache_stat_unchecked(&fscache_n_store_calls);
63259
63260 /* find a page to store */
63261 page = NULL;
63262@@ -817,7 +817,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63263 page = results[0];
63264 _debug("gang %d [%lx]", n, page->index);
63265 if (page->index > op->store_limit) {
63266- fscache_stat(&fscache_n_store_pages_over_limit);
63267+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
63268 goto superseded;
63269 }
63270
63271@@ -829,7 +829,7 @@ static void fscache_write_op(struct fscache_operation *_op)
63272 spin_unlock(&cookie->stores_lock);
63273 spin_unlock(&object->lock);
63274
63275- fscache_stat(&fscache_n_store_pages);
63276+ fscache_stat_unchecked(&fscache_n_store_pages);
63277 fscache_stat(&fscache_n_cop_write_page);
63278 ret = object->cache->ops->write_page(op, page);
63279 fscache_stat_d(&fscache_n_cop_write_page);
63280@@ -933,7 +933,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63281 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63282 ASSERT(PageFsCache(page));
63283
63284- fscache_stat(&fscache_n_stores);
63285+ fscache_stat_unchecked(&fscache_n_stores);
63286
63287 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
63288 _leave(" = -ENOBUFS [invalidating]");
63289@@ -992,7 +992,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63290 spin_unlock(&cookie->stores_lock);
63291 spin_unlock(&object->lock);
63292
63293- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
63294+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
63295 op->store_limit = object->store_limit;
63296
63297 __fscache_use_cookie(cookie);
63298@@ -1001,8 +1001,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63299
63300 spin_unlock(&cookie->lock);
63301 radix_tree_preload_end();
63302- fscache_stat(&fscache_n_store_ops);
63303- fscache_stat(&fscache_n_stores_ok);
63304+ fscache_stat_unchecked(&fscache_n_store_ops);
63305+ fscache_stat_unchecked(&fscache_n_stores_ok);
63306
63307 /* the work queue now carries its own ref on the object */
63308 fscache_put_operation(&op->op);
63309@@ -1010,14 +1010,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
63310 return 0;
63311
63312 already_queued:
63313- fscache_stat(&fscache_n_stores_again);
63314+ fscache_stat_unchecked(&fscache_n_stores_again);
63315 already_pending:
63316 spin_unlock(&cookie->stores_lock);
63317 spin_unlock(&object->lock);
63318 spin_unlock(&cookie->lock);
63319 radix_tree_preload_end();
63320 kfree(op);
63321- fscache_stat(&fscache_n_stores_ok);
63322+ fscache_stat_unchecked(&fscache_n_stores_ok);
63323 _leave(" = 0");
63324 return 0;
63325
63326@@ -1039,14 +1039,14 @@ nobufs:
63327 kfree(op);
63328 if (wake_cookie)
63329 __fscache_wake_unused_cookie(cookie);
63330- fscache_stat(&fscache_n_stores_nobufs);
63331+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
63332 _leave(" = -ENOBUFS");
63333 return -ENOBUFS;
63334
63335 nomem_free:
63336 kfree(op);
63337 nomem:
63338- fscache_stat(&fscache_n_stores_oom);
63339+ fscache_stat_unchecked(&fscache_n_stores_oom);
63340 _leave(" = -ENOMEM");
63341 return -ENOMEM;
63342 }
63343@@ -1064,7 +1064,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
63344 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
63345 ASSERTCMP(page, !=, NULL);
63346
63347- fscache_stat(&fscache_n_uncaches);
63348+ fscache_stat_unchecked(&fscache_n_uncaches);
63349
63350 /* cache withdrawal may beat us to it */
63351 if (!PageFsCache(page))
63352@@ -1115,7 +1115,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
63353 struct fscache_cookie *cookie = op->op.object->cookie;
63354
63355 #ifdef CONFIG_FSCACHE_STATS
63356- atomic_inc(&fscache_n_marks);
63357+ atomic_inc_unchecked(&fscache_n_marks);
63358 #endif
63359
63360 _debug("- mark %p{%lx}", page, page->index);
63361diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
63362index 40d13c7..ddf52b9 100644
63363--- a/fs/fscache/stats.c
63364+++ b/fs/fscache/stats.c
63365@@ -18,99 +18,99 @@
63366 /*
63367 * operation counters
63368 */
63369-atomic_t fscache_n_op_pend;
63370-atomic_t fscache_n_op_run;
63371-atomic_t fscache_n_op_enqueue;
63372-atomic_t fscache_n_op_requeue;
63373-atomic_t fscache_n_op_deferred_release;
63374-atomic_t fscache_n_op_release;
63375-atomic_t fscache_n_op_gc;
63376-atomic_t fscache_n_op_cancelled;
63377-atomic_t fscache_n_op_rejected;
63378+atomic_unchecked_t fscache_n_op_pend;
63379+atomic_unchecked_t fscache_n_op_run;
63380+atomic_unchecked_t fscache_n_op_enqueue;
63381+atomic_unchecked_t fscache_n_op_requeue;
63382+atomic_unchecked_t fscache_n_op_deferred_release;
63383+atomic_unchecked_t fscache_n_op_release;
63384+atomic_unchecked_t fscache_n_op_gc;
63385+atomic_unchecked_t fscache_n_op_cancelled;
63386+atomic_unchecked_t fscache_n_op_rejected;
63387
63388-atomic_t fscache_n_attr_changed;
63389-atomic_t fscache_n_attr_changed_ok;
63390-atomic_t fscache_n_attr_changed_nobufs;
63391-atomic_t fscache_n_attr_changed_nomem;
63392-atomic_t fscache_n_attr_changed_calls;
63393+atomic_unchecked_t fscache_n_attr_changed;
63394+atomic_unchecked_t fscache_n_attr_changed_ok;
63395+atomic_unchecked_t fscache_n_attr_changed_nobufs;
63396+atomic_unchecked_t fscache_n_attr_changed_nomem;
63397+atomic_unchecked_t fscache_n_attr_changed_calls;
63398
63399-atomic_t fscache_n_allocs;
63400-atomic_t fscache_n_allocs_ok;
63401-atomic_t fscache_n_allocs_wait;
63402-atomic_t fscache_n_allocs_nobufs;
63403-atomic_t fscache_n_allocs_intr;
63404-atomic_t fscache_n_allocs_object_dead;
63405-atomic_t fscache_n_alloc_ops;
63406-atomic_t fscache_n_alloc_op_waits;
63407+atomic_unchecked_t fscache_n_allocs;
63408+atomic_unchecked_t fscache_n_allocs_ok;
63409+atomic_unchecked_t fscache_n_allocs_wait;
63410+atomic_unchecked_t fscache_n_allocs_nobufs;
63411+atomic_unchecked_t fscache_n_allocs_intr;
63412+atomic_unchecked_t fscache_n_allocs_object_dead;
63413+atomic_unchecked_t fscache_n_alloc_ops;
63414+atomic_unchecked_t fscache_n_alloc_op_waits;
63415
63416-atomic_t fscache_n_retrievals;
63417-atomic_t fscache_n_retrievals_ok;
63418-atomic_t fscache_n_retrievals_wait;
63419-atomic_t fscache_n_retrievals_nodata;
63420-atomic_t fscache_n_retrievals_nobufs;
63421-atomic_t fscache_n_retrievals_intr;
63422-atomic_t fscache_n_retrievals_nomem;
63423-atomic_t fscache_n_retrievals_object_dead;
63424-atomic_t fscache_n_retrieval_ops;
63425-atomic_t fscache_n_retrieval_op_waits;
63426+atomic_unchecked_t fscache_n_retrievals;
63427+atomic_unchecked_t fscache_n_retrievals_ok;
63428+atomic_unchecked_t fscache_n_retrievals_wait;
63429+atomic_unchecked_t fscache_n_retrievals_nodata;
63430+atomic_unchecked_t fscache_n_retrievals_nobufs;
63431+atomic_unchecked_t fscache_n_retrievals_intr;
63432+atomic_unchecked_t fscache_n_retrievals_nomem;
63433+atomic_unchecked_t fscache_n_retrievals_object_dead;
63434+atomic_unchecked_t fscache_n_retrieval_ops;
63435+atomic_unchecked_t fscache_n_retrieval_op_waits;
63436
63437-atomic_t fscache_n_stores;
63438-atomic_t fscache_n_stores_ok;
63439-atomic_t fscache_n_stores_again;
63440-atomic_t fscache_n_stores_nobufs;
63441-atomic_t fscache_n_stores_oom;
63442-atomic_t fscache_n_store_ops;
63443-atomic_t fscache_n_store_calls;
63444-atomic_t fscache_n_store_pages;
63445-atomic_t fscache_n_store_radix_deletes;
63446-atomic_t fscache_n_store_pages_over_limit;
63447+atomic_unchecked_t fscache_n_stores;
63448+atomic_unchecked_t fscache_n_stores_ok;
63449+atomic_unchecked_t fscache_n_stores_again;
63450+atomic_unchecked_t fscache_n_stores_nobufs;
63451+atomic_unchecked_t fscache_n_stores_oom;
63452+atomic_unchecked_t fscache_n_store_ops;
63453+atomic_unchecked_t fscache_n_store_calls;
63454+atomic_unchecked_t fscache_n_store_pages;
63455+atomic_unchecked_t fscache_n_store_radix_deletes;
63456+atomic_unchecked_t fscache_n_store_pages_over_limit;
63457
63458-atomic_t fscache_n_store_vmscan_not_storing;
63459-atomic_t fscache_n_store_vmscan_gone;
63460-atomic_t fscache_n_store_vmscan_busy;
63461-atomic_t fscache_n_store_vmscan_cancelled;
63462-atomic_t fscache_n_store_vmscan_wait;
63463+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
63464+atomic_unchecked_t fscache_n_store_vmscan_gone;
63465+atomic_unchecked_t fscache_n_store_vmscan_busy;
63466+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
63467+atomic_unchecked_t fscache_n_store_vmscan_wait;
63468
63469-atomic_t fscache_n_marks;
63470-atomic_t fscache_n_uncaches;
63471+atomic_unchecked_t fscache_n_marks;
63472+atomic_unchecked_t fscache_n_uncaches;
63473
63474-atomic_t fscache_n_acquires;
63475-atomic_t fscache_n_acquires_null;
63476-atomic_t fscache_n_acquires_no_cache;
63477-atomic_t fscache_n_acquires_ok;
63478-atomic_t fscache_n_acquires_nobufs;
63479-atomic_t fscache_n_acquires_oom;
63480+atomic_unchecked_t fscache_n_acquires;
63481+atomic_unchecked_t fscache_n_acquires_null;
63482+atomic_unchecked_t fscache_n_acquires_no_cache;
63483+atomic_unchecked_t fscache_n_acquires_ok;
63484+atomic_unchecked_t fscache_n_acquires_nobufs;
63485+atomic_unchecked_t fscache_n_acquires_oom;
63486
63487-atomic_t fscache_n_invalidates;
63488-atomic_t fscache_n_invalidates_run;
63489+atomic_unchecked_t fscache_n_invalidates;
63490+atomic_unchecked_t fscache_n_invalidates_run;
63491
63492-atomic_t fscache_n_updates;
63493-atomic_t fscache_n_updates_null;
63494-atomic_t fscache_n_updates_run;
63495+atomic_unchecked_t fscache_n_updates;
63496+atomic_unchecked_t fscache_n_updates_null;
63497+atomic_unchecked_t fscache_n_updates_run;
63498
63499-atomic_t fscache_n_relinquishes;
63500-atomic_t fscache_n_relinquishes_null;
63501-atomic_t fscache_n_relinquishes_waitcrt;
63502-atomic_t fscache_n_relinquishes_retire;
63503+atomic_unchecked_t fscache_n_relinquishes;
63504+atomic_unchecked_t fscache_n_relinquishes_null;
63505+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
63506+atomic_unchecked_t fscache_n_relinquishes_retire;
63507
63508-atomic_t fscache_n_cookie_index;
63509-atomic_t fscache_n_cookie_data;
63510-atomic_t fscache_n_cookie_special;
63511+atomic_unchecked_t fscache_n_cookie_index;
63512+atomic_unchecked_t fscache_n_cookie_data;
63513+atomic_unchecked_t fscache_n_cookie_special;
63514
63515-atomic_t fscache_n_object_alloc;
63516-atomic_t fscache_n_object_no_alloc;
63517-atomic_t fscache_n_object_lookups;
63518-atomic_t fscache_n_object_lookups_negative;
63519-atomic_t fscache_n_object_lookups_positive;
63520-atomic_t fscache_n_object_lookups_timed_out;
63521-atomic_t fscache_n_object_created;
63522-atomic_t fscache_n_object_avail;
63523-atomic_t fscache_n_object_dead;
63524+atomic_unchecked_t fscache_n_object_alloc;
63525+atomic_unchecked_t fscache_n_object_no_alloc;
63526+atomic_unchecked_t fscache_n_object_lookups;
63527+atomic_unchecked_t fscache_n_object_lookups_negative;
63528+atomic_unchecked_t fscache_n_object_lookups_positive;
63529+atomic_unchecked_t fscache_n_object_lookups_timed_out;
63530+atomic_unchecked_t fscache_n_object_created;
63531+atomic_unchecked_t fscache_n_object_avail;
63532+atomic_unchecked_t fscache_n_object_dead;
63533
63534-atomic_t fscache_n_checkaux_none;
63535-atomic_t fscache_n_checkaux_okay;
63536-atomic_t fscache_n_checkaux_update;
63537-atomic_t fscache_n_checkaux_obsolete;
63538+atomic_unchecked_t fscache_n_checkaux_none;
63539+atomic_unchecked_t fscache_n_checkaux_okay;
63540+atomic_unchecked_t fscache_n_checkaux_update;
63541+atomic_unchecked_t fscache_n_checkaux_obsolete;
63542
63543 atomic_t fscache_n_cop_alloc_object;
63544 atomic_t fscache_n_cop_lookup_object;
63545@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
63546 seq_puts(m, "FS-Cache statistics\n");
63547
63548 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
63549- atomic_read(&fscache_n_cookie_index),
63550- atomic_read(&fscache_n_cookie_data),
63551- atomic_read(&fscache_n_cookie_special));
63552+ atomic_read_unchecked(&fscache_n_cookie_index),
63553+ atomic_read_unchecked(&fscache_n_cookie_data),
63554+ atomic_read_unchecked(&fscache_n_cookie_special));
63555
63556 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
63557- atomic_read(&fscache_n_object_alloc),
63558- atomic_read(&fscache_n_object_no_alloc),
63559- atomic_read(&fscache_n_object_avail),
63560- atomic_read(&fscache_n_object_dead));
63561+ atomic_read_unchecked(&fscache_n_object_alloc),
63562+ atomic_read_unchecked(&fscache_n_object_no_alloc),
63563+ atomic_read_unchecked(&fscache_n_object_avail),
63564+ atomic_read_unchecked(&fscache_n_object_dead));
63565 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
63566- atomic_read(&fscache_n_checkaux_none),
63567- atomic_read(&fscache_n_checkaux_okay),
63568- atomic_read(&fscache_n_checkaux_update),
63569- atomic_read(&fscache_n_checkaux_obsolete));
63570+ atomic_read_unchecked(&fscache_n_checkaux_none),
63571+ atomic_read_unchecked(&fscache_n_checkaux_okay),
63572+ atomic_read_unchecked(&fscache_n_checkaux_update),
63573+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
63574
63575 seq_printf(m, "Pages : mrk=%u unc=%u\n",
63576- atomic_read(&fscache_n_marks),
63577- atomic_read(&fscache_n_uncaches));
63578+ atomic_read_unchecked(&fscache_n_marks),
63579+ atomic_read_unchecked(&fscache_n_uncaches));
63580
63581 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
63582 " oom=%u\n",
63583- atomic_read(&fscache_n_acquires),
63584- atomic_read(&fscache_n_acquires_null),
63585- atomic_read(&fscache_n_acquires_no_cache),
63586- atomic_read(&fscache_n_acquires_ok),
63587- atomic_read(&fscache_n_acquires_nobufs),
63588- atomic_read(&fscache_n_acquires_oom));
63589+ atomic_read_unchecked(&fscache_n_acquires),
63590+ atomic_read_unchecked(&fscache_n_acquires_null),
63591+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
63592+ atomic_read_unchecked(&fscache_n_acquires_ok),
63593+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
63594+ atomic_read_unchecked(&fscache_n_acquires_oom));
63595
63596 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
63597- atomic_read(&fscache_n_object_lookups),
63598- atomic_read(&fscache_n_object_lookups_negative),
63599- atomic_read(&fscache_n_object_lookups_positive),
63600- atomic_read(&fscache_n_object_created),
63601- atomic_read(&fscache_n_object_lookups_timed_out));
63602+ atomic_read_unchecked(&fscache_n_object_lookups),
63603+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
63604+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
63605+ atomic_read_unchecked(&fscache_n_object_created),
63606+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
63607
63608 seq_printf(m, "Invals : n=%u run=%u\n",
63609- atomic_read(&fscache_n_invalidates),
63610- atomic_read(&fscache_n_invalidates_run));
63611+ atomic_read_unchecked(&fscache_n_invalidates),
63612+ atomic_read_unchecked(&fscache_n_invalidates_run));
63613
63614 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
63615- atomic_read(&fscache_n_updates),
63616- atomic_read(&fscache_n_updates_null),
63617- atomic_read(&fscache_n_updates_run));
63618+ atomic_read_unchecked(&fscache_n_updates),
63619+ atomic_read_unchecked(&fscache_n_updates_null),
63620+ atomic_read_unchecked(&fscache_n_updates_run));
63621
63622 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
63623- atomic_read(&fscache_n_relinquishes),
63624- atomic_read(&fscache_n_relinquishes_null),
63625- atomic_read(&fscache_n_relinquishes_waitcrt),
63626- atomic_read(&fscache_n_relinquishes_retire));
63627+ atomic_read_unchecked(&fscache_n_relinquishes),
63628+ atomic_read_unchecked(&fscache_n_relinquishes_null),
63629+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
63630+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
63631
63632 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
63633- atomic_read(&fscache_n_attr_changed),
63634- atomic_read(&fscache_n_attr_changed_ok),
63635- atomic_read(&fscache_n_attr_changed_nobufs),
63636- atomic_read(&fscache_n_attr_changed_nomem),
63637- atomic_read(&fscache_n_attr_changed_calls));
63638+ atomic_read_unchecked(&fscache_n_attr_changed),
63639+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
63640+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
63641+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
63642+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
63643
63644 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
63645- atomic_read(&fscache_n_allocs),
63646- atomic_read(&fscache_n_allocs_ok),
63647- atomic_read(&fscache_n_allocs_wait),
63648- atomic_read(&fscache_n_allocs_nobufs),
63649- atomic_read(&fscache_n_allocs_intr));
63650+ atomic_read_unchecked(&fscache_n_allocs),
63651+ atomic_read_unchecked(&fscache_n_allocs_ok),
63652+ atomic_read_unchecked(&fscache_n_allocs_wait),
63653+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
63654+ atomic_read_unchecked(&fscache_n_allocs_intr));
63655 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
63656- atomic_read(&fscache_n_alloc_ops),
63657- atomic_read(&fscache_n_alloc_op_waits),
63658- atomic_read(&fscache_n_allocs_object_dead));
63659+ atomic_read_unchecked(&fscache_n_alloc_ops),
63660+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
63661+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
63662
63663 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
63664 " int=%u oom=%u\n",
63665- atomic_read(&fscache_n_retrievals),
63666- atomic_read(&fscache_n_retrievals_ok),
63667- atomic_read(&fscache_n_retrievals_wait),
63668- atomic_read(&fscache_n_retrievals_nodata),
63669- atomic_read(&fscache_n_retrievals_nobufs),
63670- atomic_read(&fscache_n_retrievals_intr),
63671- atomic_read(&fscache_n_retrievals_nomem));
63672+ atomic_read_unchecked(&fscache_n_retrievals),
63673+ atomic_read_unchecked(&fscache_n_retrievals_ok),
63674+ atomic_read_unchecked(&fscache_n_retrievals_wait),
63675+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
63676+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
63677+ atomic_read_unchecked(&fscache_n_retrievals_intr),
63678+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
63679 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
63680- atomic_read(&fscache_n_retrieval_ops),
63681- atomic_read(&fscache_n_retrieval_op_waits),
63682- atomic_read(&fscache_n_retrievals_object_dead));
63683+ atomic_read_unchecked(&fscache_n_retrieval_ops),
63684+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
63685+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
63686
63687 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
63688- atomic_read(&fscache_n_stores),
63689- atomic_read(&fscache_n_stores_ok),
63690- atomic_read(&fscache_n_stores_again),
63691- atomic_read(&fscache_n_stores_nobufs),
63692- atomic_read(&fscache_n_stores_oom));
63693+ atomic_read_unchecked(&fscache_n_stores),
63694+ atomic_read_unchecked(&fscache_n_stores_ok),
63695+ atomic_read_unchecked(&fscache_n_stores_again),
63696+ atomic_read_unchecked(&fscache_n_stores_nobufs),
63697+ atomic_read_unchecked(&fscache_n_stores_oom));
63698 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
63699- atomic_read(&fscache_n_store_ops),
63700- atomic_read(&fscache_n_store_calls),
63701- atomic_read(&fscache_n_store_pages),
63702- atomic_read(&fscache_n_store_radix_deletes),
63703- atomic_read(&fscache_n_store_pages_over_limit));
63704+ atomic_read_unchecked(&fscache_n_store_ops),
63705+ atomic_read_unchecked(&fscache_n_store_calls),
63706+ atomic_read_unchecked(&fscache_n_store_pages),
63707+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
63708+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
63709
63710 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
63711- atomic_read(&fscache_n_store_vmscan_not_storing),
63712- atomic_read(&fscache_n_store_vmscan_gone),
63713- atomic_read(&fscache_n_store_vmscan_busy),
63714- atomic_read(&fscache_n_store_vmscan_cancelled),
63715- atomic_read(&fscache_n_store_vmscan_wait));
63716+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
63717+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
63718+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
63719+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
63720+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
63721
63722 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
63723- atomic_read(&fscache_n_op_pend),
63724- atomic_read(&fscache_n_op_run),
63725- atomic_read(&fscache_n_op_enqueue),
63726- atomic_read(&fscache_n_op_cancelled),
63727- atomic_read(&fscache_n_op_rejected));
63728+ atomic_read_unchecked(&fscache_n_op_pend),
63729+ atomic_read_unchecked(&fscache_n_op_run),
63730+ atomic_read_unchecked(&fscache_n_op_enqueue),
63731+ atomic_read_unchecked(&fscache_n_op_cancelled),
63732+ atomic_read_unchecked(&fscache_n_op_rejected));
63733 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
63734- atomic_read(&fscache_n_op_deferred_release),
63735- atomic_read(&fscache_n_op_release),
63736- atomic_read(&fscache_n_op_gc));
63737+ atomic_read_unchecked(&fscache_n_op_deferred_release),
63738+ atomic_read_unchecked(&fscache_n_op_release),
63739+ atomic_read_unchecked(&fscache_n_op_gc));
63740
63741 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
63742 atomic_read(&fscache_n_cop_alloc_object),
63743diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
63744index 966ace8..030a03a 100644
63745--- a/fs/fuse/cuse.c
63746+++ b/fs/fuse/cuse.c
63747@@ -611,10 +611,12 @@ static int __init cuse_init(void)
63748 INIT_LIST_HEAD(&cuse_conntbl[i]);
63749
63750 /* inherit and extend fuse_dev_operations */
63751- cuse_channel_fops = fuse_dev_operations;
63752- cuse_channel_fops.owner = THIS_MODULE;
63753- cuse_channel_fops.open = cuse_channel_open;
63754- cuse_channel_fops.release = cuse_channel_release;
63755+ pax_open_kernel();
63756+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
63757+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
63758+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
63759+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
63760+ pax_close_kernel();
63761
63762 cuse_class = class_create(THIS_MODULE, "cuse");
63763 if (IS_ERR(cuse_class))
63764diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
63765index ca88731..8e9c55d 100644
63766--- a/fs/fuse/dev.c
63767+++ b/fs/fuse/dev.c
63768@@ -1318,7 +1318,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63769 ret = 0;
63770 pipe_lock(pipe);
63771
63772- if (!pipe->readers) {
63773+ if (!atomic_read(&pipe->readers)) {
63774 send_sig(SIGPIPE, current, 0);
63775 if (!ret)
63776 ret = -EPIPE;
63777@@ -1347,7 +1347,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
63778 page_nr++;
63779 ret += buf->len;
63780
63781- if (pipe->files)
63782+ if (atomic_read(&pipe->files))
63783 do_wakeup = 1;
63784 }
63785
63786diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
63787index de1d84a..fd69c0c 100644
63788--- a/fs/fuse/dir.c
63789+++ b/fs/fuse/dir.c
63790@@ -1479,7 +1479,7 @@ static char *read_link(struct dentry *dentry)
63791 return link;
63792 }
63793
63794-static void free_link(char *link)
63795+static void free_link(const char *link)
63796 {
63797 if (!IS_ERR(link))
63798 free_page((unsigned long) link);
63799diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
63800index fd62cae..3494dfa 100644
63801--- a/fs/hostfs/hostfs_kern.c
63802+++ b/fs/hostfs/hostfs_kern.c
63803@@ -908,7 +908,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
63804
63805 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
63806 {
63807- char *s = nd_get_link(nd);
63808+ const char *s = nd_get_link(nd);
63809 if (!IS_ERR(s))
63810 __putname(s);
63811 }
63812diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
63813index 1e2872b..7aea000 100644
63814--- a/fs/hugetlbfs/inode.c
63815+++ b/fs/hugetlbfs/inode.c
63816@@ -154,6 +154,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63817 struct mm_struct *mm = current->mm;
63818 struct vm_area_struct *vma;
63819 struct hstate *h = hstate_file(file);
63820+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
63821 struct vm_unmapped_area_info info;
63822
63823 if (len & ~huge_page_mask(h))
63824@@ -167,17 +168,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
63825 return addr;
63826 }
63827
63828+#ifdef CONFIG_PAX_RANDMMAP
63829+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
63830+#endif
63831+
63832 if (addr) {
63833 addr = ALIGN(addr, huge_page_size(h));
63834 vma = find_vma(mm, addr);
63835- if (TASK_SIZE - len >= addr &&
63836- (!vma || addr + len <= vma->vm_start))
63837+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
63838 return addr;
63839 }
63840
63841 info.flags = 0;
63842 info.length = len;
63843 info.low_limit = TASK_UNMAPPED_BASE;
63844+
63845+#ifdef CONFIG_PAX_RANDMMAP
63846+ if (mm->pax_flags & MF_PAX_RANDMMAP)
63847+ info.low_limit += mm->delta_mmap;
63848+#endif
63849+
63850 info.high_limit = TASK_SIZE;
63851 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
63852 info.align_offset = 0;
63853@@ -919,7 +929,7 @@ static struct file_system_type hugetlbfs_fs_type = {
63854 };
63855 MODULE_ALIAS_FS("hugetlbfs");
63856
63857-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63858+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
63859
63860 static int can_do_hugetlb_shm(void)
63861 {
63862diff --git a/fs/inode.c b/fs/inode.c
63863index 26753ba..d19eb34 100644
63864--- a/fs/inode.c
63865+++ b/fs/inode.c
63866@@ -840,16 +840,20 @@ unsigned int get_next_ino(void)
63867 unsigned int *p = &get_cpu_var(last_ino);
63868 unsigned int res = *p;
63869
63870+start:
63871+
63872 #ifdef CONFIG_SMP
63873 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
63874- static atomic_t shared_last_ino;
63875- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
63876+ static atomic_unchecked_t shared_last_ino;
63877+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
63878
63879 res = next - LAST_INO_BATCH;
63880 }
63881 #endif
63882
63883- *p = ++res;
63884+ if (unlikely(!++res))
63885+ goto start; /* never zero */
63886+ *p = res;
63887 put_cpu_var(last_ino);
63888 return res;
63889 }
63890diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
63891index 4a6cf28..d3a29d3 100644
63892--- a/fs/jffs2/erase.c
63893+++ b/fs/jffs2/erase.c
63894@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
63895 struct jffs2_unknown_node marker = {
63896 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
63897 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63898- .totlen = cpu_to_je32(c->cleanmarker_size)
63899+ .totlen = cpu_to_je32(c->cleanmarker_size),
63900+ .hdr_crc = cpu_to_je32(0)
63901 };
63902
63903 jffs2_prealloc_raw_node_refs(c, jeb, 1);
63904diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
63905index 09ed551..45684f8 100644
63906--- a/fs/jffs2/wbuf.c
63907+++ b/fs/jffs2/wbuf.c
63908@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
63909 {
63910 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
63911 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
63912- .totlen = constant_cpu_to_je32(8)
63913+ .totlen = constant_cpu_to_je32(8),
63914+ .hdr_crc = constant_cpu_to_je32(0)
63915 };
63916
63917 /*
63918diff --git a/fs/jfs/super.c b/fs/jfs/super.c
63919index adf8cb0..bb935fa 100644
63920--- a/fs/jfs/super.c
63921+++ b/fs/jfs/super.c
63922@@ -893,7 +893,7 @@ static int __init init_jfs_fs(void)
63923
63924 jfs_inode_cachep =
63925 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
63926- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
63927+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
63928 init_once);
63929 if (jfs_inode_cachep == NULL)
63930 return -ENOMEM;
63931diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
63932index a693f5b..82276a1 100644
63933--- a/fs/kernfs/dir.c
63934+++ b/fs/kernfs/dir.c
63935@@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
63936 *
63937 * Returns 31 bit hash of ns + name (so it fits in an off_t )
63938 */
63939-static unsigned int kernfs_name_hash(const char *name, const void *ns)
63940+static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
63941 {
63942 unsigned long hash = init_name_hash();
63943 unsigned int len = strlen(name);
63944diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
63945index 4429d6d..9831f52 100644
63946--- a/fs/kernfs/file.c
63947+++ b/fs/kernfs/file.c
63948@@ -34,7 +34,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
63949
63950 struct kernfs_open_node {
63951 atomic_t refcnt;
63952- atomic_t event;
63953+ atomic_unchecked_t event;
63954 wait_queue_head_t poll;
63955 struct list_head files; /* goes through kernfs_open_file.list */
63956 };
63957@@ -163,7 +163,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
63958 {
63959 struct kernfs_open_file *of = sf->private;
63960
63961- of->event = atomic_read(&of->kn->attr.open->event);
63962+ of->event = atomic_read_unchecked(&of->kn->attr.open->event);
63963
63964 return of->kn->attr.ops->seq_show(sf, v);
63965 }
63966@@ -375,12 +375,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
63967 return ret;
63968 }
63969
63970-static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
63971- void *buf, int len, int write)
63972+static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
63973+ void *buf, size_t len, int write)
63974 {
63975 struct file *file = vma->vm_file;
63976 struct kernfs_open_file *of = kernfs_of(file);
63977- int ret;
63978+ ssize_t ret;
63979
63980 if (!of->vm_ops)
63981 return -EINVAL;
63982@@ -581,7 +581,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
63983 return -ENOMEM;
63984
63985 atomic_set(&new_on->refcnt, 0);
63986- atomic_set(&new_on->event, 1);
63987+ atomic_set_unchecked(&new_on->event, 1);
63988 init_waitqueue_head(&new_on->poll);
63989 INIT_LIST_HEAD(&new_on->files);
63990 goto retry;
63991@@ -787,7 +787,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
63992
63993 kernfs_put_active(kn);
63994
63995- if (of->event != atomic_read(&on->event))
63996+ if (of->event != atomic_read_unchecked(&on->event))
63997 goto trigger;
63998
63999 return DEFAULT_POLLMASK;
64000@@ -818,7 +818,7 @@ repeat:
64001
64002 on = kn->attr.open;
64003 if (on) {
64004- atomic_inc(&on->event);
64005+ atomic_inc_unchecked(&on->event);
64006 wake_up_interruptible(&on->poll);
64007 }
64008
64009diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
64010index 8a19889..4c3069a 100644
64011--- a/fs/kernfs/symlink.c
64012+++ b/fs/kernfs/symlink.c
64013@@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
64014 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
64015 void *cookie)
64016 {
64017- char *page = nd_get_link(nd);
64018+ const char *page = nd_get_link(nd);
64019 if (!IS_ERR(page))
64020 free_page((unsigned long)page);
64021 }
64022diff --git a/fs/libfs.c b/fs/libfs.c
64023index 88e3e00..979c262 100644
64024--- a/fs/libfs.c
64025+++ b/fs/libfs.c
64026@@ -160,6 +160,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64027
64028 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
64029 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
64030+ char d_name[sizeof(next->d_iname)];
64031+ const unsigned char *name;
64032+
64033 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
64034 if (!simple_positive(next)) {
64035 spin_unlock(&next->d_lock);
64036@@ -168,7 +171,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
64037
64038 spin_unlock(&next->d_lock);
64039 spin_unlock(&dentry->d_lock);
64040- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
64041+ name = next->d_name.name;
64042+ if (name == next->d_iname) {
64043+ memcpy(d_name, name, next->d_name.len);
64044+ name = d_name;
64045+ }
64046+ if (!dir_emit(ctx, name, next->d_name.len,
64047 next->d_inode->i_ino, dt_type(next->d_inode)))
64048 return 0;
64049 spin_lock(&dentry->d_lock);
64050@@ -1027,7 +1035,7 @@ EXPORT_SYMBOL(noop_fsync);
64051 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
64052 void *cookie)
64053 {
64054- char *s = nd_get_link(nd);
64055+ const char *s = nd_get_link(nd);
64056 if (!IS_ERR(s))
64057 kfree(s);
64058 }
64059diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
64060index acd3947..1f896e2 100644
64061--- a/fs/lockd/clntproc.c
64062+++ b/fs/lockd/clntproc.c
64063@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
64064 /*
64065 * Cookie counter for NLM requests
64066 */
64067-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
64068+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
64069
64070 void nlmclnt_next_cookie(struct nlm_cookie *c)
64071 {
64072- u32 cookie = atomic_inc_return(&nlm_cookie);
64073+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
64074
64075 memcpy(c->data, &cookie, 4);
64076 c->len=4;
64077diff --git a/fs/locks.c b/fs/locks.c
64078index bb08857..f65e8bf 100644
64079--- a/fs/locks.c
64080+++ b/fs/locks.c
64081@@ -2350,7 +2350,7 @@ void locks_remove_file(struct file *filp)
64082 locks_remove_posix(filp, filp);
64083
64084 if (filp->f_op->flock) {
64085- struct file_lock fl = {
64086+ struct file_lock flock = {
64087 .fl_owner = filp,
64088 .fl_pid = current->tgid,
64089 .fl_file = filp,
64090@@ -2358,9 +2358,9 @@ void locks_remove_file(struct file *filp)
64091 .fl_type = F_UNLCK,
64092 .fl_end = OFFSET_MAX,
64093 };
64094- filp->f_op->flock(filp, F_SETLKW, &fl);
64095- if (fl.fl_ops && fl.fl_ops->fl_release_private)
64096- fl.fl_ops->fl_release_private(&fl);
64097+ filp->f_op->flock(filp, F_SETLKW, &flock);
64098+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
64099+ flock.fl_ops->fl_release_private(&flock);
64100 }
64101
64102 spin_lock(&inode->i_lock);
64103diff --git a/fs/mount.h b/fs/mount.h
64104index 6740a62..ccb472f 100644
64105--- a/fs/mount.h
64106+++ b/fs/mount.h
64107@@ -11,7 +11,7 @@ struct mnt_namespace {
64108 u64 seq; /* Sequence number to prevent loops */
64109 wait_queue_head_t poll;
64110 u64 event;
64111-};
64112+} __randomize_layout;
64113
64114 struct mnt_pcp {
64115 int mnt_count;
64116@@ -57,7 +57,7 @@ struct mount {
64117 int mnt_expiry_mark; /* true if marked for expiry */
64118 struct hlist_head mnt_pins;
64119 struct path mnt_ex_mountpoint;
64120-};
64121+} __randomize_layout;
64122
64123 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
64124
64125diff --git a/fs/namei.c b/fs/namei.c
64126index bb02687..79cba2c 100644
64127--- a/fs/namei.c
64128+++ b/fs/namei.c
64129@@ -331,17 +331,32 @@ int generic_permission(struct inode *inode, int mask)
64130 if (ret != -EACCES)
64131 return ret;
64132
64133+#ifdef CONFIG_GRKERNSEC
64134+ /* we'll block if we have to log due to a denied capability use */
64135+ if (mask & MAY_NOT_BLOCK)
64136+ return -ECHILD;
64137+#endif
64138+
64139 if (S_ISDIR(inode->i_mode)) {
64140 /* DACs are overridable for directories */
64141- if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64142- return 0;
64143 if (!(mask & MAY_WRITE))
64144- if (capable_wrt_inode_uidgid(inode,
64145- CAP_DAC_READ_SEARCH))
64146+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64147+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64148 return 0;
64149+ if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64150+ return 0;
64151 return -EACCES;
64152 }
64153 /*
64154+ * Searching includes executable on directories, else just read.
64155+ */
64156+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64157+ if (mask == MAY_READ)
64158+ if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
64159+ capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64160+ return 0;
64161+
64162+ /*
64163 * Read/write DACs are always overridable.
64164 * Executable DACs are overridable when there is
64165 * at least one exec bit set.
64166@@ -350,14 +365,6 @@ int generic_permission(struct inode *inode, int mask)
64167 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
64168 return 0;
64169
64170- /*
64171- * Searching includes executable on directories, else just read.
64172- */
64173- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
64174- if (mask == MAY_READ)
64175- if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
64176- return 0;
64177-
64178 return -EACCES;
64179 }
64180 EXPORT_SYMBOL(generic_permission);
64181@@ -823,7 +830,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64182 {
64183 struct dentry *dentry = link->dentry;
64184 int error;
64185- char *s;
64186+ const char *s;
64187
64188 BUG_ON(nd->flags & LOOKUP_RCU);
64189
64190@@ -844,6 +851,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
64191 if (error)
64192 goto out_put_nd_path;
64193
64194+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
64195+ dentry->d_inode, dentry, nd->path.mnt)) {
64196+ error = -EACCES;
64197+ goto out_put_nd_path;
64198+ }
64199+
64200 nd->last_type = LAST_BIND;
64201 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
64202 error = PTR_ERR(*p);
64203@@ -1607,6 +1620,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
64204 if (res)
64205 break;
64206 res = walk_component(nd, path, LOOKUP_FOLLOW);
64207+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
64208+ res = -EACCES;
64209 put_link(nd, &link, cookie);
64210 } while (res > 0);
64211
64212@@ -1679,7 +1694,7 @@ EXPORT_SYMBOL(full_name_hash);
64213 static inline u64 hash_name(const char *name)
64214 {
64215 unsigned long a, b, adata, bdata, mask, hash, len;
64216- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64217+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
64218
64219 hash = a = 0;
64220 len = -sizeof(unsigned long);
64221@@ -1968,6 +1983,8 @@ static int path_lookupat(int dfd, const char *name,
64222 if (err)
64223 break;
64224 err = lookup_last(nd, &path);
64225+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
64226+ err = -EACCES;
64227 put_link(nd, &link, cookie);
64228 }
64229 }
64230@@ -1975,6 +1992,13 @@ static int path_lookupat(int dfd, const char *name,
64231 if (!err)
64232 err = complete_walk(nd);
64233
64234+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
64235+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64236+ path_put(&nd->path);
64237+ err = -ENOENT;
64238+ }
64239+ }
64240+
64241 if (!err && nd->flags & LOOKUP_DIRECTORY) {
64242 if (!d_can_lookup(nd->path.dentry)) {
64243 path_put(&nd->path);
64244@@ -2002,8 +2026,15 @@ static int filename_lookup(int dfd, struct filename *name,
64245 retval = path_lookupat(dfd, name->name,
64246 flags | LOOKUP_REVAL, nd);
64247
64248- if (likely(!retval))
64249+ if (likely(!retval)) {
64250 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
64251+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
64252+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
64253+ path_put(&nd->path);
64254+ return -ENOENT;
64255+ }
64256+ }
64257+ }
64258 return retval;
64259 }
64260
64261@@ -2585,6 +2616,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
64262 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
64263 return -EPERM;
64264
64265+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
64266+ return -EPERM;
64267+ if (gr_handle_rawio(inode))
64268+ return -EPERM;
64269+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
64270+ return -EACCES;
64271+
64272 return 0;
64273 }
64274
64275@@ -2816,7 +2854,7 @@ looked_up:
64276 * cleared otherwise prior to returning.
64277 */
64278 static int lookup_open(struct nameidata *nd, struct path *path,
64279- struct file *file,
64280+ struct path *link, struct file *file,
64281 const struct open_flags *op,
64282 bool got_write, int *opened)
64283 {
64284@@ -2851,6 +2889,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64285 /* Negative dentry, just create the file */
64286 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
64287 umode_t mode = op->mode;
64288+
64289+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
64290+ error = -EACCES;
64291+ goto out_dput;
64292+ }
64293+
64294+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
64295+ error = -EACCES;
64296+ goto out_dput;
64297+ }
64298+
64299 if (!IS_POSIXACL(dir->d_inode))
64300 mode &= ~current_umask();
64301 /*
64302@@ -2872,6 +2921,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
64303 nd->flags & LOOKUP_EXCL);
64304 if (error)
64305 goto out_dput;
64306+ else
64307+ gr_handle_create(dentry, nd->path.mnt);
64308 }
64309 out_no_open:
64310 path->dentry = dentry;
64311@@ -2886,7 +2937,7 @@ out_dput:
64312 /*
64313 * Handle the last step of open()
64314 */
64315-static int do_last(struct nameidata *nd, struct path *path,
64316+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
64317 struct file *file, const struct open_flags *op,
64318 int *opened, struct filename *name)
64319 {
64320@@ -2936,6 +2987,15 @@ static int do_last(struct nameidata *nd, struct path *path,
64321 if (error)
64322 return error;
64323
64324+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
64325+ error = -ENOENT;
64326+ goto out;
64327+ }
64328+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
64329+ error = -EACCES;
64330+ goto out;
64331+ }
64332+
64333 audit_inode(name, dir, LOOKUP_PARENT);
64334 error = -EISDIR;
64335 /* trailing slashes? */
64336@@ -2955,7 +3015,7 @@ retry_lookup:
64337 */
64338 }
64339 mutex_lock(&dir->d_inode->i_mutex);
64340- error = lookup_open(nd, path, file, op, got_write, opened);
64341+ error = lookup_open(nd, path, link, file, op, got_write, opened);
64342 mutex_unlock(&dir->d_inode->i_mutex);
64343
64344 if (error <= 0) {
64345@@ -2979,11 +3039,28 @@ retry_lookup:
64346 goto finish_open_created;
64347 }
64348
64349+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
64350+ error = -ENOENT;
64351+ goto exit_dput;
64352+ }
64353+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
64354+ error = -EACCES;
64355+ goto exit_dput;
64356+ }
64357+
64358 /*
64359 * create/update audit record if it already exists.
64360 */
64361- if (d_is_positive(path->dentry))
64362+ if (d_is_positive(path->dentry)) {
64363+ /* only check if O_CREAT is specified, all other checks need to go
64364+ into may_open */
64365+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
64366+ error = -EACCES;
64367+ goto exit_dput;
64368+ }
64369+
64370 audit_inode(name, path->dentry, 0);
64371+ }
64372
64373 /*
64374 * If atomic_open() acquired write access it is dropped now due to
64375@@ -3024,6 +3101,11 @@ finish_lookup:
64376 }
64377 }
64378 BUG_ON(inode != path->dentry->d_inode);
64379+ /* if we're resolving a symlink to another symlink */
64380+ if (link && gr_handle_symlink_owner(link, inode)) {
64381+ error = -EACCES;
64382+ goto out;
64383+ }
64384 return 1;
64385 }
64386
64387@@ -3033,7 +3115,6 @@ finish_lookup:
64388 save_parent.dentry = nd->path.dentry;
64389 save_parent.mnt = mntget(path->mnt);
64390 nd->path.dentry = path->dentry;
64391-
64392 }
64393 nd->inode = inode;
64394 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
64395@@ -3043,7 +3124,18 @@ finish_open:
64396 path_put(&save_parent);
64397 return error;
64398 }
64399+
64400+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
64401+ error = -ENOENT;
64402+ goto out;
64403+ }
64404+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
64405+ error = -EACCES;
64406+ goto out;
64407+ }
64408+
64409 audit_inode(name, nd->path.dentry, 0);
64410+
64411 error = -EISDIR;
64412 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
64413 goto out;
64414@@ -3207,7 +3299,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64415 if (unlikely(error))
64416 goto out;
64417
64418- error = do_last(nd, &path, file, op, &opened, pathname);
64419+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
64420 while (unlikely(error > 0)) { /* trailing symlink */
64421 struct path link = path;
64422 void *cookie;
64423@@ -3225,7 +3317,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
64424 error = follow_link(&link, nd, &cookie);
64425 if (unlikely(error))
64426 break;
64427- error = do_last(nd, &path, file, op, &opened, pathname);
64428+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
64429 put_link(nd, &link, cookie);
64430 }
64431 out:
64432@@ -3325,9 +3417,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
64433 goto unlock;
64434
64435 error = -EEXIST;
64436- if (d_is_positive(dentry))
64437+ if (d_is_positive(dentry)) {
64438+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
64439+ error = -ENOENT;
64440 goto fail;
64441-
64442+ }
64443 /*
64444 * Special case - lookup gave negative, but... we had foo/bar/
64445 * From the vfs_mknod() POV we just have a negative dentry -
64446@@ -3379,6 +3473,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
64447 }
64448 EXPORT_SYMBOL(user_path_create);
64449
64450+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
64451+{
64452+ struct filename *tmp = getname(pathname);
64453+ struct dentry *res;
64454+ if (IS_ERR(tmp))
64455+ return ERR_CAST(tmp);
64456+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
64457+ if (IS_ERR(res))
64458+ putname(tmp);
64459+ else
64460+ *to = tmp;
64461+ return res;
64462+}
64463+
64464 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
64465 {
64466 int error = may_create(dir, dentry);
64467@@ -3442,6 +3550,17 @@ retry:
64468
64469 if (!IS_POSIXACL(path.dentry->d_inode))
64470 mode &= ~current_umask();
64471+
64472+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
64473+ error = -EPERM;
64474+ goto out;
64475+ }
64476+
64477+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
64478+ error = -EACCES;
64479+ goto out;
64480+ }
64481+
64482 error = security_path_mknod(&path, dentry, mode, dev);
64483 if (error)
64484 goto out;
64485@@ -3457,6 +3576,8 @@ retry:
64486 error = vfs_mknod(path.dentry->d_inode,dentry,mode,0);
64487 break;
64488 }
64489+ if (!error)
64490+ gr_handle_create(dentry, path.mnt);
64491 out:
64492 done_path_create(&path, dentry);
64493 if (retry_estale(error, lookup_flags)) {
64494@@ -3511,9 +3632,16 @@ retry:
64495
64496 if (!IS_POSIXACL(path.dentry->d_inode))
64497 mode &= ~current_umask();
64498+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
64499+ error = -EACCES;
64500+ goto out;
64501+ }
64502 error = security_path_mkdir(&path, dentry, mode);
64503 if (!error)
64504 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
64505+ if (!error)
64506+ gr_handle_create(dentry, path.mnt);
64507+out:
64508 done_path_create(&path, dentry);
64509 if (retry_estale(error, lookup_flags)) {
64510 lookup_flags |= LOOKUP_REVAL;
64511@@ -3596,6 +3724,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
64512 struct filename *name;
64513 struct dentry *dentry;
64514 struct nameidata nd;
64515+ ino_t saved_ino = 0;
64516+ dev_t saved_dev = 0;
64517 unsigned int lookup_flags = 0;
64518 retry:
64519 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64520@@ -3628,10 +3758,21 @@ retry:
64521 error = -ENOENT;
64522 goto exit3;
64523 }
64524+
64525+ saved_ino = dentry->d_inode->i_ino;
64526+ saved_dev = gr_get_dev_from_dentry(dentry);
64527+
64528+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
64529+ error = -EACCES;
64530+ goto exit3;
64531+ }
64532+
64533 error = security_path_rmdir(&nd.path, dentry);
64534 if (error)
64535 goto exit3;
64536 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
64537+ if (!error && (saved_dev || saved_ino))
64538+ gr_handle_delete(saved_ino, saved_dev);
64539 exit3:
64540 dput(dentry);
64541 exit2:
64542@@ -3722,6 +3863,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
64543 struct nameidata nd;
64544 struct inode *inode = NULL;
64545 struct inode *delegated_inode = NULL;
64546+ ino_t saved_ino = 0;
64547+ dev_t saved_dev = 0;
64548 unsigned int lookup_flags = 0;
64549 retry:
64550 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
64551@@ -3748,10 +3891,22 @@ retry_deleg:
64552 if (d_is_negative(dentry))
64553 goto slashes;
64554 ihold(inode);
64555+
64556+ if (inode->i_nlink <= 1) {
64557+ saved_ino = inode->i_ino;
64558+ saved_dev = gr_get_dev_from_dentry(dentry);
64559+ }
64560+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
64561+ error = -EACCES;
64562+ goto exit2;
64563+ }
64564+
64565 error = security_path_unlink(&nd.path, dentry);
64566 if (error)
64567 goto exit2;
64568 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
64569+ if (!error && (saved_ino || saved_dev))
64570+ gr_handle_delete(saved_ino, saved_dev);
64571 exit2:
64572 dput(dentry);
64573 }
64574@@ -3840,9 +3995,17 @@ retry:
64575 if (IS_ERR(dentry))
64576 goto out_putname;
64577
64578+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
64579+ error = -EACCES;
64580+ goto out;
64581+ }
64582+
64583 error = security_path_symlink(&path, dentry, from->name);
64584 if (!error)
64585 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
64586+ if (!error)
64587+ gr_handle_create(dentry, path.mnt);
64588+out:
64589 done_path_create(&path, dentry);
64590 if (retry_estale(error, lookup_flags)) {
64591 lookup_flags |= LOOKUP_REVAL;
64592@@ -3946,6 +4109,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
64593 struct dentry *new_dentry;
64594 struct path old_path, new_path;
64595 struct inode *delegated_inode = NULL;
64596+ struct filename *to = NULL;
64597 int how = 0;
64598 int error;
64599
64600@@ -3969,7 +4133,7 @@ retry:
64601 if (error)
64602 return error;
64603
64604- new_dentry = user_path_create(newdfd, newname, &new_path,
64605+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
64606 (how & LOOKUP_REVAL));
64607 error = PTR_ERR(new_dentry);
64608 if (IS_ERR(new_dentry))
64609@@ -3981,11 +4145,28 @@ retry:
64610 error = may_linkat(&old_path);
64611 if (unlikely(error))
64612 goto out_dput;
64613+
64614+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
64615+ old_path.dentry->d_inode,
64616+ old_path.dentry->d_inode->i_mode, to)) {
64617+ error = -EACCES;
64618+ goto out_dput;
64619+ }
64620+
64621+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
64622+ old_path.dentry, old_path.mnt, to)) {
64623+ error = -EACCES;
64624+ goto out_dput;
64625+ }
64626+
64627 error = security_path_link(old_path.dentry, &new_path, new_dentry);
64628 if (error)
64629 goto out_dput;
64630 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
64631+ if (!error)
64632+ gr_handle_create(new_dentry, new_path.mnt);
64633 out_dput:
64634+ putname(to);
64635 done_path_create(&new_path, new_dentry);
64636 if (delegated_inode) {
64637 error = break_deleg_wait(&delegated_inode);
64638@@ -4296,6 +4477,12 @@ retry_deleg:
64639 if (new_dentry == trap)
64640 goto exit5;
64641
64642+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
64643+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
64644+ to, flags);
64645+ if (error)
64646+ goto exit5;
64647+
64648 error = security_path_rename(&oldnd.path, old_dentry,
64649 &newnd.path, new_dentry, flags);
64650 if (error)
64651@@ -4303,6 +4490,9 @@ retry_deleg:
64652 error = vfs_rename(old_dir->d_inode, old_dentry,
64653 new_dir->d_inode, new_dentry,
64654 &delegated_inode, flags);
64655+ if (!error)
64656+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
64657+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
64658 exit5:
64659 dput(new_dentry);
64660 exit4:
64661@@ -4345,14 +4535,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
64662
64663 int readlink_copy(char __user *buffer, int buflen, const char *link)
64664 {
64665+ char tmpbuf[64];
64666+ const char *newlink;
64667 int len = PTR_ERR(link);
64668+
64669 if (IS_ERR(link))
64670 goto out;
64671
64672 len = strlen(link);
64673 if (len > (unsigned) buflen)
64674 len = buflen;
64675- if (copy_to_user(buffer, link, len))
64676+
64677+ if (len < sizeof(tmpbuf)) {
64678+ memcpy(tmpbuf, link, len);
64679+ newlink = tmpbuf;
64680+ } else
64681+ newlink = link;
64682+
64683+ if (copy_to_user(buffer, newlink, len))
64684 len = -EFAULT;
64685 out:
64686 return len;
64687diff --git a/fs/namespace.c b/fs/namespace.c
64688index 550dbff..c4ad324 100644
64689--- a/fs/namespace.c
64690+++ b/fs/namespace.c
64691@@ -1362,6 +1362,9 @@ static int do_umount(struct mount *mnt, int flags)
64692 if (!(sb->s_flags & MS_RDONLY))
64693 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
64694 up_write(&sb->s_umount);
64695+
64696+ gr_log_remount(mnt->mnt_devname, retval);
64697+
64698 return retval;
64699 }
64700
64701@@ -1384,6 +1387,9 @@ static int do_umount(struct mount *mnt, int flags)
64702 }
64703 unlock_mount_hash();
64704 namespace_unlock();
64705+
64706+ gr_log_unmount(mnt->mnt_devname, retval);
64707+
64708 return retval;
64709 }
64710
64711@@ -1403,7 +1409,7 @@ static inline bool may_mount(void)
64712 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
64713 */
64714
64715-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
64716+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
64717 {
64718 struct path path;
64719 struct mount *mnt;
64720@@ -1445,7 +1451,7 @@ out:
64721 /*
64722 * The 2.0 compatible umount. No flags.
64723 */
64724-SYSCALL_DEFINE1(oldumount, char __user *, name)
64725+SYSCALL_DEFINE1(oldumount, const char __user *, name)
64726 {
64727 return sys_umount(name, 0);
64728 }
64729@@ -2494,6 +2500,16 @@ long do_mount(const char *dev_name, const char *dir_name,
64730 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
64731 MS_STRICTATIME);
64732
64733+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
64734+ retval = -EPERM;
64735+ goto dput_out;
64736+ }
64737+
64738+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
64739+ retval = -EPERM;
64740+ goto dput_out;
64741+ }
64742+
64743 if (flags & MS_REMOUNT)
64744 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
64745 data_page);
64746@@ -2508,6 +2524,9 @@ long do_mount(const char *dev_name, const char *dir_name,
64747 dev_name, data_page);
64748 dput_out:
64749 path_put(&path);
64750+
64751+ gr_log_mount(dev_name, dir_name, retval);
64752+
64753 return retval;
64754 }
64755
64756@@ -2525,7 +2544,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
64757 * number incrementing at 10Ghz will take 12,427 years to wrap which
64758 * is effectively never, so we can ignore the possibility.
64759 */
64760-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
64761+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
64762
64763 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64764 {
64765@@ -2540,7 +2559,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64766 kfree(new_ns);
64767 return ERR_PTR(ret);
64768 }
64769- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
64770+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
64771 atomic_set(&new_ns->count, 1);
64772 new_ns->root = NULL;
64773 INIT_LIST_HEAD(&new_ns->list);
64774@@ -2550,7 +2569,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
64775 return new_ns;
64776 }
64777
64778-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64779+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
64780 struct user_namespace *user_ns, struct fs_struct *new_fs)
64781 {
64782 struct mnt_namespace *new_ns;
64783@@ -2671,8 +2690,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
64784 }
64785 EXPORT_SYMBOL(mount_subtree);
64786
64787-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
64788- char __user *, type, unsigned long, flags, void __user *, data)
64789+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
64790+ const char __user *, type, unsigned long, flags, void __user *, data)
64791 {
64792 int ret;
64793 char *kernel_type;
64794@@ -2785,6 +2804,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
64795 if (error)
64796 goto out2;
64797
64798+ if (gr_handle_chroot_pivot()) {
64799+ error = -EPERM;
64800+ goto out2;
64801+ }
64802+
64803 get_fs_root(current->fs, &root);
64804 old_mp = lock_mount(&old);
64805 error = PTR_ERR(old_mp);
64806@@ -3056,7 +3080,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
64807 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
64808 return -EPERM;
64809
64810- if (fs->users != 1)
64811+ if (atomic_read(&fs->users) != 1)
64812 return -EINVAL;
64813
64814 get_mnt_ns(mnt_ns);
64815diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
64816index f4ccfe6..a5cf064 100644
64817--- a/fs/nfs/callback_xdr.c
64818+++ b/fs/nfs/callback_xdr.c
64819@@ -51,7 +51,7 @@ struct callback_op {
64820 callback_decode_arg_t decode_args;
64821 callback_encode_res_t encode_res;
64822 long res_maxsize;
64823-};
64824+} __do_const;
64825
64826 static struct callback_op callback_ops[];
64827
64828diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
64829index 577a36f..1cde799 100644
64830--- a/fs/nfs/inode.c
64831+++ b/fs/nfs/inode.c
64832@@ -1228,16 +1228,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
64833 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
64834 }
64835
64836-static atomic_long_t nfs_attr_generation_counter;
64837+static atomic_long_unchecked_t nfs_attr_generation_counter;
64838
64839 static unsigned long nfs_read_attr_generation_counter(void)
64840 {
64841- return atomic_long_read(&nfs_attr_generation_counter);
64842+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
64843 }
64844
64845 unsigned long nfs_inc_attr_generation_counter(void)
64846 {
64847- return atomic_long_inc_return(&nfs_attr_generation_counter);
64848+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
64849 }
64850
64851 void nfs_fattr_init(struct nfs_fattr *fattr)
64852diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
64853index 1d3cb47..2b8ed89 100644
64854--- a/fs/nfsd/nfs4proc.c
64855+++ b/fs/nfsd/nfs4proc.c
64856@@ -1155,7 +1155,7 @@ struct nfsd4_operation {
64857 nfsd4op_rsize op_rsize_bop;
64858 stateid_getter op_get_currentstateid;
64859 stateid_setter op_set_currentstateid;
64860-};
64861+} __do_const;
64862
64863 static struct nfsd4_operation nfsd4_ops[];
64864
64865diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
64866index 353aac8..32035ee 100644
64867--- a/fs/nfsd/nfs4xdr.c
64868+++ b/fs/nfsd/nfs4xdr.c
64869@@ -1534,7 +1534,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
64870
64871 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
64872
64873-static nfsd4_dec nfsd4_dec_ops[] = {
64874+static const nfsd4_dec nfsd4_dec_ops[] = {
64875 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
64876 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
64877 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
64878diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
64879index ff95676..96cf3f62 100644
64880--- a/fs/nfsd/nfscache.c
64881+++ b/fs/nfsd/nfscache.c
64882@@ -527,17 +527,20 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64883 {
64884 struct svc_cacherep *rp = rqstp->rq_cacherep;
64885 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
64886- int len;
64887+ long len;
64888 size_t bufsize = 0;
64889
64890 if (!rp)
64891 return;
64892
64893- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
64894- len >>= 2;
64895+ if (statp) {
64896+ len = (char*)statp - (char*)resv->iov_base;
64897+ len = resv->iov_len - len;
64898+ len >>= 2;
64899+ }
64900
64901 /* Don't cache excessive amounts of data and XDR failures */
64902- if (!statp || len > (256 >> 2)) {
64903+ if (!statp || len > (256 >> 2) || len < 0) {
64904 nfsd_reply_cache_free(rp);
64905 return;
64906 }
64907@@ -545,7 +548,7 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
64908 switch (cachetype) {
64909 case RC_REPLSTAT:
64910 if (len != 1)
64911- printk("nfsd: RC_REPLSTAT/reply len %d!\n",len);
64912+ printk("nfsd: RC_REPLSTAT/reply len %ld!\n",len);
64913 rp->c_replstat = *statp;
64914 break;
64915 case RC_REPLBUFF:
64916diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
64917index 6ab077b..5ac7f0b 100644
64918--- a/fs/nfsd/vfs.c
64919+++ b/fs/nfsd/vfs.c
64920@@ -855,7 +855,7 @@ __be32 nfsd_readv(struct file *file, loff_t offset, struct kvec *vec, int vlen,
64921
64922 oldfs = get_fs();
64923 set_fs(KERNEL_DS);
64924- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
64925+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
64926 set_fs(oldfs);
64927 return nfsd_finish_read(file, count, host_err);
64928 }
64929@@ -943,7 +943,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
64930
64931 /* Write the data. */
64932 oldfs = get_fs(); set_fs(KERNEL_DS);
64933- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
64934+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
64935 set_fs(oldfs);
64936 if (host_err < 0)
64937 goto out_nfserr;
64938@@ -1485,7 +1485,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
64939 */
64940
64941 oldfs = get_fs(); set_fs(KERNEL_DS);
64942- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
64943+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
64944 set_fs(oldfs);
64945
64946 if (host_err < 0)
64947diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
64948index 52ccd34..7a6b202 100644
64949--- a/fs/nls/nls_base.c
64950+++ b/fs/nls/nls_base.c
64951@@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
64952
64953 int __register_nls(struct nls_table *nls, struct module *owner)
64954 {
64955- struct nls_table ** tmp = &tables;
64956+ struct nls_table *tmp = tables;
64957
64958 if (nls->next)
64959 return -EBUSY;
64960
64961- nls->owner = owner;
64962+ pax_open_kernel();
64963+ *(void **)&nls->owner = owner;
64964+ pax_close_kernel();
64965 spin_lock(&nls_lock);
64966- while (*tmp) {
64967- if (nls == *tmp) {
64968+ while (tmp) {
64969+ if (nls == tmp) {
64970 spin_unlock(&nls_lock);
64971 return -EBUSY;
64972 }
64973- tmp = &(*tmp)->next;
64974+ tmp = tmp->next;
64975 }
64976- nls->next = tables;
64977+ pax_open_kernel();
64978+ *(struct nls_table **)&nls->next = tables;
64979+ pax_close_kernel();
64980 tables = nls;
64981 spin_unlock(&nls_lock);
64982 return 0;
64983@@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
64984
64985 int unregister_nls(struct nls_table * nls)
64986 {
64987- struct nls_table ** tmp = &tables;
64988+ struct nls_table * const * tmp = &tables;
64989
64990 spin_lock(&nls_lock);
64991 while (*tmp) {
64992 if (nls == *tmp) {
64993- *tmp = nls->next;
64994+ pax_open_kernel();
64995+ *(struct nls_table **)tmp = nls->next;
64996+ pax_close_kernel();
64997 spin_unlock(&nls_lock);
64998 return 0;
64999 }
65000@@ -272,7 +278,7 @@ int unregister_nls(struct nls_table * nls)
65001 return -EINVAL;
65002 }
65003
65004-static struct nls_table *find_nls(char *charset)
65005+static struct nls_table *find_nls(const char *charset)
65006 {
65007 struct nls_table *nls;
65008 spin_lock(&nls_lock);
65009@@ -288,7 +294,7 @@ static struct nls_table *find_nls(char *charset)
65010 return nls;
65011 }
65012
65013-struct nls_table *load_nls(char *charset)
65014+struct nls_table *load_nls(const char *charset)
65015 {
65016 return try_then_request_module(find_nls(charset), "nls_%s", charset);
65017 }
65018diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
65019index 162b3f1..6076a7c 100644
65020--- a/fs/nls/nls_euc-jp.c
65021+++ b/fs/nls/nls_euc-jp.c
65022@@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
65023 p_nls = load_nls("cp932");
65024
65025 if (p_nls) {
65026- table.charset2upper = p_nls->charset2upper;
65027- table.charset2lower = p_nls->charset2lower;
65028+ pax_open_kernel();
65029+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65030+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65031+ pax_close_kernel();
65032 return register_nls(&table);
65033 }
65034
65035diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
65036index a80a741..7b96e1b 100644
65037--- a/fs/nls/nls_koi8-ru.c
65038+++ b/fs/nls/nls_koi8-ru.c
65039@@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
65040 p_nls = load_nls("koi8-u");
65041
65042 if (p_nls) {
65043- table.charset2upper = p_nls->charset2upper;
65044- table.charset2lower = p_nls->charset2lower;
65045+ pax_open_kernel();
65046+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
65047+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
65048+ pax_close_kernel();
65049 return register_nls(&table);
65050 }
65051
65052diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
65053index c991616..5ae51af 100644
65054--- a/fs/notify/fanotify/fanotify_user.c
65055+++ b/fs/notify/fanotify/fanotify_user.c
65056@@ -216,8 +216,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
65057
65058 fd = fanotify_event_metadata.fd;
65059 ret = -EFAULT;
65060- if (copy_to_user(buf, &fanotify_event_metadata,
65061- fanotify_event_metadata.event_len))
65062+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
65063+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
65064 goto out_close_fd;
65065
65066 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
65067diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c
65068index 0f88bc0..7d888d7 100644
65069--- a/fs/notify/inotify/inotify_fsnotify.c
65070+++ b/fs/notify/inotify/inotify_fsnotify.c
65071@@ -165,8 +165,10 @@ static void inotify_free_group_priv(struct fsnotify_group *group)
65072 /* ideally the idr is empty and we won't hit the BUG in the callback */
65073 idr_for_each(&group->inotify_data.idr, idr_callback, group);
65074 idr_destroy(&group->inotify_data.idr);
65075- atomic_dec(&group->inotify_data.user->inotify_devs);
65076- free_uid(group->inotify_data.user);
65077+ if (group->inotify_data.user) {
65078+ atomic_dec(&group->inotify_data.user->inotify_devs);
65079+ free_uid(group->inotify_data.user);
65080+ }
65081 }
65082
65083 static void inotify_free_event(struct fsnotify_event *fsn_event)
65084diff --git a/fs/notify/notification.c b/fs/notify/notification.c
65085index a95d8e0..a91a5fd 100644
65086--- a/fs/notify/notification.c
65087+++ b/fs/notify/notification.c
65088@@ -48,7 +48,7 @@
65089 #include <linux/fsnotify_backend.h>
65090 #include "fsnotify.h"
65091
65092-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65093+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65094
65095 /**
65096 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
65097@@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
65098 */
65099 u32 fsnotify_get_cookie(void)
65100 {
65101- return atomic_inc_return(&fsnotify_sync_cookie);
65102+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
65103 }
65104 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
65105
65106diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
65107index 9e38daf..5727cae 100644
65108--- a/fs/ntfs/dir.c
65109+++ b/fs/ntfs/dir.c
65110@@ -1310,7 +1310,7 @@ find_next_index_buffer:
65111 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
65112 ~(s64)(ndir->itype.index.block_size - 1)));
65113 /* Bounds checks. */
65114- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65115+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
65116 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
65117 "inode 0x%lx or driver bug.", vdir->i_ino);
65118 goto err_out;
65119diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
65120index f5ec1ce..807fd78 100644
65121--- a/fs/ntfs/file.c
65122+++ b/fs/ntfs/file.c
65123@@ -1279,7 +1279,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
65124 char *addr;
65125 size_t total = 0;
65126 unsigned len;
65127- int left;
65128+ unsigned left;
65129
65130 do {
65131 len = PAGE_CACHE_SIZE - ofs;
65132diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
65133index 6c3296e..c0b99f0 100644
65134--- a/fs/ntfs/super.c
65135+++ b/fs/ntfs/super.c
65136@@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65137 if (!silent)
65138 ntfs_error(sb, "Primary boot sector is invalid.");
65139 } else if (!silent)
65140- ntfs_error(sb, read_err_str, "primary");
65141+ ntfs_error(sb, read_err_str, "%s", "primary");
65142 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
65143 if (bh_primary)
65144 brelse(bh_primary);
65145@@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65146 goto hotfix_primary_boot_sector;
65147 brelse(bh_backup);
65148 } else if (!silent)
65149- ntfs_error(sb, read_err_str, "backup");
65150+ ntfs_error(sb, read_err_str, "%s", "backup");
65151 /* Try to read NT3.51- backup boot sector. */
65152 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
65153 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
65154@@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
65155 "sector.");
65156 brelse(bh_backup);
65157 } else if (!silent)
65158- ntfs_error(sb, read_err_str, "backup");
65159+ ntfs_error(sb, read_err_str, "%s", "backup");
65160 /* We failed. Cleanup and return. */
65161 if (bh_primary)
65162 brelse(bh_primary);
65163diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
65164index 0440134..d52c93a 100644
65165--- a/fs/ocfs2/localalloc.c
65166+++ b/fs/ocfs2/localalloc.c
65167@@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
65168 goto bail;
65169 }
65170
65171- atomic_inc(&osb->alloc_stats.moves);
65172+ atomic_inc_unchecked(&osb->alloc_stats.moves);
65173
65174 bail:
65175 if (handle)
65176diff --git a/fs/ocfs2/namei.c b/fs/ocfs2/namei.c
65177index 8add6f1..b931e04 100644
65178--- a/fs/ocfs2/namei.c
65179+++ b/fs/ocfs2/namei.c
65180@@ -158,7 +158,7 @@ bail_add:
65181 * NOTE: This dentry already has ->d_op set from
65182 * ocfs2_get_parent() and ocfs2_get_dentry()
65183 */
65184- if (ret)
65185+ if (!IS_ERR_OR_NULL(ret))
65186 dentry = ret;
65187
65188 status = ocfs2_dentry_attach_lock(dentry, inode,
65189diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
65190index bbec539..7b266d5 100644
65191--- a/fs/ocfs2/ocfs2.h
65192+++ b/fs/ocfs2/ocfs2.h
65193@@ -236,11 +236,11 @@ enum ocfs2_vol_state
65194
65195 struct ocfs2_alloc_stats
65196 {
65197- atomic_t moves;
65198- atomic_t local_data;
65199- atomic_t bitmap_data;
65200- atomic_t bg_allocs;
65201- atomic_t bg_extends;
65202+ atomic_unchecked_t moves;
65203+ atomic_unchecked_t local_data;
65204+ atomic_unchecked_t bitmap_data;
65205+ atomic_unchecked_t bg_allocs;
65206+ atomic_unchecked_t bg_extends;
65207 };
65208
65209 enum ocfs2_local_alloc_state
65210diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
65211index 0cb889a..6a26b24 100644
65212--- a/fs/ocfs2/suballoc.c
65213+++ b/fs/ocfs2/suballoc.c
65214@@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
65215 mlog_errno(status);
65216 goto bail;
65217 }
65218- atomic_inc(&osb->alloc_stats.bg_extends);
65219+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
65220
65221 /* You should never ask for this much metadata */
65222 BUG_ON(bits_wanted >
65223@@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
65224 mlog_errno(status);
65225 goto bail;
65226 }
65227- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65228+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65229
65230 *suballoc_loc = res.sr_bg_blkno;
65231 *suballoc_bit_start = res.sr_bit_offset;
65232@@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
65233 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
65234 res->sr_bits);
65235
65236- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65237+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65238
65239 BUG_ON(res->sr_bits != 1);
65240
65241@@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
65242 mlog_errno(status);
65243 goto bail;
65244 }
65245- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65246+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
65247
65248 BUG_ON(res.sr_bits != 1);
65249
65250@@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65251 cluster_start,
65252 num_clusters);
65253 if (!status)
65254- atomic_inc(&osb->alloc_stats.local_data);
65255+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
65256 } else {
65257 if (min_clusters > (osb->bitmap_cpg - 1)) {
65258 /* The only paths asking for contiguousness
65259@@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
65260 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
65261 res.sr_bg_blkno,
65262 res.sr_bit_offset);
65263- atomic_inc(&osb->alloc_stats.bitmap_data);
65264+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
65265 *num_clusters = res.sr_bits;
65266 }
65267 }
65268diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
65269index 4142546..69375a9 100644
65270--- a/fs/ocfs2/super.c
65271+++ b/fs/ocfs2/super.c
65272@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
65273 "%10s => GlobalAllocs: %d LocalAllocs: %d "
65274 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
65275 "Stats",
65276- atomic_read(&osb->alloc_stats.bitmap_data),
65277- atomic_read(&osb->alloc_stats.local_data),
65278- atomic_read(&osb->alloc_stats.bg_allocs),
65279- atomic_read(&osb->alloc_stats.moves),
65280- atomic_read(&osb->alloc_stats.bg_extends));
65281+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
65282+ atomic_read_unchecked(&osb->alloc_stats.local_data),
65283+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
65284+ atomic_read_unchecked(&osb->alloc_stats.moves),
65285+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
65286
65287 out += snprintf(buf + out, len - out,
65288 "%10s => State: %u Descriptor: %llu Size: %u bits "
65289@@ -2100,11 +2100,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
65290
65291 mutex_init(&osb->system_file_mutex);
65292
65293- atomic_set(&osb->alloc_stats.moves, 0);
65294- atomic_set(&osb->alloc_stats.local_data, 0);
65295- atomic_set(&osb->alloc_stats.bitmap_data, 0);
65296- atomic_set(&osb->alloc_stats.bg_allocs, 0);
65297- atomic_set(&osb->alloc_stats.bg_extends, 0);
65298+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
65299+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
65300+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
65301+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
65302+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
65303
65304 /* Copy the blockcheck stats from the superblock probe */
65305 osb->osb_ecc_stats = *stats;
65306diff --git a/fs/open.c b/fs/open.c
65307index d6fd3ac..6ccf474 100644
65308--- a/fs/open.c
65309+++ b/fs/open.c
65310@@ -32,6 +32,8 @@
65311 #include <linux/dnotify.h>
65312 #include <linux/compat.h>
65313
65314+#define CREATE_TRACE_POINTS
65315+#include <trace/events/fs.h>
65316 #include "internal.h"
65317
65318 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
65319@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
65320 error = locks_verify_truncate(inode, NULL, length);
65321 if (!error)
65322 error = security_path_truncate(path);
65323+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
65324+ error = -EACCES;
65325 if (!error)
65326 error = do_truncate(path->dentry, length, 0, NULL);
65327
65328@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
65329 error = locks_verify_truncate(inode, f.file, length);
65330 if (!error)
65331 error = security_path_truncate(&f.file->f_path);
65332+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
65333+ error = -EACCES;
65334 if (!error)
65335 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
65336 sb_end_write(inode->i_sb);
65337@@ -380,6 +386,9 @@ retry:
65338 if (__mnt_is_readonly(path.mnt))
65339 res = -EROFS;
65340
65341+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
65342+ res = -EACCES;
65343+
65344 out_path_release:
65345 path_put(&path);
65346 if (retry_estale(res, lookup_flags)) {
65347@@ -411,6 +420,8 @@ retry:
65348 if (error)
65349 goto dput_and_out;
65350
65351+ gr_log_chdir(path.dentry, path.mnt);
65352+
65353 set_fs_pwd(current->fs, &path);
65354
65355 dput_and_out:
65356@@ -440,6 +451,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
65357 goto out_putf;
65358
65359 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
65360+
65361+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
65362+ error = -EPERM;
65363+
65364+ if (!error)
65365+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
65366+
65367 if (!error)
65368 set_fs_pwd(current->fs, &f.file->f_path);
65369 out_putf:
65370@@ -469,7 +487,13 @@ retry:
65371 if (error)
65372 goto dput_and_out;
65373
65374+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
65375+ goto dput_and_out;
65376+
65377 set_fs_root(current->fs, &path);
65378+
65379+ gr_handle_chroot_chdir(&path);
65380+
65381 error = 0;
65382 dput_and_out:
65383 path_put(&path);
65384@@ -493,6 +517,16 @@ static int chmod_common(struct path *path, umode_t mode)
65385 return error;
65386 retry_deleg:
65387 mutex_lock(&inode->i_mutex);
65388+
65389+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
65390+ error = -EACCES;
65391+ goto out_unlock;
65392+ }
65393+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
65394+ error = -EACCES;
65395+ goto out_unlock;
65396+ }
65397+
65398 error = security_path_chmod(path, mode);
65399 if (error)
65400 goto out_unlock;
65401@@ -558,6 +592,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
65402 uid = make_kuid(current_user_ns(), user);
65403 gid = make_kgid(current_user_ns(), group);
65404
65405+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
65406+ return -EACCES;
65407+
65408 newattrs.ia_valid = ATTR_CTIME;
65409 if (user != (uid_t) -1) {
65410 if (!uid_valid(uid))
65411@@ -983,6 +1020,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
65412 } else {
65413 fsnotify_open(f);
65414 fd_install(fd, f);
65415+ trace_do_sys_open(tmp->name, flags, mode);
65416 }
65417 }
65418 putname(tmp);
65419diff --git a/fs/pipe.c b/fs/pipe.c
65420index 21981e5..3d5f55c 100644
65421--- a/fs/pipe.c
65422+++ b/fs/pipe.c
65423@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
65424
65425 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
65426 {
65427- if (pipe->files)
65428+ if (atomic_read(&pipe->files))
65429 mutex_lock_nested(&pipe->mutex, subclass);
65430 }
65431
65432@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
65433
65434 void pipe_unlock(struct pipe_inode_info *pipe)
65435 {
65436- if (pipe->files)
65437+ if (atomic_read(&pipe->files))
65438 mutex_unlock(&pipe->mutex);
65439 }
65440 EXPORT_SYMBOL(pipe_unlock);
65441@@ -292,9 +292,9 @@ pipe_read(struct kiocb *iocb, struct iov_iter *to)
65442 }
65443 if (bufs) /* More to do? */
65444 continue;
65445- if (!pipe->writers)
65446+ if (!atomic_read(&pipe->writers))
65447 break;
65448- if (!pipe->waiting_writers) {
65449+ if (!atomic_read(&pipe->waiting_writers)) {
65450 /* syscall merging: Usually we must not sleep
65451 * if O_NONBLOCK is set, or if we got some data.
65452 * But if a writer sleeps in kernel space, then
65453@@ -351,7 +351,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65454
65455 __pipe_lock(pipe);
65456
65457- if (!pipe->readers) {
65458+ if (!atomic_read(&pipe->readers)) {
65459 send_sig(SIGPIPE, current, 0);
65460 ret = -EPIPE;
65461 goto out;
65462@@ -387,7 +387,7 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65463 for (;;) {
65464 int bufs;
65465
65466- if (!pipe->readers) {
65467+ if (!atomic_read(&pipe->readers)) {
65468 send_sig(SIGPIPE, current, 0);
65469 if (!ret)
65470 ret = -EPIPE;
65471@@ -455,9 +455,9 @@ pipe_write(struct kiocb *iocb, struct iov_iter *from)
65472 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65473 do_wakeup = 0;
65474 }
65475- pipe->waiting_writers++;
65476+ atomic_inc(&pipe->waiting_writers);
65477 pipe_wait(pipe);
65478- pipe->waiting_writers--;
65479+ atomic_dec(&pipe->waiting_writers);
65480 }
65481 out:
65482 __pipe_unlock(pipe);
65483@@ -512,7 +512,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65484 mask = 0;
65485 if (filp->f_mode & FMODE_READ) {
65486 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
65487- if (!pipe->writers && filp->f_version != pipe->w_counter)
65488+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
65489 mask |= POLLHUP;
65490 }
65491
65492@@ -522,7 +522,7 @@ pipe_poll(struct file *filp, poll_table *wait)
65493 * Most Unices do not set POLLERR for FIFOs but on Linux they
65494 * behave exactly like pipes for poll().
65495 */
65496- if (!pipe->readers)
65497+ if (!atomic_read(&pipe->readers))
65498 mask |= POLLERR;
65499 }
65500
65501@@ -534,7 +534,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
65502 int kill = 0;
65503
65504 spin_lock(&inode->i_lock);
65505- if (!--pipe->files) {
65506+ if (atomic_dec_and_test(&pipe->files)) {
65507 inode->i_pipe = NULL;
65508 kill = 1;
65509 }
65510@@ -551,11 +551,11 @@ pipe_release(struct inode *inode, struct file *file)
65511
65512 __pipe_lock(pipe);
65513 if (file->f_mode & FMODE_READ)
65514- pipe->readers--;
65515+ atomic_dec(&pipe->readers);
65516 if (file->f_mode & FMODE_WRITE)
65517- pipe->writers--;
65518+ atomic_dec(&pipe->writers);
65519
65520- if (pipe->readers || pipe->writers) {
65521+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
65522 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
65523 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
65524 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
65525@@ -620,7 +620,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
65526 kfree(pipe);
65527 }
65528
65529-static struct vfsmount *pipe_mnt __read_mostly;
65530+struct vfsmount *pipe_mnt __read_mostly;
65531
65532 /*
65533 * pipefs_dname() is called from d_path().
65534@@ -650,8 +650,9 @@ static struct inode * get_pipe_inode(void)
65535 goto fail_iput;
65536
65537 inode->i_pipe = pipe;
65538- pipe->files = 2;
65539- pipe->readers = pipe->writers = 1;
65540+ atomic_set(&pipe->files, 2);
65541+ atomic_set(&pipe->readers, 1);
65542+ atomic_set(&pipe->writers, 1);
65543 inode->i_fop = &pipefifo_fops;
65544
65545 /*
65546@@ -830,17 +831,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
65547 spin_lock(&inode->i_lock);
65548 if (inode->i_pipe) {
65549 pipe = inode->i_pipe;
65550- pipe->files++;
65551+ atomic_inc(&pipe->files);
65552 spin_unlock(&inode->i_lock);
65553 } else {
65554 spin_unlock(&inode->i_lock);
65555 pipe = alloc_pipe_info();
65556 if (!pipe)
65557 return -ENOMEM;
65558- pipe->files = 1;
65559+ atomic_set(&pipe->files, 1);
65560 spin_lock(&inode->i_lock);
65561 if (unlikely(inode->i_pipe)) {
65562- inode->i_pipe->files++;
65563+ atomic_inc(&inode->i_pipe->files);
65564 spin_unlock(&inode->i_lock);
65565 free_pipe_info(pipe);
65566 pipe = inode->i_pipe;
65567@@ -865,10 +866,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
65568 * opened, even when there is no process writing the FIFO.
65569 */
65570 pipe->r_counter++;
65571- if (pipe->readers++ == 0)
65572+ if (atomic_inc_return(&pipe->readers) == 1)
65573 wake_up_partner(pipe);
65574
65575- if (!is_pipe && !pipe->writers) {
65576+ if (!is_pipe && !atomic_read(&pipe->writers)) {
65577 if ((filp->f_flags & O_NONBLOCK)) {
65578 /* suppress POLLHUP until we have
65579 * seen a writer */
65580@@ -887,14 +888,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
65581 * errno=ENXIO when there is no process reading the FIFO.
65582 */
65583 ret = -ENXIO;
65584- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
65585+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
65586 goto err;
65587
65588 pipe->w_counter++;
65589- if (!pipe->writers++)
65590+ if (atomic_inc_return(&pipe->writers) == 1)
65591 wake_up_partner(pipe);
65592
65593- if (!is_pipe && !pipe->readers) {
65594+ if (!is_pipe && !atomic_read(&pipe->readers)) {
65595 if (wait_for_partner(pipe, &pipe->r_counter))
65596 goto err_wr;
65597 }
65598@@ -908,11 +909,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
65599 * the process can at least talk to itself.
65600 */
65601
65602- pipe->readers++;
65603- pipe->writers++;
65604+ atomic_inc(&pipe->readers);
65605+ atomic_inc(&pipe->writers);
65606 pipe->r_counter++;
65607 pipe->w_counter++;
65608- if (pipe->readers == 1 || pipe->writers == 1)
65609+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
65610 wake_up_partner(pipe);
65611 break;
65612
65613@@ -926,13 +927,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
65614 return 0;
65615
65616 err_rd:
65617- if (!--pipe->readers)
65618+ if (atomic_dec_and_test(&pipe->readers))
65619 wake_up_interruptible(&pipe->wait);
65620 ret = -ERESTARTSYS;
65621 goto err;
65622
65623 err_wr:
65624- if (!--pipe->writers)
65625+ if (atomic_dec_and_test(&pipe->writers))
65626 wake_up_interruptible(&pipe->wait);
65627 ret = -ERESTARTSYS;
65628 goto err;
65629diff --git a/fs/posix_acl.c b/fs/posix_acl.c
65630index 0855f77..6787d50 100644
65631--- a/fs/posix_acl.c
65632+++ b/fs/posix_acl.c
65633@@ -20,6 +20,7 @@
65634 #include <linux/xattr.h>
65635 #include <linux/export.h>
65636 #include <linux/user_namespace.h>
65637+#include <linux/grsecurity.h>
65638
65639 struct posix_acl **acl_by_type(struct inode *inode, int type)
65640 {
65641@@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
65642 }
65643 }
65644 if (mode_p)
65645- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65646+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65647 return not_equiv;
65648 }
65649 EXPORT_SYMBOL(posix_acl_equiv_mode);
65650@@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
65651 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
65652 }
65653
65654- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
65655+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
65656 return not_equiv;
65657 }
65658
65659@@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
65660 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
65661 int err = -ENOMEM;
65662 if (clone) {
65663+ *mode_p &= ~gr_acl_umask();
65664+
65665 err = posix_acl_create_masq(clone, mode_p);
65666 if (err < 0) {
65667 posix_acl_release(clone);
65668@@ -659,11 +662,12 @@ struct posix_acl *
65669 posix_acl_from_xattr(struct user_namespace *user_ns,
65670 const void *value, size_t size)
65671 {
65672- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
65673- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
65674+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
65675+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
65676 int count;
65677 struct posix_acl *acl;
65678 struct posix_acl_entry *acl_e;
65679+ umode_t umask = gr_acl_umask();
65680
65681 if (!value)
65682 return NULL;
65683@@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65684
65685 switch(acl_e->e_tag) {
65686 case ACL_USER_OBJ:
65687+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65688+ break;
65689 case ACL_GROUP_OBJ:
65690 case ACL_MASK:
65691+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65692+ break;
65693 case ACL_OTHER:
65694+ acl_e->e_perm &= ~(umask & S_IRWXO);
65695 break;
65696
65697 case ACL_USER:
65698+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65699 acl_e->e_uid =
65700 make_kuid(user_ns,
65701 le32_to_cpu(entry->e_id));
65702@@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65703 goto fail;
65704 break;
65705 case ACL_GROUP:
65706+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65707 acl_e->e_gid =
65708 make_kgid(user_ns,
65709 le32_to_cpu(entry->e_id));
65710diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
65711index 2183fcf..3c32a98 100644
65712--- a/fs/proc/Kconfig
65713+++ b/fs/proc/Kconfig
65714@@ -30,7 +30,7 @@ config PROC_FS
65715
65716 config PROC_KCORE
65717 bool "/proc/kcore support" if !ARM
65718- depends on PROC_FS && MMU
65719+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
65720 help
65721 Provides a virtual ELF core file of the live kernel. This can
65722 be read with gdb and other ELF tools. No modifications can be
65723@@ -38,8 +38,8 @@ config PROC_KCORE
65724
65725 config PROC_VMCORE
65726 bool "/proc/vmcore support"
65727- depends on PROC_FS && CRASH_DUMP
65728- default y
65729+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
65730+ default n
65731 help
65732 Exports the dump image of crashed kernel in ELF format.
65733
65734@@ -63,8 +63,8 @@ config PROC_SYSCTL
65735 limited in memory.
65736
65737 config PROC_PAGE_MONITOR
65738- default y
65739- depends on PROC_FS && MMU
65740+ default n
65741+ depends on PROC_FS && MMU && !GRKERNSEC
65742 bool "Enable /proc page monitoring" if EXPERT
65743 help
65744 Various /proc files exist to monitor process memory utilization:
65745diff --git a/fs/proc/array.c b/fs/proc/array.c
65746index cd3653e..9b9b79a 100644
65747--- a/fs/proc/array.c
65748+++ b/fs/proc/array.c
65749@@ -60,6 +60,7 @@
65750 #include <linux/tty.h>
65751 #include <linux/string.h>
65752 #include <linux/mman.h>
65753+#include <linux/grsecurity.h>
65754 #include <linux/proc_fs.h>
65755 #include <linux/ioport.h>
65756 #include <linux/uaccess.h>
65757@@ -347,6 +348,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
65758 seq_putc(m, '\n');
65759 }
65760
65761+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65762+static inline void task_pax(struct seq_file *m, struct task_struct *p)
65763+{
65764+ if (p->mm)
65765+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
65766+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
65767+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
65768+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
65769+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
65770+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
65771+ else
65772+ seq_printf(m, "PaX:\t-----\n");
65773+}
65774+#endif
65775+
65776 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65777 struct pid *pid, struct task_struct *task)
65778 {
65779@@ -365,9 +381,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
65780 task_cpus_allowed(m, task);
65781 cpuset_task_status_allowed(m, task);
65782 task_context_switch_counts(m, task);
65783+
65784+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
65785+ task_pax(m, task);
65786+#endif
65787+
65788+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
65789+ task_grsec_rbac(m, task);
65790+#endif
65791+
65792 return 0;
65793 }
65794
65795+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65796+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65797+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
65798+ _mm->pax_flags & MF_PAX_SEGMEXEC))
65799+#endif
65800+
65801 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65802 struct pid *pid, struct task_struct *task, int whole)
65803 {
65804@@ -389,6 +420,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65805 char tcomm[sizeof(task->comm)];
65806 unsigned long flags;
65807
65808+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65809+ if (current->exec_id != m->exec_id) {
65810+ gr_log_badprocpid("stat");
65811+ return 0;
65812+ }
65813+#endif
65814+
65815 state = *get_task_state(task);
65816 vsize = eip = esp = 0;
65817 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65818@@ -459,6 +497,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65819 gtime = task_gtime(task);
65820 }
65821
65822+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65823+ if (PAX_RAND_FLAGS(mm)) {
65824+ eip = 0;
65825+ esp = 0;
65826+ wchan = 0;
65827+ }
65828+#endif
65829+#ifdef CONFIG_GRKERNSEC_HIDESYM
65830+ wchan = 0;
65831+ eip =0;
65832+ esp =0;
65833+#endif
65834+
65835 /* scale priority and nice values from timeslices to -20..20 */
65836 /* to make it look like a "normal" Unix priority/nice value */
65837 priority = task_prio(task);
65838@@ -490,9 +541,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65839 seq_put_decimal_ull(m, ' ', vsize);
65840 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
65841 seq_put_decimal_ull(m, ' ', rsslim);
65842+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65843+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
65844+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
65845+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
65846+#else
65847 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
65848 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
65849 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
65850+#endif
65851 seq_put_decimal_ull(m, ' ', esp);
65852 seq_put_decimal_ull(m, ' ', eip);
65853 /* The signal information here is obsolete.
65854@@ -514,7 +571,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
65855 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
65856 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
65857
65858- if (mm && permitted) {
65859+ if (mm && permitted
65860+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65861+ && !PAX_RAND_FLAGS(mm)
65862+#endif
65863+ ) {
65864 seq_put_decimal_ull(m, ' ', mm->start_data);
65865 seq_put_decimal_ull(m, ' ', mm->end_data);
65866 seq_put_decimal_ull(m, ' ', mm->start_brk);
65867@@ -552,8 +613,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65868 struct pid *pid, struct task_struct *task)
65869 {
65870 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
65871- struct mm_struct *mm = get_task_mm(task);
65872+ struct mm_struct *mm;
65873
65874+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65875+ if (current->exec_id != m->exec_id) {
65876+ gr_log_badprocpid("statm");
65877+ return 0;
65878+ }
65879+#endif
65880+ mm = get_task_mm(task);
65881 if (mm) {
65882 size = task_statm(mm, &shared, &text, &data, &resident);
65883 mmput(mm);
65884@@ -576,6 +644,20 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
65885 return 0;
65886 }
65887
65888+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
65889+int proc_pid_ipaddr(struct seq_file *m, struct pid_namespace *ns, struct pid *pid, struct task_struct *task)
65890+{
65891+ unsigned long flags;
65892+ u32 curr_ip = 0;
65893+
65894+ if (lock_task_sighand(task, &flags)) {
65895+ curr_ip = task->signal->curr_ip;
65896+ unlock_task_sighand(task, &flags);
65897+ }
65898+ return seq_printf(m, "%pI4\n", &curr_ip);
65899+}
65900+#endif
65901+
65902 #ifdef CONFIG_CHECKPOINT_RESTORE
65903 static struct pid *
65904 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
65905diff --git a/fs/proc/base.c b/fs/proc/base.c
65906index baf852b..03fe930 100644
65907--- a/fs/proc/base.c
65908+++ b/fs/proc/base.c
65909@@ -113,6 +113,14 @@ struct pid_entry {
65910 union proc_op op;
65911 };
65912
65913+struct getdents_callback {
65914+ struct linux_dirent __user * current_dir;
65915+ struct linux_dirent __user * previous;
65916+ struct file * file;
65917+ int count;
65918+ int error;
65919+};
65920+
65921 #define NOD(NAME, MODE, IOP, FOP, OP) { \
65922 .name = (NAME), \
65923 .len = sizeof(NAME) - 1, \
65924@@ -208,12 +216,28 @@ static int proc_pid_cmdline(struct seq_file *m, struct pid_namespace *ns,
65925 return 0;
65926 }
65927
65928+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65929+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
65930+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
65931+ _mm->pax_flags & MF_PAX_SEGMEXEC))
65932+#endif
65933+
65934 static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65935 struct pid *pid, struct task_struct *task)
65936 {
65937 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
65938 if (mm && !IS_ERR(mm)) {
65939 unsigned int nwords = 0;
65940+
65941+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65942+ /* allow if we're currently ptracing this task */
65943+ if (PAX_RAND_FLAGS(mm) &&
65944+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
65945+ mmput(mm);
65946+ return 0;
65947+ }
65948+#endif
65949+
65950 do {
65951 nwords += 2;
65952 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
65953@@ -225,7 +249,7 @@ static int proc_pid_auxv(struct seq_file *m, struct pid_namespace *ns,
65954 }
65955
65956
65957-#ifdef CONFIG_KALLSYMS
65958+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65959 /*
65960 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
65961 * Returns the resolved symbol. If that fails, simply return the address.
65962@@ -265,7 +289,7 @@ static void unlock_trace(struct task_struct *task)
65963 mutex_unlock(&task->signal->cred_guard_mutex);
65964 }
65965
65966-#ifdef CONFIG_STACKTRACE
65967+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
65968
65969 #define MAX_STACK_TRACE_DEPTH 64
65970
65971@@ -487,7 +511,7 @@ static int proc_pid_limits(struct seq_file *m, struct pid_namespace *ns,
65972 return 0;
65973 }
65974
65975-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
65976+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
65977 static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
65978 struct pid *pid, struct task_struct *task)
65979 {
65980@@ -517,7 +541,7 @@ static int proc_pid_syscall(struct seq_file *m, struct pid_namespace *ns,
65981 /************************************************************************/
65982
65983 /* permission checks */
65984-static int proc_fd_access_allowed(struct inode *inode)
65985+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
65986 {
65987 struct task_struct *task;
65988 int allowed = 0;
65989@@ -527,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
65990 */
65991 task = get_proc_task(inode);
65992 if (task) {
65993- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
65994+ if (log)
65995+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
65996+ else
65997+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
65998 put_task_struct(task);
65999 }
66000 return allowed;
66001@@ -558,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
66002 struct task_struct *task,
66003 int hide_pid_min)
66004 {
66005+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66006+ return false;
66007+
66008+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66009+ rcu_read_lock();
66010+ {
66011+ const struct cred *tmpcred = current_cred();
66012+ const struct cred *cred = __task_cred(task);
66013+
66014+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
66015+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66016+ || in_group_p(grsec_proc_gid)
66017+#endif
66018+ ) {
66019+ rcu_read_unlock();
66020+ return true;
66021+ }
66022+ }
66023+ rcu_read_unlock();
66024+
66025+ if (!pid->hide_pid)
66026+ return false;
66027+#endif
66028+
66029 if (pid->hide_pid < hide_pid_min)
66030 return true;
66031 if (in_group_p(pid->pid_gid))
66032 return true;
66033+
66034 return ptrace_may_access(task, PTRACE_MODE_READ);
66035 }
66036
66037@@ -579,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
66038 put_task_struct(task);
66039
66040 if (!has_perms) {
66041+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66042+ {
66043+#else
66044 if (pid->hide_pid == 2) {
66045+#endif
66046 /*
66047 * Let's make getdents(), stat(), and open()
66048 * consistent with each other. If a process
66049@@ -640,6 +696,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66050 if (!task)
66051 return -ESRCH;
66052
66053+ if (gr_acl_handle_procpidmem(task)) {
66054+ put_task_struct(task);
66055+ return -EPERM;
66056+ }
66057+
66058 mm = mm_access(task, mode);
66059 put_task_struct(task);
66060
66061@@ -655,6 +716,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
66062
66063 file->private_data = mm;
66064
66065+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66066+ file->f_version = current->exec_id;
66067+#endif
66068+
66069 return 0;
66070 }
66071
66072@@ -676,6 +741,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66073 ssize_t copied;
66074 char *page;
66075
66076+#ifdef CONFIG_GRKERNSEC
66077+ if (write)
66078+ return -EPERM;
66079+#endif
66080+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66081+ if (file->f_version != current->exec_id) {
66082+ gr_log_badprocpid("mem");
66083+ return 0;
66084+ }
66085+#endif
66086+
66087 if (!mm)
66088 return 0;
66089
66090@@ -688,7 +764,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
66091 goto free;
66092
66093 while (count > 0) {
66094- int this_len = min_t(int, count, PAGE_SIZE);
66095+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
66096
66097 if (write && copy_from_user(page, buf, this_len)) {
66098 copied = -EFAULT;
66099@@ -780,6 +856,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66100 if (!mm)
66101 return 0;
66102
66103+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
66104+ if (file->f_version != current->exec_id) {
66105+ gr_log_badprocpid("environ");
66106+ return 0;
66107+ }
66108+#endif
66109+
66110 page = (char *)__get_free_page(GFP_TEMPORARY);
66111 if (!page)
66112 return -ENOMEM;
66113@@ -789,7 +872,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
66114 goto free;
66115 while (count > 0) {
66116 size_t this_len, max_len;
66117- int retval;
66118+ ssize_t retval;
66119
66120 if (src >= (mm->env_end - mm->env_start))
66121 break;
66122@@ -1403,7 +1486,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
66123 int error = -EACCES;
66124
66125 /* Are we allowed to snoop on the tasks file descriptors? */
66126- if (!proc_fd_access_allowed(inode))
66127+ if (!proc_fd_access_allowed(inode, 0))
66128 goto out;
66129
66130 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66131@@ -1447,8 +1530,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
66132 struct path path;
66133
66134 /* Are we allowed to snoop on the tasks file descriptors? */
66135- if (!proc_fd_access_allowed(inode))
66136- goto out;
66137+ /* logging this is needed for learning on chromium to work properly,
66138+ but we don't want to flood the logs from 'ps' which does a readlink
66139+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
66140+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
66141+ */
66142+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
66143+ if (!proc_fd_access_allowed(inode,0))
66144+ goto out;
66145+ } else {
66146+ if (!proc_fd_access_allowed(inode,1))
66147+ goto out;
66148+ }
66149
66150 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
66151 if (error)
66152@@ -1498,7 +1591,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
66153 rcu_read_lock();
66154 cred = __task_cred(task);
66155 inode->i_uid = cred->euid;
66156+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66157+ inode->i_gid = grsec_proc_gid;
66158+#else
66159 inode->i_gid = cred->egid;
66160+#endif
66161 rcu_read_unlock();
66162 }
66163 security_task_to_inode(task, inode);
66164@@ -1534,10 +1631,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
66165 return -ENOENT;
66166 }
66167 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66168+#ifdef CONFIG_GRKERNSEC_PROC_USER
66169+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66170+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66171+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66172+#endif
66173 task_dumpable(task)) {
66174 cred = __task_cred(task);
66175 stat->uid = cred->euid;
66176+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66177+ stat->gid = grsec_proc_gid;
66178+#else
66179 stat->gid = cred->egid;
66180+#endif
66181 }
66182 }
66183 rcu_read_unlock();
66184@@ -1575,11 +1681,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
66185
66186 if (task) {
66187 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
66188+#ifdef CONFIG_GRKERNSEC_PROC_USER
66189+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
66190+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66191+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
66192+#endif
66193 task_dumpable(task)) {
66194 rcu_read_lock();
66195 cred = __task_cred(task);
66196 inode->i_uid = cred->euid;
66197+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66198+ inode->i_gid = grsec_proc_gid;
66199+#else
66200 inode->i_gid = cred->egid;
66201+#endif
66202 rcu_read_unlock();
66203 } else {
66204 inode->i_uid = GLOBAL_ROOT_UID;
66205@@ -2114,6 +2229,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
66206 if (!task)
66207 goto out_no_task;
66208
66209+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66210+ goto out;
66211+
66212 /*
66213 * Yes, it does not scale. And it should not. Don't add
66214 * new entries into /proc/<tgid>/ without very good reasons.
66215@@ -2144,6 +2262,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
66216 if (!task)
66217 return -ENOENT;
66218
66219+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66220+ goto out;
66221+
66222 if (!dir_emit_dots(file, ctx))
66223 goto out;
66224
66225@@ -2535,7 +2656,7 @@ static const struct pid_entry tgid_base_stuff[] = {
66226 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
66227 #endif
66228 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66229-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66230+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66231 ONE("syscall", S_IRUSR, proc_pid_syscall),
66232 #endif
66233 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66234@@ -2560,10 +2681,10 @@ static const struct pid_entry tgid_base_stuff[] = {
66235 #ifdef CONFIG_SECURITY
66236 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66237 #endif
66238-#ifdef CONFIG_KALLSYMS
66239+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66240 ONE("wchan", S_IRUGO, proc_pid_wchan),
66241 #endif
66242-#ifdef CONFIG_STACKTRACE
66243+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66244 ONE("stack", S_IRUSR, proc_pid_stack),
66245 #endif
66246 #ifdef CONFIG_SCHEDSTATS
66247@@ -2597,6 +2718,9 @@ static const struct pid_entry tgid_base_stuff[] = {
66248 #ifdef CONFIG_HARDWALL
66249 ONE("hardwall", S_IRUGO, proc_pid_hardwall),
66250 #endif
66251+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66252+ ONE("ipaddr", S_IRUSR, proc_pid_ipaddr),
66253+#endif
66254 #ifdef CONFIG_USER_NS
66255 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
66256 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
66257@@ -2727,7 +2851,14 @@ static int proc_pid_instantiate(struct inode *dir,
66258 if (!inode)
66259 goto out;
66260
66261+#ifdef CONFIG_GRKERNSEC_PROC_USER
66262+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
66263+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66264+ inode->i_gid = grsec_proc_gid;
66265+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
66266+#else
66267 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
66268+#endif
66269 inode->i_op = &proc_tgid_base_inode_operations;
66270 inode->i_fop = &proc_tgid_base_operations;
66271 inode->i_flags|=S_IMMUTABLE;
66272@@ -2765,7 +2896,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
66273 if (!task)
66274 goto out;
66275
66276+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
66277+ goto out_put_task;
66278+
66279 result = proc_pid_instantiate(dir, dentry, task, NULL);
66280+out_put_task:
66281 put_task_struct(task);
66282 out:
66283 return ERR_PTR(result);
66284@@ -2879,7 +3014,7 @@ static const struct pid_entry tid_base_stuff[] = {
66285 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
66286 #endif
66287 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
66288-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
66289+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
66290 ONE("syscall", S_IRUSR, proc_pid_syscall),
66291 #endif
66292 ONE("cmdline", S_IRUGO, proc_pid_cmdline),
66293@@ -2906,10 +3041,10 @@ static const struct pid_entry tid_base_stuff[] = {
66294 #ifdef CONFIG_SECURITY
66295 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
66296 #endif
66297-#ifdef CONFIG_KALLSYMS
66298+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66299 ONE("wchan", S_IRUGO, proc_pid_wchan),
66300 #endif
66301-#ifdef CONFIG_STACKTRACE
66302+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
66303 ONE("stack", S_IRUSR, proc_pid_stack),
66304 #endif
66305 #ifdef CONFIG_SCHEDSTATS
66306diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
66307index cbd82df..c0407d2 100644
66308--- a/fs/proc/cmdline.c
66309+++ b/fs/proc/cmdline.c
66310@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
66311
66312 static int __init proc_cmdline_init(void)
66313 {
66314+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66315+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
66316+#else
66317 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
66318+#endif
66319 return 0;
66320 }
66321 fs_initcall(proc_cmdline_init);
66322diff --git a/fs/proc/devices.c b/fs/proc/devices.c
66323index 50493ed..248166b 100644
66324--- a/fs/proc/devices.c
66325+++ b/fs/proc/devices.c
66326@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
66327
66328 static int __init proc_devices_init(void)
66329 {
66330+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66331+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
66332+#else
66333 proc_create("devices", 0, NULL, &proc_devinfo_operations);
66334+#endif
66335 return 0;
66336 }
66337 fs_initcall(proc_devices_init);
66338diff --git a/fs/proc/fd.c b/fs/proc/fd.c
66339index 955bb55..71948bd 100644
66340--- a/fs/proc/fd.c
66341+++ b/fs/proc/fd.c
66342@@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
66343 if (!task)
66344 return -ENOENT;
66345
66346- files = get_files_struct(task);
66347+ if (!gr_acl_handle_procpidmem(task))
66348+ files = get_files_struct(task);
66349 put_task_struct(task);
66350
66351 if (files) {
66352@@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
66353 */
66354 int proc_fd_permission(struct inode *inode, int mask)
66355 {
66356+ struct task_struct *task;
66357 int rv = generic_permission(inode, mask);
66358- if (rv == 0)
66359- return 0;
66360+
66361 if (task_tgid(current) == proc_pid(inode))
66362 rv = 0;
66363+
66364+ task = get_proc_task(inode);
66365+ if (task == NULL)
66366+ return rv;
66367+
66368+ if (gr_acl_handle_procpidmem(task))
66369+ rv = -EACCES;
66370+
66371+ put_task_struct(task);
66372+
66373 return rv;
66374 }
66375
66376diff --git a/fs/proc/generic.c b/fs/proc/generic.c
66377index 317b726..e329aed 100644
66378--- a/fs/proc/generic.c
66379+++ b/fs/proc/generic.c
66380@@ -23,6 +23,7 @@
66381 #include <linux/bitops.h>
66382 #include <linux/spinlock.h>
66383 #include <linux/completion.h>
66384+#include <linux/grsecurity.h>
66385 #include <asm/uaccess.h>
66386
66387 #include "internal.h"
66388@@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
66389 return proc_lookup_de(PDE(dir), dir, dentry);
66390 }
66391
66392+struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
66393+ unsigned int flags)
66394+{
66395+ if (gr_proc_is_restricted())
66396+ return ERR_PTR(-EACCES);
66397+
66398+ return proc_lookup_de(PDE(dir), dir, dentry);
66399+}
66400+
66401 /*
66402 * This returns non-zero if at EOF, so that the /proc
66403 * root directory can use this and check if it should
66404@@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
66405 return proc_readdir_de(PDE(inode), file, ctx);
66406 }
66407
66408+int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
66409+{
66410+ struct inode *inode = file_inode(file);
66411+
66412+ if (gr_proc_is_restricted())
66413+ return -EACCES;
66414+
66415+ return proc_readdir_de(PDE(inode), file, ctx);
66416+}
66417+
66418 /*
66419 * These are the generic /proc directory operations. They
66420 * use the in-memory "struct proc_dir_entry" tree to parse
66421@@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
66422 .iterate = proc_readdir,
66423 };
66424
66425+static const struct file_operations proc_dir_restricted_operations = {
66426+ .llseek = generic_file_llseek,
66427+ .read = generic_read_dir,
66428+ .iterate = proc_readdir_restrict,
66429+};
66430+
66431 /*
66432 * proc directories can do almost nothing..
66433 */
66434@@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
66435 .setattr = proc_notify_change,
66436 };
66437
66438+static const struct inode_operations proc_dir_restricted_inode_operations = {
66439+ .lookup = proc_lookup_restrict,
66440+ .getattr = proc_getattr,
66441+ .setattr = proc_notify_change,
66442+};
66443+
66444 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
66445 {
66446 struct proc_dir_entry *tmp;
66447@@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
66448 return ret;
66449
66450 if (S_ISDIR(dp->mode)) {
66451- dp->proc_fops = &proc_dir_operations;
66452- dp->proc_iops = &proc_dir_inode_operations;
66453+ if (dp->restricted) {
66454+ dp->proc_fops = &proc_dir_restricted_operations;
66455+ dp->proc_iops = &proc_dir_restricted_inode_operations;
66456+ } else {
66457+ dp->proc_fops = &proc_dir_operations;
66458+ dp->proc_iops = &proc_dir_inode_operations;
66459+ }
66460 dir->nlink++;
66461 } else if (S_ISLNK(dp->mode)) {
66462 dp->proc_iops = &proc_link_inode_operations;
66463@@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
66464 }
66465 EXPORT_SYMBOL_GPL(proc_mkdir_data);
66466
66467+struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
66468+ struct proc_dir_entry *parent, void *data)
66469+{
66470+ struct proc_dir_entry *ent;
66471+
66472+ if (mode == 0)
66473+ mode = S_IRUGO | S_IXUGO;
66474+
66475+ ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
66476+ if (ent) {
66477+ ent->data = data;
66478+ ent->restricted = 1;
66479+ if (proc_register(parent, ent) < 0) {
66480+ kfree(ent);
66481+ ent = NULL;
66482+ }
66483+ }
66484+ return ent;
66485+}
66486+EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
66487+
66488 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
66489 struct proc_dir_entry *parent)
66490 {
66491@@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
66492 }
66493 EXPORT_SYMBOL(proc_mkdir);
66494
66495+struct proc_dir_entry *proc_mkdir_restrict(const char *name,
66496+ struct proc_dir_entry *parent)
66497+{
66498+ return proc_mkdir_data_restrict(name, 0, parent, NULL);
66499+}
66500+EXPORT_SYMBOL(proc_mkdir_restrict);
66501+
66502 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
66503 struct proc_dir_entry *parent,
66504 const struct file_operations *proc_fops,
66505diff --git a/fs/proc/inode.c b/fs/proc/inode.c
66506index 333080d..0a35ec4 100644
66507--- a/fs/proc/inode.c
66508+++ b/fs/proc/inode.c
66509@@ -23,11 +23,17 @@
66510 #include <linux/slab.h>
66511 #include <linux/mount.h>
66512 #include <linux/magic.h>
66513+#include <linux/grsecurity.h>
66514
66515 #include <asm/uaccess.h>
66516
66517 #include "internal.h"
66518
66519+#ifdef CONFIG_PROC_SYSCTL
66520+extern const struct inode_operations proc_sys_inode_operations;
66521+extern const struct inode_operations proc_sys_dir_operations;
66522+#endif
66523+
66524 static void proc_evict_inode(struct inode *inode)
66525 {
66526 struct proc_dir_entry *de;
66527@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
66528 ns = PROC_I(inode)->ns.ns;
66529 if (ns_ops && ns)
66530 ns_ops->put(ns);
66531+
66532+#ifdef CONFIG_PROC_SYSCTL
66533+ if (inode->i_op == &proc_sys_inode_operations ||
66534+ inode->i_op == &proc_sys_dir_operations)
66535+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
66536+#endif
66537+
66538 }
66539
66540 static struct kmem_cache * proc_inode_cachep;
66541@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
66542 if (de->mode) {
66543 inode->i_mode = de->mode;
66544 inode->i_uid = de->uid;
66545+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66546+ inode->i_gid = grsec_proc_gid;
66547+#else
66548 inode->i_gid = de->gid;
66549+#endif
66550 }
66551 if (de->size)
66552 inode->i_size = de->size;
66553diff --git a/fs/proc/internal.h b/fs/proc/internal.h
66554index 7da13e4..68d0981 100644
66555--- a/fs/proc/internal.h
66556+++ b/fs/proc/internal.h
66557@@ -46,9 +46,10 @@ struct proc_dir_entry {
66558 struct completion *pde_unload_completion;
66559 struct list_head pde_openers; /* who did ->open, but not ->release */
66560 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
66561+ u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
66562 u8 namelen;
66563 char name[];
66564-};
66565+} __randomize_layout;
66566
66567 union proc_op {
66568 int (*proc_get_link)(struct dentry *, struct path *);
66569@@ -66,7 +67,7 @@ struct proc_inode {
66570 struct ctl_table *sysctl_entry;
66571 struct proc_ns ns;
66572 struct inode vfs_inode;
66573-};
66574+} __randomize_layout;
66575
66576 /*
66577 * General functions
66578@@ -154,6 +155,10 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
66579 struct pid *, struct task_struct *);
66580 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
66581 struct pid *, struct task_struct *);
66582+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
66583+extern int proc_pid_ipaddr(struct seq_file *, struct pid_namespace *,
66584+ struct pid *, struct task_struct *);
66585+#endif
66586
66587 /*
66588 * base.c
66589@@ -178,9 +183,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
66590 * generic.c
66591 */
66592 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
66593+extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
66594 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
66595 struct dentry *);
66596 extern int proc_readdir(struct file *, struct dir_context *);
66597+extern int proc_readdir_restrict(struct file *, struct dir_context *);
66598 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
66599
66600 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
66601diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
66602index a352d57..cb94a5c 100644
66603--- a/fs/proc/interrupts.c
66604+++ b/fs/proc/interrupts.c
66605@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
66606
66607 static int __init proc_interrupts_init(void)
66608 {
66609+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66610+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
66611+#else
66612 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
66613+#endif
66614 return 0;
66615 }
66616 fs_initcall(proc_interrupts_init);
66617diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
66618index 6df8d07..3321060 100644
66619--- a/fs/proc/kcore.c
66620+++ b/fs/proc/kcore.c
66621@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66622 * the addresses in the elf_phdr on our list.
66623 */
66624 start = kc_offset_to_vaddr(*fpos - elf_buflen);
66625- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
66626+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
66627+ if (tsz > buflen)
66628 tsz = buflen;
66629-
66630+
66631 while (buflen) {
66632 struct kcore_list *m;
66633
66634@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66635 kfree(elf_buf);
66636 } else {
66637 if (kern_addr_valid(start)) {
66638- unsigned long n;
66639+ char *elf_buf;
66640+ mm_segment_t oldfs;
66641
66642- n = copy_to_user(buffer, (char *)start, tsz);
66643- /*
66644- * We cannot distinguish between fault on source
66645- * and fault on destination. When this happens
66646- * we clear too and hope it will trigger the
66647- * EFAULT again.
66648- */
66649- if (n) {
66650- if (clear_user(buffer + tsz - n,
66651- n))
66652+ elf_buf = kmalloc(tsz, GFP_KERNEL);
66653+ if (!elf_buf)
66654+ return -ENOMEM;
66655+ oldfs = get_fs();
66656+ set_fs(KERNEL_DS);
66657+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
66658+ set_fs(oldfs);
66659+ if (copy_to_user(buffer, elf_buf, tsz)) {
66660+ kfree(elf_buf);
66661 return -EFAULT;
66662+ }
66663 }
66664+ set_fs(oldfs);
66665+ kfree(elf_buf);
66666 } else {
66667 if (clear_user(buffer, tsz))
66668 return -EFAULT;
66669@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
66670
66671 static int open_kcore(struct inode *inode, struct file *filp)
66672 {
66673+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66674+ return -EPERM;
66675+#endif
66676 if (!capable(CAP_SYS_RAWIO))
66677 return -EPERM;
66678 if (kcore_need_update)
66679diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
66680index aa1eee0..03dda72 100644
66681--- a/fs/proc/meminfo.c
66682+++ b/fs/proc/meminfo.c
66683@@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
66684 vmi.used >> 10,
66685 vmi.largest_chunk >> 10
66686 #ifdef CONFIG_MEMORY_FAILURE
66687- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66688+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
66689 #endif
66690 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
66691 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
66692diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
66693index d4a3574..b421ce9 100644
66694--- a/fs/proc/nommu.c
66695+++ b/fs/proc/nommu.c
66696@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
66697
66698 if (file) {
66699 seq_pad(m, ' ');
66700- seq_path(m, &file->f_path, "");
66701+ seq_path(m, &file->f_path, "\n\\");
66702 }
66703
66704 seq_putc(m, '\n');
66705diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
66706index a63af3e..b4f262a 100644
66707--- a/fs/proc/proc_net.c
66708+++ b/fs/proc/proc_net.c
66709@@ -23,9 +23,27 @@
66710 #include <linux/nsproxy.h>
66711 #include <net/net_namespace.h>
66712 #include <linux/seq_file.h>
66713+#include <linux/grsecurity.h>
66714
66715 #include "internal.h"
66716
66717+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66718+static struct seq_operations *ipv6_seq_ops_addr;
66719+
66720+void register_ipv6_seq_ops_addr(struct seq_operations *addr)
66721+{
66722+ ipv6_seq_ops_addr = addr;
66723+}
66724+
66725+void unregister_ipv6_seq_ops_addr(void)
66726+{
66727+ ipv6_seq_ops_addr = NULL;
66728+}
66729+
66730+EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
66731+EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
66732+#endif
66733+
66734 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
66735 {
66736 return pde->parent->data;
66737@@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
66738 return maybe_get_net(PDE_NET(PDE(inode)));
66739 }
66740
66741+extern const struct seq_operations dev_seq_ops;
66742+
66743 int seq_open_net(struct inode *ino, struct file *f,
66744 const struct seq_operations *ops, int size)
66745 {
66746@@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
66747
66748 BUG_ON(size < sizeof(*p));
66749
66750+ /* only permit access to /proc/net/dev */
66751+ if (
66752+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
66753+ ops != ipv6_seq_ops_addr &&
66754+#endif
66755+ ops != &dev_seq_ops && gr_proc_is_restricted())
66756+ return -EACCES;
66757+
66758 net = get_proc_net(ino);
66759 if (net == NULL)
66760 return -ENXIO;
66761@@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
66762 int err;
66763 struct net *net;
66764
66765+ if (gr_proc_is_restricted())
66766+ return -EACCES;
66767+
66768 err = -ENXIO;
66769 net = get_proc_net(inode);
66770 if (net == NULL)
66771diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
66772index f92d5dd..26398ac 100644
66773--- a/fs/proc/proc_sysctl.c
66774+++ b/fs/proc/proc_sysctl.c
66775@@ -11,13 +11,21 @@
66776 #include <linux/namei.h>
66777 #include <linux/mm.h>
66778 #include <linux/module.h>
66779+#include <linux/nsproxy.h>
66780+#ifdef CONFIG_GRKERNSEC
66781+#include <net/net_namespace.h>
66782+#endif
66783 #include "internal.h"
66784
66785+extern int gr_handle_chroot_sysctl(const int op);
66786+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
66787+ const int op);
66788+
66789 static const struct dentry_operations proc_sys_dentry_operations;
66790 static const struct file_operations proc_sys_file_operations;
66791-static const struct inode_operations proc_sys_inode_operations;
66792+const struct inode_operations proc_sys_inode_operations;
66793 static const struct file_operations proc_sys_dir_file_operations;
66794-static const struct inode_operations proc_sys_dir_operations;
66795+const struct inode_operations proc_sys_dir_operations;
66796
66797 void proc_sys_poll_notify(struct ctl_table_poll *poll)
66798 {
66799@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
66800
66801 err = NULL;
66802 d_set_d_op(dentry, &proc_sys_dentry_operations);
66803+
66804+ gr_handle_proc_create(dentry, inode);
66805+
66806 d_add(dentry, inode);
66807
66808 out:
66809@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66810 struct inode *inode = file_inode(filp);
66811 struct ctl_table_header *head = grab_header(inode);
66812 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
66813+ int op = write ? MAY_WRITE : MAY_READ;
66814 ssize_t error;
66815 size_t res;
66816
66817@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66818 * and won't be until we finish.
66819 */
66820 error = -EPERM;
66821- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
66822+ if (sysctl_perm(head, table, op))
66823 goto out;
66824
66825 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
66826@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
66827 if (!table->proc_handler)
66828 goto out;
66829
66830+#ifdef CONFIG_GRKERNSEC
66831+ error = -EPERM;
66832+ if (gr_handle_chroot_sysctl(op))
66833+ goto out;
66834+ dget(filp->f_path.dentry);
66835+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
66836+ dput(filp->f_path.dentry);
66837+ goto out;
66838+ }
66839+ dput(filp->f_path.dentry);
66840+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
66841+ goto out;
66842+ if (write) {
66843+ if (current->nsproxy->net_ns != table->extra2) {
66844+ if (!capable(CAP_SYS_ADMIN))
66845+ goto out;
66846+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
66847+ goto out;
66848+ }
66849+#endif
66850+
66851 /* careful: calling conventions are nasty here */
66852 res = count;
66853 error = table->proc_handler(table, write, buf, &res, ppos);
66854@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
66855 return false;
66856 } else {
66857 d_set_d_op(child, &proc_sys_dentry_operations);
66858+
66859+ gr_handle_proc_create(child, inode);
66860+
66861 d_add(child, inode);
66862 }
66863 } else {
66864@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, struct ctl_table *table,
66865 if ((*pos)++ < ctx->pos)
66866 return true;
66867
66868+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
66869+ return 0;
66870+
66871 if (unlikely(S_ISLNK(table->mode)))
66872 res = proc_sys_link_fill_cache(file, ctx, head, table);
66873 else
66874@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
66875 if (IS_ERR(head))
66876 return PTR_ERR(head);
66877
66878+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
66879+ return -ENOENT;
66880+
66881 generic_fillattr(inode, stat);
66882 if (table)
66883 stat->mode = (stat->mode & S_IFMT) | table->mode;
66884@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
66885 .llseek = generic_file_llseek,
66886 };
66887
66888-static const struct inode_operations proc_sys_inode_operations = {
66889+const struct inode_operations proc_sys_inode_operations = {
66890 .permission = proc_sys_permission,
66891 .setattr = proc_sys_setattr,
66892 .getattr = proc_sys_getattr,
66893 };
66894
66895-static const struct inode_operations proc_sys_dir_operations = {
66896+const struct inode_operations proc_sys_dir_operations = {
66897 .lookup = proc_sys_lookup,
66898 .permission = proc_sys_permission,
66899 .setattr = proc_sys_setattr,
66900@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
66901 static struct ctl_dir *new_dir(struct ctl_table_set *set,
66902 const char *name, int namelen)
66903 {
66904- struct ctl_table *table;
66905+ ctl_table_no_const *table;
66906 struct ctl_dir *new;
66907 struct ctl_node *node;
66908 char *new_name;
66909@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
66910 return NULL;
66911
66912 node = (struct ctl_node *)(new + 1);
66913- table = (struct ctl_table *)(node + 1);
66914+ table = (ctl_table_no_const *)(node + 1);
66915 new_name = (char *)(table + 2);
66916 memcpy(new_name, name, namelen);
66917 new_name[namelen] = '\0';
66918@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
66919 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
66920 struct ctl_table_root *link_root)
66921 {
66922- struct ctl_table *link_table, *entry, *link;
66923+ ctl_table_no_const *link_table, *link;
66924+ struct ctl_table *entry;
66925 struct ctl_table_header *links;
66926 struct ctl_node *node;
66927 char *link_name;
66928@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
66929 return NULL;
66930
66931 node = (struct ctl_node *)(links + 1);
66932- link_table = (struct ctl_table *)(node + nr_entries);
66933+ link_table = (ctl_table_no_const *)(node + nr_entries);
66934 link_name = (char *)&link_table[nr_entries + 1];
66935
66936 for (link = link_table, entry = table; entry->procname; link++, entry++) {
66937@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66938 struct ctl_table_header ***subheader, struct ctl_table_set *set,
66939 struct ctl_table *table)
66940 {
66941- struct ctl_table *ctl_table_arg = NULL;
66942- struct ctl_table *entry, *files;
66943+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
66944+ struct ctl_table *entry;
66945 int nr_files = 0;
66946 int nr_dirs = 0;
66947 int err = -ENOMEM;
66948@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66949 nr_files++;
66950 }
66951
66952- files = table;
66953 /* If there are mixed files and directories we need a new table */
66954 if (nr_dirs && nr_files) {
66955- struct ctl_table *new;
66956+ ctl_table_no_const *new;
66957 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
66958 GFP_KERNEL);
66959 if (!files)
66960@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
66961 /* Register everything except a directory full of subdirectories */
66962 if (nr_files || !nr_dirs) {
66963 struct ctl_table_header *header;
66964- header = __register_sysctl_table(set, path, files);
66965+ header = __register_sysctl_table(set, path, files ? files : table);
66966 if (!header) {
66967 kfree(ctl_table_arg);
66968 goto out;
66969diff --git a/fs/proc/root.c b/fs/proc/root.c
66970index 094e44d..085a877 100644
66971--- a/fs/proc/root.c
66972+++ b/fs/proc/root.c
66973@@ -188,7 +188,15 @@ void __init proc_root_init(void)
66974 proc_mkdir("openprom", NULL);
66975 #endif
66976 proc_tty_init();
66977+#ifdef CONFIG_GRKERNSEC_PROC_ADD
66978+#ifdef CONFIG_GRKERNSEC_PROC_USER
66979+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
66980+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66981+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
66982+#endif
66983+#else
66984 proc_mkdir("bus", NULL);
66985+#endif
66986 proc_sys_init();
66987 }
66988
66989diff --git a/fs/proc/stat.c b/fs/proc/stat.c
66990index bf2d03f..f058f9c 100644
66991--- a/fs/proc/stat.c
66992+++ b/fs/proc/stat.c
66993@@ -11,6 +11,7 @@
66994 #include <linux/irqnr.h>
66995 #include <linux/cputime.h>
66996 #include <linux/tick.h>
66997+#include <linux/grsecurity.h>
66998
66999 #ifndef arch_irq_stat_cpu
67000 #define arch_irq_stat_cpu(cpu) 0
67001@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
67002 u64 sum_softirq = 0;
67003 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
67004 struct timespec boottime;
67005+ int unrestricted = 1;
67006+
67007+#ifdef CONFIG_GRKERNSEC_PROC_ADD
67008+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67009+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
67010+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
67011+ && !in_group_p(grsec_proc_gid)
67012+#endif
67013+ )
67014+ unrestricted = 0;
67015+#endif
67016+#endif
67017
67018 user = nice = system = idle = iowait =
67019 irq = softirq = steal = 0;
67020@@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
67021 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67022 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67023 idle += get_idle_time(i);
67024- iowait += get_iowait_time(i);
67025- irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67026- softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67027- steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67028- guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67029- guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67030- sum += kstat_cpu_irqs_sum(i);
67031- sum += arch_irq_stat_cpu(i);
67032+ if (unrestricted) {
67033+ iowait += get_iowait_time(i);
67034+ irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67035+ softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67036+ steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67037+ guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67038+ guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67039+ sum += kstat_cpu_irqs_sum(i);
67040+ sum += arch_irq_stat_cpu(i);
67041+ for (j = 0; j < NR_SOFTIRQS; j++) {
67042+ unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67043
67044- for (j = 0; j < NR_SOFTIRQS; j++) {
67045- unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
67046-
67047- per_softirq_sums[j] += softirq_stat;
67048- sum_softirq += softirq_stat;
67049+ per_softirq_sums[j] += softirq_stat;
67050+ sum_softirq += softirq_stat;
67051+ }
67052 }
67053 }
67054- sum += arch_irq_stat();
67055+ if (unrestricted)
67056+ sum += arch_irq_stat();
67057
67058 seq_puts(p, "cpu ");
67059 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67060@@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
67061 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
67062 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
67063 idle = get_idle_time(i);
67064- iowait = get_iowait_time(i);
67065- irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67066- softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67067- steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67068- guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67069- guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67070+ if (unrestricted) {
67071+ iowait = get_iowait_time(i);
67072+ irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
67073+ softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
67074+ steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
67075+ guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
67076+ guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
67077+ }
67078 seq_printf(p, "cpu%d", i);
67079 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
67080 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
67081@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
67082
67083 /* sum again ? it could be updated? */
67084 for_each_irq_nr(j)
67085- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
67086+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
67087
67088 seq_printf(p,
67089 "\nctxt %llu\n"
67090@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
67091 "processes %lu\n"
67092 "procs_running %lu\n"
67093 "procs_blocked %lu\n",
67094- nr_context_switches(),
67095+ unrestricted ? nr_context_switches() : 0ULL,
67096 (unsigned long)jif,
67097- total_forks,
67098- nr_running(),
67099- nr_iowait());
67100+ unrestricted ? total_forks : 0UL,
67101+ unrestricted ? nr_running() : 0UL,
67102+ unrestricted ? nr_iowait() : 0UL);
67103
67104 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
67105
67106diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
67107index c341568..75852a2 100644
67108--- a/fs/proc/task_mmu.c
67109+++ b/fs/proc/task_mmu.c
67110@@ -13,12 +13,19 @@
67111 #include <linux/swap.h>
67112 #include <linux/swapops.h>
67113 #include <linux/mmu_notifier.h>
67114+#include <linux/grsecurity.h>
67115
67116 #include <asm/elf.h>
67117 #include <asm/uaccess.h>
67118 #include <asm/tlbflush.h>
67119 #include "internal.h"
67120
67121+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67122+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
67123+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
67124+ _mm->pax_flags & MF_PAX_SEGMEXEC))
67125+#endif
67126+
67127 void task_mem(struct seq_file *m, struct mm_struct *mm)
67128 {
67129 unsigned long data, text, lib, swap;
67130@@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67131 "VmExe:\t%8lu kB\n"
67132 "VmLib:\t%8lu kB\n"
67133 "VmPTE:\t%8lu kB\n"
67134- "VmSwap:\t%8lu kB\n",
67135- hiwater_vm << (PAGE_SHIFT-10),
67136+ "VmSwap:\t%8lu kB\n"
67137+
67138+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67139+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
67140+#endif
67141+
67142+ ,hiwater_vm << (PAGE_SHIFT-10),
67143 total_vm << (PAGE_SHIFT-10),
67144 mm->locked_vm << (PAGE_SHIFT-10),
67145 mm->pinned_vm << (PAGE_SHIFT-10),
67146@@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67147 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
67148 (PTRS_PER_PTE * sizeof(pte_t) *
67149 atomic_long_read(&mm->nr_ptes)) >> 10,
67150- swap << (PAGE_SHIFT-10));
67151+ swap << (PAGE_SHIFT-10)
67152+
67153+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
67154+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67155+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
67156+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
67157+#else
67158+ , mm->context.user_cs_base
67159+ , mm->context.user_cs_limit
67160+#endif
67161+#endif
67162+
67163+ );
67164 }
67165
67166 unsigned long task_vsize(struct mm_struct *mm)
67167@@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67168 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
67169 }
67170
67171- /* We don't show the stack guard page in /proc/maps */
67172+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67173+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
67174+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
67175+#else
67176 start = vma->vm_start;
67177- if (stack_guard_page_start(vma, start))
67178- start += PAGE_SIZE;
67179 end = vma->vm_end;
67180- if (stack_guard_page_end(vma, end))
67181- end -= PAGE_SIZE;
67182+#endif
67183
67184 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
67185 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
67186@@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67187 flags & VM_WRITE ? 'w' : '-',
67188 flags & VM_EXEC ? 'x' : '-',
67189 flags & VM_MAYSHARE ? 's' : 'p',
67190+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67191+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
67192+#else
67193 pgoff,
67194+#endif
67195 MAJOR(dev), MINOR(dev), ino);
67196
67197 /*
67198@@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67199 */
67200 if (file) {
67201 seq_pad(m, ' ');
67202- seq_path(m, &file->f_path, "\n");
67203+ seq_path(m, &file->f_path, "\n\\");
67204 goto done;
67205 }
67206
67207@@ -328,8 +356,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
67208 * Thread stack in /proc/PID/task/TID/maps or
67209 * the main process stack.
67210 */
67211- if (!is_pid || (vma->vm_start <= mm->start_stack &&
67212- vma->vm_end >= mm->start_stack)) {
67213+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
67214+ (vma->vm_start <= mm->start_stack &&
67215+ vma->vm_end >= mm->start_stack)) {
67216 name = "[stack]";
67217 } else {
67218 /* Thread stack in /proc/PID/maps */
67219@@ -353,6 +382,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
67220 struct proc_maps_private *priv = m->private;
67221 struct task_struct *task = priv->task;
67222
67223+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67224+ if (current->exec_id != m->exec_id) {
67225+ gr_log_badprocpid("maps");
67226+ return 0;
67227+ }
67228+#endif
67229+
67230 show_map_vma(m, vma, is_pid);
67231
67232 if (m->count < m->size) /* vma is copied successfully */
67233@@ -593,12 +629,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67234 .private = &mss,
67235 };
67236
67237+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67238+ if (current->exec_id != m->exec_id) {
67239+ gr_log_badprocpid("smaps");
67240+ return 0;
67241+ }
67242+#endif
67243 memset(&mss, 0, sizeof mss);
67244- mss.vma = vma;
67245- /* mmap_sem is held in m_start */
67246- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67247- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67248-
67249+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67250+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
67251+#endif
67252+ mss.vma = vma;
67253+ /* mmap_sem is held in m_start */
67254+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
67255+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
67256+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67257+ }
67258+#endif
67259 show_map_vma(m, vma, is_pid);
67260
67261 seq_printf(m,
67262@@ -616,7 +663,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
67263 "KernelPageSize: %8lu kB\n"
67264 "MMUPageSize: %8lu kB\n"
67265 "Locked: %8lu kB\n",
67266+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67267+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
67268+#else
67269 (vma->vm_end - vma->vm_start) >> 10,
67270+#endif
67271 mss.resident >> 10,
67272 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
67273 mss.shared_clean >> 10,
67274@@ -1422,6 +1473,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67275 char buffer[64];
67276 int nid;
67277
67278+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67279+ if (current->exec_id != m->exec_id) {
67280+ gr_log_badprocpid("numa_maps");
67281+ return 0;
67282+ }
67283+#endif
67284+
67285 if (!mm)
67286 return 0;
67287
67288@@ -1439,11 +1497,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
67289 mpol_to_str(buffer, sizeof(buffer), pol);
67290 mpol_cond_put(pol);
67291
67292+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67293+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
67294+#else
67295 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
67296+#endif
67297
67298 if (file) {
67299 seq_puts(m, " file=");
67300- seq_path(m, &file->f_path, "\n\t= ");
67301+ seq_path(m, &file->f_path, "\n\t\\= ");
67302 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
67303 seq_puts(m, " heap");
67304 } else {
67305diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
67306index 678455d..ebd3245 100644
67307--- a/fs/proc/task_nommu.c
67308+++ b/fs/proc/task_nommu.c
67309@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
67310 else
67311 bytes += kobjsize(mm);
67312
67313- if (current->fs && current->fs->users > 1)
67314+ if (current->fs && atomic_read(&current->fs->users) > 1)
67315 sbytes += kobjsize(current->fs);
67316 else
67317 bytes += kobjsize(current->fs);
67318@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
67319
67320 if (file) {
67321 seq_pad(m, ' ');
67322- seq_path(m, &file->f_path, "");
67323+ seq_path(m, &file->f_path, "\n\\");
67324 } else if (mm) {
67325 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
67326
67327diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
67328index a90d6d35..d08047c 100644
67329--- a/fs/proc/vmcore.c
67330+++ b/fs/proc/vmcore.c
67331@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
67332 nr_bytes = count;
67333
67334 /* If pfn is not ram, return zeros for sparse dump files */
67335- if (pfn_is_ram(pfn) == 0)
67336- memset(buf, 0, nr_bytes);
67337- else {
67338+ if (pfn_is_ram(pfn) == 0) {
67339+ if (userbuf) {
67340+ if (clear_user((char __force_user *)buf, nr_bytes))
67341+ return -EFAULT;
67342+ } else
67343+ memset(buf, 0, nr_bytes);
67344+ } else {
67345 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
67346 offset, userbuf);
67347 if (tmp < 0)
67348@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
67349 static int copy_to(void *target, void *src, size_t size, int userbuf)
67350 {
67351 if (userbuf) {
67352- if (copy_to_user((char __user *) target, src, size))
67353+ if (copy_to_user((char __force_user *) target, src, size))
67354 return -EFAULT;
67355 } else {
67356 memcpy(target, src, size);
67357@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67358 if (*fpos < m->offset + m->size) {
67359 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
67360 start = m->paddr + *fpos - m->offset;
67361- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
67362+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
67363 if (tmp < 0)
67364 return tmp;
67365 buflen -= tsz;
67366@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
67367 static ssize_t read_vmcore(struct file *file, char __user *buffer,
67368 size_t buflen, loff_t *fpos)
67369 {
67370- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
67371+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
67372 }
67373
67374 /*
67375diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
67376index d3fb2b6..43a8140 100644
67377--- a/fs/qnx6/qnx6.h
67378+++ b/fs/qnx6/qnx6.h
67379@@ -74,7 +74,7 @@ enum {
67380 BYTESEX_BE,
67381 };
67382
67383-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67384+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
67385 {
67386 if (sbi->s_bytesex == BYTESEX_LE)
67387 return le64_to_cpu((__force __le64)n);
67388@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
67389 return (__force __fs64)cpu_to_be64(n);
67390 }
67391
67392-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67393+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
67394 {
67395 if (sbi->s_bytesex == BYTESEX_LE)
67396 return le32_to_cpu((__force __le32)n);
67397diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
67398index bb2869f..d34ada8 100644
67399--- a/fs/quota/netlink.c
67400+++ b/fs/quota/netlink.c
67401@@ -44,7 +44,7 @@ static struct genl_family quota_genl_family = {
67402 void quota_send_warning(struct kqid qid, dev_t dev,
67403 const char warntype)
67404 {
67405- static atomic_t seq;
67406+ static atomic_unchecked_t seq;
67407 struct sk_buff *skb;
67408 void *msg_head;
67409 int ret;
67410@@ -60,7 +60,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
67411 "VFS: Not enough memory to send quota warning.\n");
67412 return;
67413 }
67414- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
67415+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
67416 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
67417 if (!msg_head) {
67418 printk(KERN_ERR
67419diff --git a/fs/read_write.c b/fs/read_write.c
67420index 009d854..16ce214 100644
67421--- a/fs/read_write.c
67422+++ b/fs/read_write.c
67423@@ -495,7 +495,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
67424
67425 old_fs = get_fs();
67426 set_fs(get_ds());
67427- p = (__force const char __user *)buf;
67428+ p = (const char __force_user *)buf;
67429 if (count > MAX_RW_COUNT)
67430 count = MAX_RW_COUNT;
67431 if (file->f_op->write)
67432diff --git a/fs/readdir.c b/fs/readdir.c
67433index 33fd922..e0d6094 100644
67434--- a/fs/readdir.c
67435+++ b/fs/readdir.c
67436@@ -18,6 +18,7 @@
67437 #include <linux/security.h>
67438 #include <linux/syscalls.h>
67439 #include <linux/unistd.h>
67440+#include <linux/namei.h>
67441
67442 #include <asm/uaccess.h>
67443
67444@@ -71,6 +72,7 @@ struct old_linux_dirent {
67445 struct readdir_callback {
67446 struct dir_context ctx;
67447 struct old_linux_dirent __user * dirent;
67448+ struct file * file;
67449 int result;
67450 };
67451
67452@@ -88,6 +90,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
67453 buf->result = -EOVERFLOW;
67454 return -EOVERFLOW;
67455 }
67456+
67457+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67458+ return 0;
67459+
67460 buf->result++;
67461 dirent = buf->dirent;
67462 if (!access_ok(VERIFY_WRITE, dirent,
67463@@ -119,6 +125,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
67464 if (!f.file)
67465 return -EBADF;
67466
67467+ buf.file = f.file;
67468 error = iterate_dir(f.file, &buf.ctx);
67469 if (buf.result)
67470 error = buf.result;
67471@@ -144,6 +151,7 @@ struct getdents_callback {
67472 struct dir_context ctx;
67473 struct linux_dirent __user * current_dir;
67474 struct linux_dirent __user * previous;
67475+ struct file * file;
67476 int count;
67477 int error;
67478 };
67479@@ -165,6 +173,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
67480 buf->error = -EOVERFLOW;
67481 return -EOVERFLOW;
67482 }
67483+
67484+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67485+ return 0;
67486+
67487 dirent = buf->previous;
67488 if (dirent) {
67489 if (__put_user(offset, &dirent->d_off))
67490@@ -210,6 +222,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
67491 if (!f.file)
67492 return -EBADF;
67493
67494+ buf.file = f.file;
67495 error = iterate_dir(f.file, &buf.ctx);
67496 if (error >= 0)
67497 error = buf.error;
67498@@ -228,6 +241,7 @@ struct getdents_callback64 {
67499 struct dir_context ctx;
67500 struct linux_dirent64 __user * current_dir;
67501 struct linux_dirent64 __user * previous;
67502+ struct file *file;
67503 int count;
67504 int error;
67505 };
67506@@ -243,6 +257,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
67507 buf->error = -EINVAL; /* only used if we fail.. */
67508 if (reclen > buf->count)
67509 return -EINVAL;
67510+
67511+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
67512+ return 0;
67513+
67514 dirent = buf->previous;
67515 if (dirent) {
67516 if (__put_user(offset, &dirent->d_off))
67517@@ -290,6 +308,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
67518 if (!f.file)
67519 return -EBADF;
67520
67521+ buf.file = f.file;
67522 error = iterate_dir(f.file, &buf.ctx);
67523 if (error >= 0)
67524 error = buf.error;
67525diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
67526index 9c02d96..6562c10 100644
67527--- a/fs/reiserfs/do_balan.c
67528+++ b/fs/reiserfs/do_balan.c
67529@@ -1887,7 +1887,7 @@ void do_balance(struct tree_balance *tb, struct item_head *ih,
67530 return;
67531 }
67532
67533- atomic_inc(&fs_generation(tb->tb_sb));
67534+ atomic_inc_unchecked(&fs_generation(tb->tb_sb));
67535 do_balance_starts(tb);
67536
67537 /*
67538diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
67539index aca73dd..e3c558d 100644
67540--- a/fs/reiserfs/item_ops.c
67541+++ b/fs/reiserfs/item_ops.c
67542@@ -724,18 +724,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
67543 }
67544
67545 static struct item_operations errcatch_ops = {
67546- errcatch_bytes_number,
67547- errcatch_decrement_key,
67548- errcatch_is_left_mergeable,
67549- errcatch_print_item,
67550- errcatch_check_item,
67551+ .bytes_number = errcatch_bytes_number,
67552+ .decrement_key = errcatch_decrement_key,
67553+ .is_left_mergeable = errcatch_is_left_mergeable,
67554+ .print_item = errcatch_print_item,
67555+ .check_item = errcatch_check_item,
67556
67557- errcatch_create_vi,
67558- errcatch_check_left,
67559- errcatch_check_right,
67560- errcatch_part_size,
67561- errcatch_unit_num,
67562- errcatch_print_vi
67563+ .create_vi = errcatch_create_vi,
67564+ .check_left = errcatch_check_left,
67565+ .check_right = errcatch_check_right,
67566+ .part_size = errcatch_part_size,
67567+ .unit_num = errcatch_unit_num,
67568+ .print_vi = errcatch_print_vi
67569 };
67570
67571 #if ! (TYPE_STAT_DATA == 0 && TYPE_INDIRECT == 1 && TYPE_DIRECT == 2 && TYPE_DIRENTRY == 3)
67572diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
67573index 621b9f3..af527fd 100644
67574--- a/fs/reiserfs/procfs.c
67575+++ b/fs/reiserfs/procfs.c
67576@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
67577 "SMALL_TAILS " : "NO_TAILS ",
67578 replay_only(sb) ? "REPLAY_ONLY " : "",
67579 convert_reiserfs(sb) ? "CONV " : "",
67580- atomic_read(&r->s_generation_counter),
67581+ atomic_read_unchecked(&r->s_generation_counter),
67582 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
67583 SF(s_do_balance), SF(s_unneeded_left_neighbor),
67584 SF(s_good_search_by_key_reada), SF(s_bmaps),
67585diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
67586index 735c2c2..81b91af 100644
67587--- a/fs/reiserfs/reiserfs.h
67588+++ b/fs/reiserfs/reiserfs.h
67589@@ -573,7 +573,7 @@ struct reiserfs_sb_info {
67590 /* Comment? -Hans */
67591 wait_queue_head_t s_wait;
67592 /* increased by one every time the tree gets re-balanced */
67593- atomic_t s_generation_counter;
67594+ atomic_unchecked_t s_generation_counter;
67595
67596 /* File system properties. Currently holds on-disk FS format */
67597 unsigned long s_properties;
67598@@ -2294,7 +2294,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
67599 #define REISERFS_USER_MEM 1 /* user memory mode */
67600
67601 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
67602-#define get_generation(s) atomic_read (&fs_generation(s))
67603+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
67604 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
67605 #define __fs_changed(gen,s) (gen != get_generation (s))
67606 #define fs_changed(gen,s) \
67607diff --git a/fs/select.c b/fs/select.c
67608index 467bb1c..cf9d65a 100644
67609--- a/fs/select.c
67610+++ b/fs/select.c
67611@@ -20,6 +20,7 @@
67612 #include <linux/export.h>
67613 #include <linux/slab.h>
67614 #include <linux/poll.h>
67615+#include <linux/security.h>
67616 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
67617 #include <linux/file.h>
67618 #include <linux/fdtable.h>
67619@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
67620 struct poll_list *walk = head;
67621 unsigned long todo = nfds;
67622
67623+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
67624 if (nfds > rlimit(RLIMIT_NOFILE))
67625 return -EINVAL;
67626
67627diff --git a/fs/seq_file.c b/fs/seq_file.c
67628index 3857b72..0b7281e 100644
67629--- a/fs/seq_file.c
67630+++ b/fs/seq_file.c
67631@@ -12,6 +12,8 @@
67632 #include <linux/slab.h>
67633 #include <linux/cred.h>
67634 #include <linux/mm.h>
67635+#include <linux/sched.h>
67636+#include <linux/grsecurity.h>
67637
67638 #include <asm/uaccess.h>
67639 #include <asm/page.h>
67640@@ -34,12 +36,7 @@ static void seq_set_overflow(struct seq_file *m)
67641
67642 static void *seq_buf_alloc(unsigned long size)
67643 {
67644- void *buf;
67645-
67646- buf = kmalloc(size, GFP_KERNEL | __GFP_NOWARN);
67647- if (!buf && size > PAGE_SIZE)
67648- buf = vmalloc(size);
67649- return buf;
67650+ return kmalloc(size, GFP_KERNEL | GFP_USERCOPY);
67651 }
67652
67653 /**
67654@@ -72,6 +69,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
67655 #ifdef CONFIG_USER_NS
67656 p->user_ns = file->f_cred->user_ns;
67657 #endif
67658+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
67659+ p->exec_id = current->exec_id;
67660+#endif
67661
67662 /*
67663 * Wrappers around seq_open(e.g. swaps_open) need to be
67664@@ -94,6 +94,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
67665 }
67666 EXPORT_SYMBOL(seq_open);
67667
67668+
67669+int seq_open_restrict(struct file *file, const struct seq_operations *op)
67670+{
67671+ if (gr_proc_is_restricted())
67672+ return -EACCES;
67673+
67674+ return seq_open(file, op);
67675+}
67676+EXPORT_SYMBOL(seq_open_restrict);
67677+
67678 static int traverse(struct seq_file *m, loff_t offset)
67679 {
67680 loff_t pos = 0, index;
67681@@ -165,7 +175,7 @@ Eoverflow:
67682 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
67683 {
67684 struct seq_file *m = file->private_data;
67685- size_t copied = 0;
67686+ ssize_t copied = 0;
67687 loff_t pos;
67688 size_t n;
67689 void *p;
67690@@ -596,7 +606,7 @@ static void single_stop(struct seq_file *p, void *v)
67691 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
67692 void *data)
67693 {
67694- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
67695+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
67696 int res = -ENOMEM;
67697
67698 if (op) {
67699@@ -632,6 +642,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
67700 }
67701 EXPORT_SYMBOL(single_open_size);
67702
67703+int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
67704+ void *data)
67705+{
67706+ if (gr_proc_is_restricted())
67707+ return -EACCES;
67708+
67709+ return single_open(file, show, data);
67710+}
67711+EXPORT_SYMBOL(single_open_restrict);
67712+
67713+
67714 int single_release(struct inode *inode, struct file *file)
67715 {
67716 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
67717diff --git a/fs/splice.c b/fs/splice.c
67718index f5cb9ba..8ddb1e9 100644
67719--- a/fs/splice.c
67720+++ b/fs/splice.c
67721@@ -193,7 +193,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67722 pipe_lock(pipe);
67723
67724 for (;;) {
67725- if (!pipe->readers) {
67726+ if (!atomic_read(&pipe->readers)) {
67727 send_sig(SIGPIPE, current, 0);
67728 if (!ret)
67729 ret = -EPIPE;
67730@@ -216,7 +216,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67731 page_nr++;
67732 ret += buf->len;
67733
67734- if (pipe->files)
67735+ if (atomic_read(&pipe->files))
67736 do_wakeup = 1;
67737
67738 if (!--spd->nr_pages)
67739@@ -247,9 +247,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
67740 do_wakeup = 0;
67741 }
67742
67743- pipe->waiting_writers++;
67744+ atomic_inc(&pipe->waiting_writers);
67745 pipe_wait(pipe);
67746- pipe->waiting_writers--;
67747+ atomic_dec(&pipe->waiting_writers);
67748 }
67749
67750 pipe_unlock(pipe);
67751@@ -576,7 +576,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
67752 old_fs = get_fs();
67753 set_fs(get_ds());
67754 /* The cast to a user pointer is valid due to the set_fs() */
67755- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
67756+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
67757 set_fs(old_fs);
67758
67759 return res;
67760@@ -591,7 +591,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
67761 old_fs = get_fs();
67762 set_fs(get_ds());
67763 /* The cast to a user pointer is valid due to the set_fs() */
67764- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
67765+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
67766 set_fs(old_fs);
67767
67768 return res;
67769@@ -644,7 +644,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
67770 goto err;
67771
67772 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
67773- vec[i].iov_base = (void __user *) page_address(page);
67774+ vec[i].iov_base = (void __force_user *) page_address(page);
67775 vec[i].iov_len = this_len;
67776 spd.pages[i] = page;
67777 spd.nr_pages++;
67778@@ -783,7 +783,7 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67779 ops->release(pipe, buf);
67780 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67781 pipe->nrbufs--;
67782- if (pipe->files)
67783+ if (atomic_read(&pipe->files))
67784 sd->need_wakeup = true;
67785 }
67786
67787@@ -807,10 +807,10 @@ static int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_des
67788 static int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
67789 {
67790 while (!pipe->nrbufs) {
67791- if (!pipe->writers)
67792+ if (!atomic_read(&pipe->writers))
67793 return 0;
67794
67795- if (!pipe->waiting_writers && sd->num_spliced)
67796+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
67797 return 0;
67798
67799 if (sd->flags & SPLICE_F_NONBLOCK)
67800@@ -1040,7 +1040,7 @@ iter_file_splice_write(struct pipe_inode_info *pipe, struct file *out,
67801 ops->release(pipe, buf);
67802 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
67803 pipe->nrbufs--;
67804- if (pipe->files)
67805+ if (atomic_read(&pipe->files))
67806 sd.need_wakeup = true;
67807 } else {
67808 buf->offset += ret;
67809@@ -1200,7 +1200,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
67810 * out of the pipe right after the splice_to_pipe(). So set
67811 * PIPE_READERS appropriately.
67812 */
67813- pipe->readers = 1;
67814+ atomic_set(&pipe->readers, 1);
67815
67816 current->splice_pipe = pipe;
67817 }
67818@@ -1496,6 +1496,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
67819
67820 partial[buffers].offset = off;
67821 partial[buffers].len = plen;
67822+ partial[buffers].private = 0;
67823
67824 off = 0;
67825 len -= plen;
67826@@ -1732,9 +1733,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67827 ret = -ERESTARTSYS;
67828 break;
67829 }
67830- if (!pipe->writers)
67831+ if (!atomic_read(&pipe->writers))
67832 break;
67833- if (!pipe->waiting_writers) {
67834+ if (!atomic_read(&pipe->waiting_writers)) {
67835 if (flags & SPLICE_F_NONBLOCK) {
67836 ret = -EAGAIN;
67837 break;
67838@@ -1766,7 +1767,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67839 pipe_lock(pipe);
67840
67841 while (pipe->nrbufs >= pipe->buffers) {
67842- if (!pipe->readers) {
67843+ if (!atomic_read(&pipe->readers)) {
67844 send_sig(SIGPIPE, current, 0);
67845 ret = -EPIPE;
67846 break;
67847@@ -1779,9 +1780,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
67848 ret = -ERESTARTSYS;
67849 break;
67850 }
67851- pipe->waiting_writers++;
67852+ atomic_inc(&pipe->waiting_writers);
67853 pipe_wait(pipe);
67854- pipe->waiting_writers--;
67855+ atomic_dec(&pipe->waiting_writers);
67856 }
67857
67858 pipe_unlock(pipe);
67859@@ -1817,14 +1818,14 @@ retry:
67860 pipe_double_lock(ipipe, opipe);
67861
67862 do {
67863- if (!opipe->readers) {
67864+ if (!atomic_read(&opipe->readers)) {
67865 send_sig(SIGPIPE, current, 0);
67866 if (!ret)
67867 ret = -EPIPE;
67868 break;
67869 }
67870
67871- if (!ipipe->nrbufs && !ipipe->writers)
67872+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
67873 break;
67874
67875 /*
67876@@ -1921,7 +1922,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67877 pipe_double_lock(ipipe, opipe);
67878
67879 do {
67880- if (!opipe->readers) {
67881+ if (!atomic_read(&opipe->readers)) {
67882 send_sig(SIGPIPE, current, 0);
67883 if (!ret)
67884 ret = -EPIPE;
67885@@ -1966,7 +1967,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
67886 * return EAGAIN if we have the potential of some data in the
67887 * future, otherwise just return 0
67888 */
67889- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
67890+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
67891 ret = -EAGAIN;
67892
67893 pipe_unlock(ipipe);
67894diff --git a/fs/stat.c b/fs/stat.c
67895index ae0c3ce..9ee641c 100644
67896--- a/fs/stat.c
67897+++ b/fs/stat.c
67898@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
67899 stat->gid = inode->i_gid;
67900 stat->rdev = inode->i_rdev;
67901 stat->size = i_size_read(inode);
67902- stat->atime = inode->i_atime;
67903- stat->mtime = inode->i_mtime;
67904+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67905+ stat->atime = inode->i_ctime;
67906+ stat->mtime = inode->i_ctime;
67907+ } else {
67908+ stat->atime = inode->i_atime;
67909+ stat->mtime = inode->i_mtime;
67910+ }
67911 stat->ctime = inode->i_ctime;
67912 stat->blksize = (1 << inode->i_blkbits);
67913 stat->blocks = inode->i_blocks;
67914@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
67915 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
67916 {
67917 struct inode *inode = path->dentry->d_inode;
67918+ int retval;
67919
67920- if (inode->i_op->getattr)
67921- return inode->i_op->getattr(path->mnt, path->dentry, stat);
67922+ if (inode->i_op->getattr) {
67923+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
67924+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
67925+ stat->atime = stat->ctime;
67926+ stat->mtime = stat->ctime;
67927+ }
67928+ return retval;
67929+ }
67930
67931 generic_fillattr(inode, stat);
67932 return 0;
67933diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
67934index 0b45ff4..847de5b 100644
67935--- a/fs/sysfs/dir.c
67936+++ b/fs/sysfs/dir.c
67937@@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
67938 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67939 {
67940 struct kernfs_node *parent, *kn;
67941+ const char *name;
67942+ umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
67943+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67944+ const char *parent_name;
67945+#endif
67946
67947 BUG_ON(!kobj);
67948
67949+ name = kobject_name(kobj);
67950+
67951 if (kobj->parent)
67952 parent = kobj->parent->sd;
67953 else
67954@@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
67955 if (!parent)
67956 return -ENOENT;
67957
67958- kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
67959- S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
67960+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
67961+ parent_name = parent->name;
67962+ mode = S_IRWXU;
67963+
67964+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
67965+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
67966+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
67967+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
67968+ mode = S_IRWXU | S_IRUGO | S_IXUGO;
67969+#endif
67970+
67971+ kn = kernfs_create_dir_ns(parent, name,
67972+ mode, kobj, ns);
67973 if (IS_ERR(kn)) {
67974 if (PTR_ERR(kn) == -EEXIST)
67975- sysfs_warn_dup(parent, kobject_name(kobj));
67976+ sysfs_warn_dup(parent, name);
67977 return PTR_ERR(kn);
67978 }
67979
67980diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
67981index 69d4889..a810bd4 100644
67982--- a/fs/sysv/sysv.h
67983+++ b/fs/sysv/sysv.h
67984@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
67985 #endif
67986 }
67987
67988-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
67989+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
67990 {
67991 if (sbi->s_bytesex == BYTESEX_PDP)
67992 return PDP_swab((__force __u32)n);
67993diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
67994index fb08b0c..65fcc7e 100644
67995--- a/fs/ubifs/io.c
67996+++ b/fs/ubifs/io.c
67997@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
67998 return err;
67999 }
68000
68001-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68002+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
68003 {
68004 int err;
68005
68006diff --git a/fs/udf/misc.c b/fs/udf/misc.c
68007index c175b4d..8f36a16 100644
68008--- a/fs/udf/misc.c
68009+++ b/fs/udf/misc.c
68010@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
68011
68012 u8 udf_tag_checksum(const struct tag *t)
68013 {
68014- u8 *data = (u8 *)t;
68015+ const u8 *data = (const u8 *)t;
68016 u8 checksum = 0;
68017 int i;
68018 for (i = 0; i < sizeof(struct tag); ++i)
68019diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
68020index 8d974c4..b82f6ec 100644
68021--- a/fs/ufs/swab.h
68022+++ b/fs/ufs/swab.h
68023@@ -22,7 +22,7 @@ enum {
68024 BYTESEX_BE
68025 };
68026
68027-static inline u64
68028+static inline u64 __intentional_overflow(-1)
68029 fs64_to_cpu(struct super_block *sbp, __fs64 n)
68030 {
68031 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68032@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
68033 return (__force __fs64)cpu_to_be64(n);
68034 }
68035
68036-static inline u32
68037+static inline u32 __intentional_overflow(-1)
68038 fs32_to_cpu(struct super_block *sbp, __fs32 n)
68039 {
68040 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
68041diff --git a/fs/utimes.c b/fs/utimes.c
68042index aa138d6..5f3a811 100644
68043--- a/fs/utimes.c
68044+++ b/fs/utimes.c
68045@@ -1,6 +1,7 @@
68046 #include <linux/compiler.h>
68047 #include <linux/file.h>
68048 #include <linux/fs.h>
68049+#include <linux/security.h>
68050 #include <linux/linkage.h>
68051 #include <linux/mount.h>
68052 #include <linux/namei.h>
68053@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
68054 }
68055 }
68056 retry_deleg:
68057+
68058+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
68059+ error = -EACCES;
68060+ goto mnt_drop_write_and_out;
68061+ }
68062+
68063 mutex_lock(&inode->i_mutex);
68064 error = notify_change(path->dentry, &newattrs, &delegated_inode);
68065 mutex_unlock(&inode->i_mutex);
68066diff --git a/fs/xattr.c b/fs/xattr.c
68067index c69e6d4..cc56af5 100644
68068--- a/fs/xattr.c
68069+++ b/fs/xattr.c
68070@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
68071 return rc;
68072 }
68073
68074+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
68075+ssize_t
68076+pax_getxattr(struct dentry *dentry, void *value, size_t size)
68077+{
68078+ struct inode *inode = dentry->d_inode;
68079+ ssize_t error;
68080+
68081+ error = inode_permission(inode, MAY_EXEC);
68082+ if (error)
68083+ return error;
68084+
68085+ if (inode->i_op->getxattr)
68086+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
68087+ else
68088+ error = -EOPNOTSUPP;
68089+
68090+ return error;
68091+}
68092+EXPORT_SYMBOL(pax_getxattr);
68093+#endif
68094+
68095 ssize_t
68096 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
68097 {
68098@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
68099 * Extended attribute SET operations
68100 */
68101 static long
68102-setxattr(struct dentry *d, const char __user *name, const void __user *value,
68103+setxattr(struct path *path, const char __user *name, const void __user *value,
68104 size_t size, int flags)
68105 {
68106 int error;
68107@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
68108 posix_acl_fix_xattr_from_user(kvalue, size);
68109 }
68110
68111- error = vfs_setxattr(d, kname, kvalue, size, flags);
68112+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
68113+ error = -EACCES;
68114+ goto out;
68115+ }
68116+
68117+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
68118 out:
68119 if (vvalue)
68120 vfree(vvalue);
68121@@ -377,7 +403,7 @@ retry:
68122 return error;
68123 error = mnt_want_write(path.mnt);
68124 if (!error) {
68125- error = setxattr(path.dentry, name, value, size, flags);
68126+ error = setxattr(&path, name, value, size, flags);
68127 mnt_drop_write(path.mnt);
68128 }
68129 path_put(&path);
68130@@ -401,7 +427,7 @@ retry:
68131 return error;
68132 error = mnt_want_write(path.mnt);
68133 if (!error) {
68134- error = setxattr(path.dentry, name, value, size, flags);
68135+ error = setxattr(&path, name, value, size, flags);
68136 mnt_drop_write(path.mnt);
68137 }
68138 path_put(&path);
68139@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
68140 const void __user *,value, size_t, size, int, flags)
68141 {
68142 struct fd f = fdget(fd);
68143- struct dentry *dentry;
68144 int error = -EBADF;
68145
68146 if (!f.file)
68147 return error;
68148- dentry = f.file->f_path.dentry;
68149- audit_inode(NULL, dentry, 0);
68150+ audit_inode(NULL, f.file->f_path.dentry, 0);
68151 error = mnt_want_write_file(f.file);
68152 if (!error) {
68153- error = setxattr(dentry, name, value, size, flags);
68154+ error = setxattr(&f.file->f_path, name, value, size, flags);
68155 mnt_drop_write_file(f.file);
68156 }
68157 fdput(f);
68158@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
68159 * Extended attribute REMOVE operations
68160 */
68161 static long
68162-removexattr(struct dentry *d, const char __user *name)
68163+removexattr(struct path *path, const char __user *name)
68164 {
68165 int error;
68166 char kname[XATTR_NAME_MAX + 1];
68167@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
68168 if (error < 0)
68169 return error;
68170
68171- return vfs_removexattr(d, kname);
68172+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
68173+ return -EACCES;
68174+
68175+ return vfs_removexattr(path->dentry, kname);
68176 }
68177
68178 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
68179@@ -652,7 +679,7 @@ retry:
68180 return error;
68181 error = mnt_want_write(path.mnt);
68182 if (!error) {
68183- error = removexattr(path.dentry, name);
68184+ error = removexattr(&path, name);
68185 mnt_drop_write(path.mnt);
68186 }
68187 path_put(&path);
68188@@ -675,7 +702,7 @@ retry:
68189 return error;
68190 error = mnt_want_write(path.mnt);
68191 if (!error) {
68192- error = removexattr(path.dentry, name);
68193+ error = removexattr(&path, name);
68194 mnt_drop_write(path.mnt);
68195 }
68196 path_put(&path);
68197@@ -689,16 +716,16 @@ retry:
68198 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
68199 {
68200 struct fd f = fdget(fd);
68201- struct dentry *dentry;
68202+ struct path *path;
68203 int error = -EBADF;
68204
68205 if (!f.file)
68206 return error;
68207- dentry = f.file->f_path.dentry;
68208- audit_inode(NULL, dentry, 0);
68209+ path = &f.file->f_path;
68210+ audit_inode(NULL, path->dentry, 0);
68211 error = mnt_want_write_file(f.file);
68212 if (!error) {
68213- error = removexattr(dentry, name);
68214+ error = removexattr(path, name);
68215 mnt_drop_write_file(f.file);
68216 }
68217 fdput(f);
68218diff --git a/fs/xfs/libxfs/xfs_bmap.c b/fs/xfs/libxfs/xfs_bmap.c
68219index 86df952..ac430d6 100644
68220--- a/fs/xfs/libxfs/xfs_bmap.c
68221+++ b/fs/xfs/libxfs/xfs_bmap.c
68222@@ -583,7 +583,7 @@ xfs_bmap_validate_ret(
68223
68224 #else
68225 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
68226-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
68227+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
68228 #endif /* DEBUG */
68229
68230 /*
68231diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
68232index f1b69ed..3d0222f 100644
68233--- a/fs/xfs/xfs_dir2_readdir.c
68234+++ b/fs/xfs/xfs_dir2_readdir.c
68235@@ -159,7 +159,12 @@ xfs_dir2_sf_getdents(
68236 ino = dp->d_ops->sf_get_ino(sfp, sfep);
68237 filetype = dp->d_ops->sf_get_ftype(sfep);
68238 ctx->pos = off & 0x7fffffff;
68239- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68240+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
68241+ char name[sfep->namelen];
68242+ memcpy(name, sfep->name, sfep->namelen);
68243+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(dp->i_mount, filetype)))
68244+ return 0;
68245+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
68246 xfs_dir3_get_dtype(dp->i_mount, filetype)))
68247 return 0;
68248 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
68249diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
68250index 3799695..0ddc953 100644
68251--- a/fs/xfs/xfs_ioctl.c
68252+++ b/fs/xfs/xfs_ioctl.c
68253@@ -122,7 +122,7 @@ xfs_find_handle(
68254 }
68255
68256 error = -EFAULT;
68257- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
68258+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
68259 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
68260 goto out_put;
68261
68262diff --git a/fs/xfs/xfs_linux.h b/fs/xfs/xfs_linux.h
68263index d10dc8f..56b3430 100644
68264--- a/fs/xfs/xfs_linux.h
68265+++ b/fs/xfs/xfs_linux.h
68266@@ -230,7 +230,7 @@ static inline kgid_t xfs_gid_to_kgid(__uint32_t gid)
68267 * of the compiler which do not like us using do_div in the middle
68268 * of large functions.
68269 */
68270-static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68271+static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68272 {
68273 __u32 mod;
68274
68275@@ -286,7 +286,7 @@ static inline __u32 xfs_do_mod(void *a, __u32 b, int n)
68276 return 0;
68277 }
68278 #else
68279-static inline __u32 xfs_do_div(void *a, __u32 b, int n)
68280+static inline __u32 __intentional_overflow(-1) xfs_do_div(void *a, __u32 b, int n)
68281 {
68282 __u32 mod;
68283
68284diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
68285new file mode 100644
68286index 0000000..f27264e
68287--- /dev/null
68288+++ b/grsecurity/Kconfig
68289@@ -0,0 +1,1166 @@
68290+#
68291+# grecurity configuration
68292+#
68293+menu "Memory Protections"
68294+depends on GRKERNSEC
68295+
68296+config GRKERNSEC_KMEM
68297+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
68298+ default y if GRKERNSEC_CONFIG_AUTO
68299+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
68300+ help
68301+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
68302+ be written to or read from to modify or leak the contents of the running
68303+ kernel. /dev/port will also not be allowed to be opened, writing to
68304+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
68305+ If you have module support disabled, enabling this will close up several
68306+ ways that are currently used to insert malicious code into the running
68307+ kernel.
68308+
68309+ Even with this feature enabled, we still highly recommend that
68310+ you use the RBAC system, as it is still possible for an attacker to
68311+ modify the running kernel through other more obscure methods.
68312+
68313+ It is highly recommended that you say Y here if you meet all the
68314+ conditions above.
68315+
68316+config GRKERNSEC_VM86
68317+ bool "Restrict VM86 mode"
68318+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68319+ depends on X86_32
68320+
68321+ help
68322+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
68323+ make use of a special execution mode on 32bit x86 processors called
68324+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
68325+ video cards and will still work with this option enabled. The purpose
68326+ of the option is to prevent exploitation of emulation errors in
68327+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
68328+ Nearly all users should be able to enable this option.
68329+
68330+config GRKERNSEC_IO
68331+ bool "Disable privileged I/O"
68332+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68333+ depends on X86
68334+ select RTC_CLASS
68335+ select RTC_INTF_DEV
68336+ select RTC_DRV_CMOS
68337+
68338+ help
68339+ If you say Y here, all ioperm and iopl calls will return an error.
68340+ Ioperm and iopl can be used to modify the running kernel.
68341+ Unfortunately, some programs need this access to operate properly,
68342+ the most notable of which are XFree86 and hwclock. hwclock can be
68343+ remedied by having RTC support in the kernel, so real-time
68344+ clock support is enabled if this option is enabled, to ensure
68345+ that hwclock operates correctly. If hwclock still does not work,
68346+ either update udev or symlink /dev/rtc to /dev/rtc0.
68347+
68348+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
68349+ you may not be able to boot into a graphical environment with this
68350+ option enabled. In this case, you should use the RBAC system instead.
68351+
68352+config GRKERNSEC_BPF_HARDEN
68353+ bool "Harden BPF interpreter"
68354+ default y if GRKERNSEC_CONFIG_AUTO
68355+ help
68356+ Unlike previous versions of grsecurity that hardened both the BPF
68357+ interpreted code against corruption at rest as well as the JIT code
68358+ against JIT-spray attacks and attacker-controlled immediate values
68359+ for ROP, this feature will enforce disabling of the new eBPF JIT engine
68360+ and will ensure the interpreted code is read-only at rest. This feature
68361+ may be removed at a later time when eBPF stabilizes to entirely revert
68362+ back to the more secure pre-3.16 BPF interpreter/JIT.
68363+
68364+ If you're using KERNEXEC, it's recommended that you enable this option
68365+ to supplement the hardening of the kernel.
68366+
68367+config GRKERNSEC_PERF_HARDEN
68368+ bool "Disable unprivileged PERF_EVENTS usage by default"
68369+ default y if GRKERNSEC_CONFIG_AUTO
68370+ depends on PERF_EVENTS
68371+ help
68372+ If you say Y here, the range of acceptable values for the
68373+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
68374+ default to a new value: 3. When the sysctl is set to this value, no
68375+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
68376+
68377+ Though PERF_EVENTS can be used legitimately for performance monitoring
68378+ and low-level application profiling, it is forced on regardless of
68379+ configuration, has been at fault for several vulnerabilities, and
68380+ creates new opportunities for side channels and other information leaks.
68381+
68382+ This feature puts PERF_EVENTS into a secure default state and permits
68383+ the administrator to change out of it temporarily if unprivileged
68384+ application profiling is needed.
68385+
68386+config GRKERNSEC_RAND_THREADSTACK
68387+ bool "Insert random gaps between thread stacks"
68388+ default y if GRKERNSEC_CONFIG_AUTO
68389+ depends on PAX_RANDMMAP && !PPC
68390+ help
68391+ If you say Y here, a random-sized gap will be enforced between allocated
68392+ thread stacks. Glibc's NPTL and other threading libraries that
68393+ pass MAP_STACK to the kernel for thread stack allocation are supported.
68394+ The implementation currently provides 8 bits of entropy for the gap.
68395+
68396+ Many distributions do not compile threaded remote services with the
68397+ -fstack-check argument to GCC, causing the variable-sized stack-based
68398+ allocator, alloca(), to not probe the stack on allocation. This
68399+ permits an unbounded alloca() to skip over any guard page and potentially
68400+ modify another thread's stack reliably. An enforced random gap
68401+ reduces the reliability of such an attack and increases the chance
68402+ that such a read/write to another thread's stack instead lands in
68403+ an unmapped area, causing a crash and triggering grsecurity's
68404+ anti-bruteforcing logic.
68405+
68406+config GRKERNSEC_PROC_MEMMAP
68407+ bool "Harden ASLR against information leaks and entropy reduction"
68408+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
68409+ depends on PAX_NOEXEC || PAX_ASLR
68410+ help
68411+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
68412+ give no information about the addresses of its mappings if
68413+ PaX features that rely on random addresses are enabled on the task.
68414+ In addition to sanitizing this information and disabling other
68415+ dangerous sources of information, this option causes reads of sensitive
68416+ /proc/<pid> entries where the file descriptor was opened in a different
68417+ task than the one performing the read. Such attempts are logged.
68418+ This option also limits argv/env strings for suid/sgid binaries
68419+ to 512KB to prevent a complete exhaustion of the stack entropy provided
68420+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
68421+ binaries to prevent alternative mmap layouts from being abused.
68422+
68423+ If you use PaX it is essential that you say Y here as it closes up
68424+ several holes that make full ASLR useless locally.
68425+
68426+
68427+config GRKERNSEC_KSTACKOVERFLOW
68428+ bool "Prevent kernel stack overflows"
68429+ default y if GRKERNSEC_CONFIG_AUTO
68430+ depends on !IA64 && 64BIT
68431+ help
68432+ If you say Y here, the kernel's process stacks will be allocated
68433+ with vmalloc instead of the kernel's default allocator. This
68434+ introduces guard pages that in combination with the alloca checking
68435+ of the STACKLEAK feature prevents all forms of kernel process stack
68436+ overflow abuse. Note that this is different from kernel stack
68437+ buffer overflows.
68438+
68439+config GRKERNSEC_BRUTE
68440+ bool "Deter exploit bruteforcing"
68441+ default y if GRKERNSEC_CONFIG_AUTO
68442+ help
68443+ If you say Y here, attempts to bruteforce exploits against forking
68444+ daemons such as apache or sshd, as well as against suid/sgid binaries
68445+ will be deterred. When a child of a forking daemon is killed by PaX
68446+ or crashes due to an illegal instruction or other suspicious signal,
68447+ the parent process will be delayed 30 seconds upon every subsequent
68448+ fork until the administrator is able to assess the situation and
68449+ restart the daemon.
68450+ In the suid/sgid case, the attempt is logged, the user has all their
68451+ existing instances of the suid/sgid binary terminated and will
68452+ be unable to execute any suid/sgid binaries for 15 minutes.
68453+
68454+ It is recommended that you also enable signal logging in the auditing
68455+ section so that logs are generated when a process triggers a suspicious
68456+ signal.
68457+ If the sysctl option is enabled, a sysctl option with name
68458+ "deter_bruteforce" is created.
68459+
68460+config GRKERNSEC_MODHARDEN
68461+ bool "Harden module auto-loading"
68462+ default y if GRKERNSEC_CONFIG_AUTO
68463+ depends on MODULES
68464+ help
68465+ If you say Y here, module auto-loading in response to use of some
68466+ feature implemented by an unloaded module will be restricted to
68467+ root users. Enabling this option helps defend against attacks
68468+ by unprivileged users who abuse the auto-loading behavior to
68469+ cause a vulnerable module to load that is then exploited.
68470+
68471+ If this option prevents a legitimate use of auto-loading for a
68472+ non-root user, the administrator can execute modprobe manually
68473+ with the exact name of the module mentioned in the alert log.
68474+ Alternatively, the administrator can add the module to the list
68475+ of modules loaded at boot by modifying init scripts.
68476+
68477+ Modification of init scripts will most likely be needed on
68478+ Ubuntu servers with encrypted home directory support enabled,
68479+ as the first non-root user logging in will cause the ecb(aes),
68480+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
68481+
68482+config GRKERNSEC_HIDESYM
68483+ bool "Hide kernel symbols"
68484+ default y if GRKERNSEC_CONFIG_AUTO
68485+ select PAX_USERCOPY_SLABS
68486+ help
68487+ If you say Y here, getting information on loaded modules, and
68488+ displaying all kernel symbols through a syscall will be restricted
68489+ to users with CAP_SYS_MODULE. For software compatibility reasons,
68490+ /proc/kallsyms will be restricted to the root user. The RBAC
68491+ system can hide that entry even from root.
68492+
68493+ This option also prevents leaking of kernel addresses through
68494+ several /proc entries.
68495+
68496+ Note that this option is only effective provided the following
68497+ conditions are met:
68498+ 1) The kernel using grsecurity is not precompiled by some distribution
68499+ 2) You have also enabled GRKERNSEC_DMESG
68500+ 3) You are using the RBAC system and hiding other files such as your
68501+ kernel image and System.map. Alternatively, enabling this option
68502+ causes the permissions on /boot, /lib/modules, and the kernel
68503+ source directory to change at compile time to prevent
68504+ reading by non-root users.
68505+ If the above conditions are met, this option will aid in providing a
68506+ useful protection against local kernel exploitation of overflows
68507+ and arbitrary read/write vulnerabilities.
68508+
68509+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
68510+ in addition to this feature.
68511+
68512+config GRKERNSEC_RANDSTRUCT
68513+ bool "Randomize layout of sensitive kernel structures"
68514+ default y if GRKERNSEC_CONFIG_AUTO
68515+ select GRKERNSEC_HIDESYM
68516+ select MODVERSIONS if MODULES
68517+ help
68518+ If you say Y here, the layouts of a number of sensitive kernel
68519+ structures (task, fs, cred, etc) and all structures composed entirely
68520+ of function pointers (aka "ops" structs) will be randomized at compile-time.
68521+ This can introduce the requirement of an additional infoleak
68522+ vulnerability for exploits targeting these structure types.
68523+
68524+ Enabling this feature will introduce some performance impact, slightly
68525+ increase memory usage, and prevent the use of forensic tools like
68526+ Volatility against the system (unless the kernel source tree isn't
68527+ cleaned after kernel installation).
68528+
68529+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
68530+ It remains after a make clean to allow for external modules to be compiled
68531+ with the existing seed and will be removed by a make mrproper or
68532+ make distclean.
68533+
68534+ Note that the implementation requires gcc 4.6.4. or newer. You may need
68535+ to install the supporting headers explicitly in addition to the normal
68536+ gcc package.
68537+
68538+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
68539+ bool "Use cacheline-aware structure randomization"
68540+ depends on GRKERNSEC_RANDSTRUCT
68541+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
68542+ help
68543+ If you say Y here, the RANDSTRUCT randomization will make a best effort
68544+ at restricting randomization to cacheline-sized groups of elements. It
68545+ will further not randomize bitfields in structures. This reduces the
68546+ performance hit of RANDSTRUCT at the cost of weakened randomization.
68547+
68548+config GRKERNSEC_KERN_LOCKOUT
68549+ bool "Active kernel exploit response"
68550+ default y if GRKERNSEC_CONFIG_AUTO
68551+ depends on X86 || ARM || PPC || SPARC
68552+ help
68553+ If you say Y here, when a PaX alert is triggered due to suspicious
68554+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
68555+ or an OOPS occurs due to bad memory accesses, instead of just
68556+ terminating the offending process (and potentially allowing
68557+ a subsequent exploit from the same user), we will take one of two
68558+ actions:
68559+ If the user was root, we will panic the system
68560+ If the user was non-root, we will log the attempt, terminate
68561+ all processes owned by the user, then prevent them from creating
68562+ any new processes until the system is restarted
68563+ This deters repeated kernel exploitation/bruteforcing attempts
68564+ and is useful for later forensics.
68565+
68566+config GRKERNSEC_OLD_ARM_USERLAND
68567+ bool "Old ARM userland compatibility"
68568+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
68569+ help
68570+ If you say Y here, stubs of executable code to perform such operations
68571+ as "compare-exchange" will be placed at fixed locations in the ARM vector
68572+ table. This is unfortunately needed for old ARM userland meant to run
68573+ across a wide range of processors. Without this option enabled,
68574+ the get_tls and data memory barrier stubs will be emulated by the kernel,
68575+ which is enough for Linaro userlands or other userlands designed for v6
68576+ and newer ARM CPUs. It's recommended that you try without this option enabled
68577+ first, and only enable it if your userland does not boot (it will likely fail
68578+ at init time).
68579+
68580+endmenu
68581+menu "Role Based Access Control Options"
68582+depends on GRKERNSEC
68583+
68584+config GRKERNSEC_RBAC_DEBUG
68585+ bool
68586+
68587+config GRKERNSEC_NO_RBAC
68588+ bool "Disable RBAC system"
68589+ help
68590+ If you say Y here, the /dev/grsec device will be removed from the kernel,
68591+ preventing the RBAC system from being enabled. You should only say Y
68592+ here if you have no intention of using the RBAC system, so as to prevent
68593+ an attacker with root access from misusing the RBAC system to hide files
68594+ and processes when loadable module support and /dev/[k]mem have been
68595+ locked down.
68596+
68597+config GRKERNSEC_ACL_HIDEKERN
68598+ bool "Hide kernel processes"
68599+ help
68600+ If you say Y here, all kernel threads will be hidden to all
68601+ processes but those whose subject has the "view hidden processes"
68602+ flag.
68603+
68604+config GRKERNSEC_ACL_MAXTRIES
68605+ int "Maximum tries before password lockout"
68606+ default 3
68607+ help
68608+ This option enforces the maximum number of times a user can attempt
68609+ to authorize themselves with the grsecurity RBAC system before being
68610+ denied the ability to attempt authorization again for a specified time.
68611+ The lower the number, the harder it will be to brute-force a password.
68612+
68613+config GRKERNSEC_ACL_TIMEOUT
68614+ int "Time to wait after max password tries, in seconds"
68615+ default 30
68616+ help
68617+ This option specifies the time the user must wait after attempting to
68618+ authorize to the RBAC system with the maximum number of invalid
68619+ passwords. The higher the number, the harder it will be to brute-force
68620+ a password.
68621+
68622+endmenu
68623+menu "Filesystem Protections"
68624+depends on GRKERNSEC
68625+
68626+config GRKERNSEC_PROC
68627+ bool "Proc restrictions"
68628+ default y if GRKERNSEC_CONFIG_AUTO
68629+ help
68630+ If you say Y here, the permissions of the /proc filesystem
68631+ will be altered to enhance system security and privacy. You MUST
68632+ choose either a user only restriction or a user and group restriction.
68633+ Depending upon the option you choose, you can either restrict users to
68634+ see only the processes they themselves run, or choose a group that can
68635+ view all processes and files normally restricted to root if you choose
68636+ the "restrict to user only" option. NOTE: If you're running identd or
68637+ ntpd as a non-root user, you will have to run it as the group you
68638+ specify here.
68639+
68640+config GRKERNSEC_PROC_USER
68641+ bool "Restrict /proc to user only"
68642+ depends on GRKERNSEC_PROC
68643+ help
68644+ If you say Y here, non-root users will only be able to view their own
68645+ processes, and restricts them from viewing network-related information,
68646+ and viewing kernel symbol and module information.
68647+
68648+config GRKERNSEC_PROC_USERGROUP
68649+ bool "Allow special group"
68650+ default y if GRKERNSEC_CONFIG_AUTO
68651+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
68652+ help
68653+ If you say Y here, you will be able to select a group that will be
68654+ able to view all processes and network-related information. If you've
68655+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
68656+ remain hidden. This option is useful if you want to run identd as
68657+ a non-root user. The group you select may also be chosen at boot time
68658+ via "grsec_proc_gid=" on the kernel commandline.
68659+
68660+config GRKERNSEC_PROC_GID
68661+ int "GID for special group"
68662+ depends on GRKERNSEC_PROC_USERGROUP
68663+ default 1001
68664+
68665+config GRKERNSEC_PROC_ADD
68666+ bool "Additional restrictions"
68667+ default y if GRKERNSEC_CONFIG_AUTO
68668+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
68669+ help
68670+ If you say Y here, additional restrictions will be placed on
68671+ /proc that keep normal users from viewing device information and
68672+ slabinfo information that could be useful for exploits.
68673+
68674+config GRKERNSEC_LINK
68675+ bool "Linking restrictions"
68676+ default y if GRKERNSEC_CONFIG_AUTO
68677+ help
68678+ If you say Y here, /tmp race exploits will be prevented, since users
68679+ will no longer be able to follow symlinks owned by other users in
68680+ world-writable +t directories (e.g. /tmp), unless the owner of the
68681+ symlink is the owner of the directory. users will also not be
68682+ able to hardlink to files they do not own. If the sysctl option is
68683+ enabled, a sysctl option with name "linking_restrictions" is created.
68684+
68685+config GRKERNSEC_SYMLINKOWN
68686+ bool "Kernel-enforced SymlinksIfOwnerMatch"
68687+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
68688+ help
68689+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
68690+ that prevents it from being used as a security feature. As Apache
68691+ verifies the symlink by performing a stat() against the target of
68692+ the symlink before it is followed, an attacker can setup a symlink
68693+ to point to a same-owned file, then replace the symlink with one
68694+ that targets another user's file just after Apache "validates" the
68695+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
68696+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
68697+ will be in place for the group you specify. If the sysctl option
68698+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
68699+ created.
68700+
68701+config GRKERNSEC_SYMLINKOWN_GID
68702+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
68703+ depends on GRKERNSEC_SYMLINKOWN
68704+ default 1006
68705+ help
68706+ Setting this GID determines what group kernel-enforced
68707+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
68708+ is enabled, a sysctl option with name "symlinkown_gid" is created.
68709+
68710+config GRKERNSEC_FIFO
68711+ bool "FIFO restrictions"
68712+ default y if GRKERNSEC_CONFIG_AUTO
68713+ help
68714+ If you say Y here, users will not be able to write to FIFOs they don't
68715+ own in world-writable +t directories (e.g. /tmp), unless the owner of
68716+ the FIFO is the same owner of the directory it's held in. If the sysctl
68717+ option is enabled, a sysctl option with name "fifo_restrictions" is
68718+ created.
68719+
68720+config GRKERNSEC_SYSFS_RESTRICT
68721+ bool "Sysfs/debugfs restriction"
68722+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
68723+ depends on SYSFS
68724+ help
68725+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
68726+ any filesystem normally mounted under it (e.g. debugfs) will be
68727+ mostly accessible only by root. These filesystems generally provide access
68728+ to hardware and debug information that isn't appropriate for unprivileged
68729+ users of the system. Sysfs and debugfs have also become a large source
68730+ of new vulnerabilities, ranging from infoleaks to local compromise.
68731+ There has been very little oversight with an eye toward security involved
68732+ in adding new exporters of information to these filesystems, so their
68733+ use is discouraged.
68734+ For reasons of compatibility, a few directories have been whitelisted
68735+ for access by non-root users:
68736+ /sys/fs/selinux
68737+ /sys/fs/fuse
68738+ /sys/devices/system/cpu
68739+
68740+config GRKERNSEC_ROFS
68741+ bool "Runtime read-only mount protection"
68742+ depends on SYSCTL
68743+ help
68744+ If you say Y here, a sysctl option with name "romount_protect" will
68745+ be created. By setting this option to 1 at runtime, filesystems
68746+ will be protected in the following ways:
68747+ * No new writable mounts will be allowed
68748+ * Existing read-only mounts won't be able to be remounted read/write
68749+ * Write operations will be denied on all block devices
68750+ This option acts independently of grsec_lock: once it is set to 1,
68751+ it cannot be turned off. Therefore, please be mindful of the resulting
68752+ behavior if this option is enabled in an init script on a read-only
68753+ filesystem.
68754+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
68755+ and GRKERNSEC_IO should be enabled and module loading disabled via
68756+ config or at runtime.
68757+ This feature is mainly intended for secure embedded systems.
68758+
68759+
68760+config GRKERNSEC_DEVICE_SIDECHANNEL
68761+ bool "Eliminate stat/notify-based device sidechannels"
68762+ default y if GRKERNSEC_CONFIG_AUTO
68763+ help
68764+ If you say Y here, timing analyses on block or character
68765+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
68766+ will be thwarted for unprivileged users. If a process without
68767+ CAP_MKNOD stats such a device, the last access and last modify times
68768+ will match the device's create time. No access or modify events
68769+ will be triggered through inotify/dnotify/fanotify for such devices.
68770+ This feature will prevent attacks that may at a minimum
68771+ allow an attacker to determine the administrator's password length.
68772+
68773+config GRKERNSEC_CHROOT
68774+ bool "Chroot jail restrictions"
68775+ default y if GRKERNSEC_CONFIG_AUTO
68776+ help
68777+ If you say Y here, you will be able to choose several options that will
68778+ make breaking out of a chrooted jail much more difficult. If you
68779+ encounter no software incompatibilities with the following options, it
68780+ is recommended that you enable each one.
68781+
68782+ Note that the chroot restrictions are not intended to apply to "chroots"
68783+ to directories that are simple bind mounts of the global root filesystem.
68784+ For several other reasons, a user shouldn't expect any significant
68785+ security by performing such a chroot.
68786+
68787+config GRKERNSEC_CHROOT_MOUNT
68788+ bool "Deny mounts"
68789+ default y if GRKERNSEC_CONFIG_AUTO
68790+ depends on GRKERNSEC_CHROOT
68791+ help
68792+ If you say Y here, processes inside a chroot will not be able to
68793+ mount or remount filesystems. If the sysctl option is enabled, a
68794+ sysctl option with name "chroot_deny_mount" is created.
68795+
68796+config GRKERNSEC_CHROOT_DOUBLE
68797+ bool "Deny double-chroots"
68798+ default y if GRKERNSEC_CONFIG_AUTO
68799+ depends on GRKERNSEC_CHROOT
68800+ help
68801+ If you say Y here, processes inside a chroot will not be able to chroot
68802+ again outside the chroot. This is a widely used method of breaking
68803+ out of a chroot jail and should not be allowed. If the sysctl
68804+ option is enabled, a sysctl option with name
68805+ "chroot_deny_chroot" is created.
68806+
68807+config GRKERNSEC_CHROOT_PIVOT
68808+ bool "Deny pivot_root in chroot"
68809+ default y if GRKERNSEC_CONFIG_AUTO
68810+ depends on GRKERNSEC_CHROOT
68811+ help
68812+ If you say Y here, processes inside a chroot will not be able to use
68813+ a function called pivot_root() that was introduced in Linux 2.3.41. It
68814+ works similar to chroot in that it changes the root filesystem. This
68815+ function could be misused in a chrooted process to attempt to break out
68816+ of the chroot, and therefore should not be allowed. If the sysctl
68817+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
68818+ created.
68819+
68820+config GRKERNSEC_CHROOT_CHDIR
68821+ bool "Enforce chdir(\"/\") on all chroots"
68822+ default y if GRKERNSEC_CONFIG_AUTO
68823+ depends on GRKERNSEC_CHROOT
68824+ help
68825+ If you say Y here, the current working directory of all newly-chrooted
68826+ applications will be set to the the root directory of the chroot.
68827+ The man page on chroot(2) states:
68828+ Note that this call does not change the current working
68829+ directory, so that `.' can be outside the tree rooted at
68830+ `/'. In particular, the super-user can escape from a
68831+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
68832+
68833+ It is recommended that you say Y here, since it's not known to break
68834+ any software. If the sysctl option is enabled, a sysctl option with
68835+ name "chroot_enforce_chdir" is created.
68836+
68837+config GRKERNSEC_CHROOT_CHMOD
68838+ bool "Deny (f)chmod +s"
68839+ default y if GRKERNSEC_CONFIG_AUTO
68840+ depends on GRKERNSEC_CHROOT
68841+ help
68842+ If you say Y here, processes inside a chroot will not be able to chmod
68843+ or fchmod files to make them have suid or sgid bits. This protects
68844+ against another published method of breaking a chroot. If the sysctl
68845+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
68846+ created.
68847+
68848+config GRKERNSEC_CHROOT_FCHDIR
68849+ bool "Deny fchdir and fhandle out of chroot"
68850+ default y if GRKERNSEC_CONFIG_AUTO
68851+ depends on GRKERNSEC_CHROOT
68852+ help
68853+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
68854+ to a file descriptor of the chrooting process that points to a directory
68855+ outside the filesystem will be stopped. Additionally, this option prevents
68856+ use of the recently-created syscall for opening files by a guessable "file
68857+ handle" inside a chroot. If the sysctl option is enabled, a sysctl option
68858+ with name "chroot_deny_fchdir" is created.
68859+
68860+config GRKERNSEC_CHROOT_MKNOD
68861+ bool "Deny mknod"
68862+ default y if GRKERNSEC_CONFIG_AUTO
68863+ depends on GRKERNSEC_CHROOT
68864+ help
68865+ If you say Y here, processes inside a chroot will not be allowed to
68866+ mknod. The problem with using mknod inside a chroot is that it
68867+ would allow an attacker to create a device entry that is the same
68868+ as one on the physical root of your system, which could range from
68869+ anything from the console device to a device for your harddrive (which
68870+ they could then use to wipe the drive or steal data). It is recommended
68871+ that you say Y here, unless you run into software incompatibilities.
68872+ If the sysctl option is enabled, a sysctl option with name
68873+ "chroot_deny_mknod" is created.
68874+
68875+config GRKERNSEC_CHROOT_SHMAT
68876+ bool "Deny shmat() out of chroot"
68877+ default y if GRKERNSEC_CONFIG_AUTO
68878+ depends on GRKERNSEC_CHROOT
68879+ help
68880+ If you say Y here, processes inside a chroot will not be able to attach
68881+ to shared memory segments that were created outside of the chroot jail.
68882+ It is recommended that you say Y here. If the sysctl option is enabled,
68883+ a sysctl option with name "chroot_deny_shmat" is created.
68884+
68885+config GRKERNSEC_CHROOT_UNIX
68886+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
68887+ default y if GRKERNSEC_CONFIG_AUTO
68888+ depends on GRKERNSEC_CHROOT
68889+ help
68890+ If you say Y here, processes inside a chroot will not be able to
68891+ connect to abstract (meaning not belonging to a filesystem) Unix
68892+ domain sockets that were bound outside of a chroot. It is recommended
68893+ that you say Y here. If the sysctl option is enabled, a sysctl option
68894+ with name "chroot_deny_unix" is created.
68895+
68896+config GRKERNSEC_CHROOT_FINDTASK
68897+ bool "Protect outside processes"
68898+ default y if GRKERNSEC_CONFIG_AUTO
68899+ depends on GRKERNSEC_CHROOT
68900+ help
68901+ If you say Y here, processes inside a chroot will not be able to
68902+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
68903+ getsid, or view any process outside of the chroot. If the sysctl
68904+ option is enabled, a sysctl option with name "chroot_findtask" is
68905+ created.
68906+
68907+config GRKERNSEC_CHROOT_NICE
68908+ bool "Restrict priority changes"
68909+ default y if GRKERNSEC_CONFIG_AUTO
68910+ depends on GRKERNSEC_CHROOT
68911+ help
68912+ If you say Y here, processes inside a chroot will not be able to raise
68913+ the priority of processes in the chroot, or alter the priority of
68914+ processes outside the chroot. This provides more security than simply
68915+ removing CAP_SYS_NICE from the process' capability set. If the
68916+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
68917+ is created.
68918+
68919+config GRKERNSEC_CHROOT_SYSCTL
68920+ bool "Deny sysctl writes"
68921+ default y if GRKERNSEC_CONFIG_AUTO
68922+ depends on GRKERNSEC_CHROOT
68923+ help
68924+ If you say Y here, an attacker in a chroot will not be able to
68925+ write to sysctl entries, either by sysctl(2) or through a /proc
68926+ interface. It is strongly recommended that you say Y here. If the
68927+ sysctl option is enabled, a sysctl option with name
68928+ "chroot_deny_sysctl" is created.
68929+
68930+config GRKERNSEC_CHROOT_CAPS
68931+ bool "Capability restrictions"
68932+ default y if GRKERNSEC_CONFIG_AUTO
68933+ depends on GRKERNSEC_CHROOT
68934+ help
68935+ If you say Y here, the capabilities on all processes within a
68936+ chroot jail will be lowered to stop module insertion, raw i/o,
68937+ system and net admin tasks, rebooting the system, modifying immutable
68938+ files, modifying IPC owned by another, and changing the system time.
68939+ This is left an option because it can break some apps. Disable this
68940+ if your chrooted apps are having problems performing those kinds of
68941+ tasks. If the sysctl option is enabled, a sysctl option with
68942+ name "chroot_caps" is created.
68943+
68944+config GRKERNSEC_CHROOT_INITRD
68945+ bool "Exempt initrd tasks from restrictions"
68946+ default y if GRKERNSEC_CONFIG_AUTO
68947+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
68948+ help
68949+ If you say Y here, tasks started prior to init will be exempted from
68950+ grsecurity's chroot restrictions. This option is mainly meant to
68951+ resolve Plymouth's performing privileged operations unnecessarily
68952+ in a chroot.
68953+
68954+endmenu
68955+menu "Kernel Auditing"
68956+depends on GRKERNSEC
68957+
68958+config GRKERNSEC_AUDIT_GROUP
68959+ bool "Single group for auditing"
68960+ help
68961+ If you say Y here, the exec and chdir logging features will only operate
68962+ on a group you specify. This option is recommended if you only want to
68963+ watch certain users instead of having a large amount of logs from the
68964+ entire system. If the sysctl option is enabled, a sysctl option with
68965+ name "audit_group" is created.
68966+
68967+config GRKERNSEC_AUDIT_GID
68968+ int "GID for auditing"
68969+ depends on GRKERNSEC_AUDIT_GROUP
68970+ default 1007
68971+
68972+config GRKERNSEC_EXECLOG
68973+ bool "Exec logging"
68974+ help
68975+ If you say Y here, all execve() calls will be logged (since the
68976+ other exec*() calls are frontends to execve(), all execution
68977+ will be logged). Useful for shell-servers that like to keep track
68978+ of their users. If the sysctl option is enabled, a sysctl option with
68979+ name "exec_logging" is created.
68980+ WARNING: This option when enabled will produce a LOT of logs, especially
68981+ on an active system.
68982+
68983+config GRKERNSEC_RESLOG
68984+ bool "Resource logging"
68985+ default y if GRKERNSEC_CONFIG_AUTO
68986+ help
68987+ If you say Y here, all attempts to overstep resource limits will
68988+ be logged with the resource name, the requested size, and the current
68989+ limit. It is highly recommended that you say Y here. If the sysctl
68990+ option is enabled, a sysctl option with name "resource_logging" is
68991+ created. If the RBAC system is enabled, the sysctl value is ignored.
68992+
68993+config GRKERNSEC_CHROOT_EXECLOG
68994+ bool "Log execs within chroot"
68995+ help
68996+ If you say Y here, all executions inside a chroot jail will be logged
68997+ to syslog. This can cause a large amount of logs if certain
68998+ applications (eg. djb's daemontools) are installed on the system, and
68999+ is therefore left as an option. If the sysctl option is enabled, a
69000+ sysctl option with name "chroot_execlog" is created.
69001+
69002+config GRKERNSEC_AUDIT_PTRACE
69003+ bool "Ptrace logging"
69004+ help
69005+ If you say Y here, all attempts to attach to a process via ptrace
69006+ will be logged. If the sysctl option is enabled, a sysctl option
69007+ with name "audit_ptrace" is created.
69008+
69009+config GRKERNSEC_AUDIT_CHDIR
69010+ bool "Chdir logging"
69011+ help
69012+ If you say Y here, all chdir() calls will be logged. If the sysctl
69013+ option is enabled, a sysctl option with name "audit_chdir" is created.
69014+
69015+config GRKERNSEC_AUDIT_MOUNT
69016+ bool "(Un)Mount logging"
69017+ help
69018+ If you say Y here, all mounts and unmounts will be logged. If the
69019+ sysctl option is enabled, a sysctl option with name "audit_mount" is
69020+ created.
69021+
69022+config GRKERNSEC_SIGNAL
69023+ bool "Signal logging"
69024+ default y if GRKERNSEC_CONFIG_AUTO
69025+ help
69026+ If you say Y here, certain important signals will be logged, such as
69027+ SIGSEGV, which will as a result inform you of when a error in a program
69028+ occurred, which in some cases could mean a possible exploit attempt.
69029+ If the sysctl option is enabled, a sysctl option with name
69030+ "signal_logging" is created.
69031+
69032+config GRKERNSEC_FORKFAIL
69033+ bool "Fork failure logging"
69034+ help
69035+ If you say Y here, all failed fork() attempts will be logged.
69036+ This could suggest a fork bomb, or someone attempting to overstep
69037+ their process limit. If the sysctl option is enabled, a sysctl option
69038+ with name "forkfail_logging" is created.
69039+
69040+config GRKERNSEC_TIME
69041+ bool "Time change logging"
69042+ default y if GRKERNSEC_CONFIG_AUTO
69043+ help
69044+ If you say Y here, any changes of the system clock will be logged.
69045+ If the sysctl option is enabled, a sysctl option with name
69046+ "timechange_logging" is created.
69047+
69048+config GRKERNSEC_PROC_IPADDR
69049+ bool "/proc/<pid>/ipaddr support"
69050+ default y if GRKERNSEC_CONFIG_AUTO
69051+ help
69052+ If you say Y here, a new entry will be added to each /proc/<pid>
69053+ directory that contains the IP address of the person using the task.
69054+ The IP is carried across local TCP and AF_UNIX stream sockets.
69055+ This information can be useful for IDS/IPSes to perform remote response
69056+ to a local attack. The entry is readable by only the owner of the
69057+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
69058+ the RBAC system), and thus does not create privacy concerns.
69059+
69060+config GRKERNSEC_RWXMAP_LOG
69061+ bool 'Denied RWX mmap/mprotect logging'
69062+ default y if GRKERNSEC_CONFIG_AUTO
69063+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
69064+ help
69065+ If you say Y here, calls to mmap() and mprotect() with explicit
69066+ usage of PROT_WRITE and PROT_EXEC together will be logged when
69067+ denied by the PAX_MPROTECT feature. This feature will also
69068+ log other problematic scenarios that can occur when PAX_MPROTECT
69069+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
69070+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
69071+ is created.
69072+
69073+endmenu
69074+
69075+menu "Executable Protections"
69076+depends on GRKERNSEC
69077+
69078+config GRKERNSEC_DMESG
69079+ bool "Dmesg(8) restriction"
69080+ default y if GRKERNSEC_CONFIG_AUTO
69081+ help
69082+ If you say Y here, non-root users will not be able to use dmesg(8)
69083+ to view the contents of the kernel's circular log buffer.
69084+ The kernel's log buffer often contains kernel addresses and other
69085+ identifying information useful to an attacker in fingerprinting a
69086+ system for a targeted exploit.
69087+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
69088+ created.
69089+
69090+config GRKERNSEC_HARDEN_PTRACE
69091+ bool "Deter ptrace-based process snooping"
69092+ default y if GRKERNSEC_CONFIG_AUTO
69093+ help
69094+ If you say Y here, TTY sniffers and other malicious monitoring
69095+ programs implemented through ptrace will be defeated. If you
69096+ have been using the RBAC system, this option has already been
69097+ enabled for several years for all users, with the ability to make
69098+ fine-grained exceptions.
69099+
69100+ This option only affects the ability of non-root users to ptrace
69101+ processes that are not a descendent of the ptracing process.
69102+ This means that strace ./binary and gdb ./binary will still work,
69103+ but attaching to arbitrary processes will not. If the sysctl
69104+ option is enabled, a sysctl option with name "harden_ptrace" is
69105+ created.
69106+
69107+config GRKERNSEC_PTRACE_READEXEC
69108+ bool "Require read access to ptrace sensitive binaries"
69109+ default y if GRKERNSEC_CONFIG_AUTO
69110+ help
69111+ If you say Y here, unprivileged users will not be able to ptrace unreadable
69112+ binaries. This option is useful in environments that
69113+ remove the read bits (e.g. file mode 4711) from suid binaries to
69114+ prevent infoleaking of their contents. This option adds
69115+ consistency to the use of that file mode, as the binary could normally
69116+ be read out when run without privileges while ptracing.
69117+
69118+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
69119+ is created.
69120+
69121+config GRKERNSEC_SETXID
69122+ bool "Enforce consistent multithreaded privileges"
69123+ default y if GRKERNSEC_CONFIG_AUTO
69124+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
69125+ help
69126+ If you say Y here, a change from a root uid to a non-root uid
69127+ in a multithreaded application will cause the resulting uids,
69128+ gids, supplementary groups, and capabilities in that thread
69129+ to be propagated to the other threads of the process. In most
69130+ cases this is unnecessary, as glibc will emulate this behavior
69131+ on behalf of the application. Other libcs do not act in the
69132+ same way, allowing the other threads of the process to continue
69133+ running with root privileges. If the sysctl option is enabled,
69134+ a sysctl option with name "consistent_setxid" is created.
69135+
69136+config GRKERNSEC_HARDEN_IPC
69137+ bool "Disallow access to overly-permissive IPC objects"
69138+ default y if GRKERNSEC_CONFIG_AUTO
69139+ depends on SYSVIPC
69140+ help
69141+ If you say Y here, access to overly-permissive IPC objects (shared
69142+ memory, message queues, and semaphores) will be denied for processes
69143+ given the following criteria beyond normal permission checks:
69144+ 1) If the IPC object is world-accessible and the euid doesn't match
69145+ that of the creator or current uid for the IPC object
69146+ 2) If the IPC object is group-accessible and the egid doesn't
69147+ match that of the creator or current gid for the IPC object
69148+ It's a common error to grant too much permission to these objects,
69149+ with impact ranging from denial of service and information leaking to
69150+ privilege escalation. This feature was developed in response to
69151+ research by Tim Brown:
69152+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
69153+ who found hundreds of such insecure usages. Processes with
69154+ CAP_IPC_OWNER are still permitted to access these IPC objects.
69155+ If the sysctl option is enabled, a sysctl option with name
69156+ "harden_ipc" is created.
69157+
69158+config GRKERNSEC_TPE
69159+ bool "Trusted Path Execution (TPE)"
69160+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
69161+ help
69162+ If you say Y here, you will be able to choose a gid to add to the
69163+ supplementary groups of users you want to mark as "untrusted."
69164+ These users will not be able to execute any files that are not in
69165+ root-owned directories writable only by root. If the sysctl option
69166+ is enabled, a sysctl option with name "tpe" is created.
69167+
69168+config GRKERNSEC_TPE_ALL
69169+ bool "Partially restrict all non-root users"
69170+ depends on GRKERNSEC_TPE
69171+ help
69172+ If you say Y here, all non-root users will be covered under
69173+ a weaker TPE restriction. This is separate from, and in addition to,
69174+ the main TPE options that you have selected elsewhere. Thus, if a
69175+ "trusted" GID is chosen, this restriction applies to even that GID.
69176+ Under this restriction, all non-root users will only be allowed to
69177+ execute files in directories they own that are not group or
69178+ world-writable, or in directories owned by root and writable only by
69179+ root. If the sysctl option is enabled, a sysctl option with name
69180+ "tpe_restrict_all" is created.
69181+
69182+config GRKERNSEC_TPE_INVERT
69183+ bool "Invert GID option"
69184+ depends on GRKERNSEC_TPE
69185+ help
69186+ If you say Y here, the group you specify in the TPE configuration will
69187+ decide what group TPE restrictions will be *disabled* for. This
69188+ option is useful if you want TPE restrictions to be applied to most
69189+ users on the system. If the sysctl option is enabled, a sysctl option
69190+ with name "tpe_invert" is created. Unlike other sysctl options, this
69191+ entry will default to on for backward-compatibility.
69192+
69193+config GRKERNSEC_TPE_GID
69194+ int
69195+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
69196+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
69197+
69198+config GRKERNSEC_TPE_UNTRUSTED_GID
69199+ int "GID for TPE-untrusted users"
69200+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
69201+ default 1005
69202+ help
69203+ Setting this GID determines what group TPE restrictions will be
69204+ *enabled* for. If the sysctl option is enabled, a sysctl option
69205+ with name "tpe_gid" is created.
69206+
69207+config GRKERNSEC_TPE_TRUSTED_GID
69208+ int "GID for TPE-trusted users"
69209+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
69210+ default 1005
69211+ help
69212+ Setting this GID determines what group TPE restrictions will be
69213+ *disabled* for. If the sysctl option is enabled, a sysctl option
69214+ with name "tpe_gid" is created.
69215+
69216+endmenu
69217+menu "Network Protections"
69218+depends on GRKERNSEC
69219+
69220+config GRKERNSEC_BLACKHOLE
69221+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
69222+ default y if GRKERNSEC_CONFIG_AUTO
69223+ depends on NET
69224+ help
69225+ If you say Y here, neither TCP resets nor ICMP
69226+ destination-unreachable packets will be sent in response to packets
69227+ sent to ports for which no associated listening process exists.
69228+ It will also prevent the sending of ICMP protocol unreachable packets
69229+ in response to packets with unknown protocols.
69230+ This feature supports both IPV4 and IPV6 and exempts the
69231+ loopback interface from blackholing. Enabling this feature
69232+ makes a host more resilient to DoS attacks and reduces network
69233+ visibility against scanners.
69234+
69235+ The blackhole feature as-implemented is equivalent to the FreeBSD
69236+ blackhole feature, as it prevents RST responses to all packets, not
69237+ just SYNs. Under most application behavior this causes no
69238+ problems, but applications (like haproxy) may not close certain
69239+ connections in a way that cleanly terminates them on the remote
69240+ end, leaving the remote host in LAST_ACK state. Because of this
69241+ side-effect and to prevent intentional LAST_ACK DoSes, this
69242+ feature also adds automatic mitigation against such attacks.
69243+ The mitigation drastically reduces the amount of time a socket
69244+ can spend in LAST_ACK state. If you're using haproxy and not
69245+ all servers it connects to have this option enabled, consider
69246+ disabling this feature on the haproxy host.
69247+
69248+ If the sysctl option is enabled, two sysctl options with names
69249+ "ip_blackhole" and "lastack_retries" will be created.
69250+ While "ip_blackhole" takes the standard zero/non-zero on/off
69251+ toggle, "lastack_retries" uses the same kinds of values as
69252+ "tcp_retries1" and "tcp_retries2". The default value of 4
69253+ prevents a socket from lasting more than 45 seconds in LAST_ACK
69254+ state.
69255+
69256+config GRKERNSEC_NO_SIMULT_CONNECT
69257+ bool "Disable TCP Simultaneous Connect"
69258+ default y if GRKERNSEC_CONFIG_AUTO
69259+ depends on NET
69260+ help
69261+ If you say Y here, a feature by Willy Tarreau will be enabled that
69262+ removes a weakness in Linux's strict implementation of TCP that
69263+ allows two clients to connect to each other without either entering
69264+ a listening state. The weakness allows an attacker to easily prevent
69265+ a client from connecting to a known server provided the source port
69266+ for the connection is guessed correctly.
69267+
69268+ As the weakness could be used to prevent an antivirus or IPS from
69269+ fetching updates, or prevent an SSL gateway from fetching a CRL,
69270+ it should be eliminated by enabling this option. Though Linux is
69271+ one of few operating systems supporting simultaneous connect, it
69272+ has no legitimate use in practice and is rarely supported by firewalls.
69273+
69274+config GRKERNSEC_SOCKET
69275+ bool "Socket restrictions"
69276+ depends on NET
69277+ help
69278+ If you say Y here, you will be able to choose from several options.
69279+ If you assign a GID on your system and add it to the supplementary
69280+ groups of users you want to restrict socket access to, this patch
69281+ will perform up to three things, based on the option(s) you choose.
69282+
69283+config GRKERNSEC_SOCKET_ALL
69284+ bool "Deny any sockets to group"
69285+ depends on GRKERNSEC_SOCKET
69286+ help
69287+ If you say Y here, you will be able to choose a GID of whose users will
69288+ be unable to connect to other hosts from your machine or run server
69289+ applications from your machine. If the sysctl option is enabled, a
69290+ sysctl option with name "socket_all" is created.
69291+
69292+config GRKERNSEC_SOCKET_ALL_GID
69293+ int "GID to deny all sockets for"
69294+ depends on GRKERNSEC_SOCKET_ALL
69295+ default 1004
69296+ help
69297+ Here you can choose the GID to disable socket access for. Remember to
69298+ add the users you want socket access disabled for to the GID
69299+ specified here. If the sysctl option is enabled, a sysctl option
69300+ with name "socket_all_gid" is created.
69301+
69302+config GRKERNSEC_SOCKET_CLIENT
69303+ bool "Deny client sockets to group"
69304+ depends on GRKERNSEC_SOCKET
69305+ help
69306+ If you say Y here, you will be able to choose a GID of whose users will
69307+ be unable to connect to other hosts from your machine, but will be
69308+ able to run servers. If this option is enabled, all users in the group
69309+ you specify will have to use passive mode when initiating ftp transfers
69310+ from the shell on your machine. If the sysctl option is enabled, a
69311+ sysctl option with name "socket_client" is created.
69312+
69313+config GRKERNSEC_SOCKET_CLIENT_GID
69314+ int "GID to deny client sockets for"
69315+ depends on GRKERNSEC_SOCKET_CLIENT
69316+ default 1003
69317+ help
69318+ Here you can choose the GID to disable client socket access for.
69319+ Remember to add the users you want client socket access disabled for to
69320+ the GID specified here. If the sysctl option is enabled, a sysctl
69321+ option with name "socket_client_gid" is created.
69322+
69323+config GRKERNSEC_SOCKET_SERVER
69324+ bool "Deny server sockets to group"
69325+ depends on GRKERNSEC_SOCKET
69326+ help
69327+ If you say Y here, you will be able to choose a GID of whose users will
69328+ be unable to run server applications from your machine. If the sysctl
69329+ option is enabled, a sysctl option with name "socket_server" is created.
69330+
69331+config GRKERNSEC_SOCKET_SERVER_GID
69332+ int "GID to deny server sockets for"
69333+ depends on GRKERNSEC_SOCKET_SERVER
69334+ default 1002
69335+ help
69336+ Here you can choose the GID to disable server socket access for.
69337+ Remember to add the users you want server socket access disabled for to
69338+ the GID specified here. If the sysctl option is enabled, a sysctl
69339+ option with name "socket_server_gid" is created.
69340+
69341+endmenu
69342+
69343+menu "Physical Protections"
69344+depends on GRKERNSEC
69345+
69346+config GRKERNSEC_DENYUSB
69347+ bool "Deny new USB connections after toggle"
69348+ default y if GRKERNSEC_CONFIG_AUTO
69349+ depends on SYSCTL && USB_SUPPORT
69350+ help
69351+ If you say Y here, a new sysctl option with name "deny_new_usb"
69352+ will be created. Setting its value to 1 will prevent any new
69353+ USB devices from being recognized by the OS. Any attempted USB
69354+ device insertion will be logged. This option is intended to be
69355+ used against custom USB devices designed to exploit vulnerabilities
69356+ in various USB device drivers.
69357+
69358+ For greatest effectiveness, this sysctl should be set after any
69359+ relevant init scripts. This option is safe to enable in distros
69360+ as each user can choose whether or not to toggle the sysctl.
69361+
69362+config GRKERNSEC_DENYUSB_FORCE
69363+ bool "Reject all USB devices not connected at boot"
69364+ select USB
69365+ depends on GRKERNSEC_DENYUSB
69366+ help
69367+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
69368+ that doesn't involve a sysctl entry. This option should only be
69369+ enabled if you're sure you want to deny all new USB connections
69370+ at runtime and don't want to modify init scripts. This should not
69371+ be enabled by distros. It forces the core USB code to be built
69372+ into the kernel image so that all devices connected at boot time
69373+ can be recognized and new USB device connections can be prevented
69374+ prior to init running.
69375+
69376+endmenu
69377+
69378+menu "Sysctl Support"
69379+depends on GRKERNSEC && SYSCTL
69380+
69381+config GRKERNSEC_SYSCTL
69382+ bool "Sysctl support"
69383+ default y if GRKERNSEC_CONFIG_AUTO
69384+ help
69385+ If you say Y here, you will be able to change the options that
69386+ grsecurity runs with at bootup, without having to recompile your
69387+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
69388+ to enable (1) or disable (0) various features. All the sysctl entries
69389+ are mutable until the "grsec_lock" entry is set to a non-zero value.
69390+ All features enabled in the kernel configuration are disabled at boot
69391+ if you do not say Y to the "Turn on features by default" option.
69392+ All options should be set at startup, and the grsec_lock entry should
69393+ be set to a non-zero value after all the options are set.
69394+ *THIS IS EXTREMELY IMPORTANT*
69395+
69396+config GRKERNSEC_SYSCTL_DISTRO
69397+ bool "Extra sysctl support for distro makers (READ HELP)"
69398+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
69399+ help
69400+ If you say Y here, additional sysctl options will be created
69401+ for features that affect processes running as root. Therefore,
69402+ it is critical when using this option that the grsec_lock entry be
69403+ enabled after boot. Only distros with prebuilt kernel packages
69404+ with this option enabled that can ensure grsec_lock is enabled
69405+ after boot should use this option.
69406+ *Failure to set grsec_lock after boot makes all grsec features
69407+ this option covers useless*
69408+
69409+ Currently this option creates the following sysctl entries:
69410+ "Disable Privileged I/O": "disable_priv_io"
69411+
69412+config GRKERNSEC_SYSCTL_ON
69413+ bool "Turn on features by default"
69414+ default y if GRKERNSEC_CONFIG_AUTO
69415+ depends on GRKERNSEC_SYSCTL
69416+ help
69417+ If you say Y here, instead of having all features enabled in the
69418+ kernel configuration disabled at boot time, the features will be
69419+ enabled at boot time. It is recommended you say Y here unless
69420+ there is some reason you would want all sysctl-tunable features to
69421+ be disabled by default. As mentioned elsewhere, it is important
69422+ to enable the grsec_lock entry once you have finished modifying
69423+ the sysctl entries.
69424+
69425+endmenu
69426+menu "Logging Options"
69427+depends on GRKERNSEC
69428+
69429+config GRKERNSEC_FLOODTIME
69430+ int "Seconds in between log messages (minimum)"
69431+ default 10
69432+ help
69433+ This option allows you to enforce the number of seconds between
69434+ grsecurity log messages. The default should be suitable for most
69435+ people, however, if you choose to change it, choose a value small enough
69436+ to allow informative logs to be produced, but large enough to
69437+ prevent flooding.
69438+
69439+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
69440+ any rate limiting on grsecurity log messages.
69441+
69442+config GRKERNSEC_FLOODBURST
69443+ int "Number of messages in a burst (maximum)"
69444+ default 6
69445+ help
69446+ This option allows you to choose the maximum number of messages allowed
69447+ within the flood time interval you chose in a separate option. The
69448+ default should be suitable for most people, however if you find that
69449+ many of your logs are being interpreted as flooding, you may want to
69450+ raise this value.
69451+
69452+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
69453+ any rate limiting on grsecurity log messages.
69454+
69455+endmenu
69456diff --git a/grsecurity/Makefile b/grsecurity/Makefile
69457new file mode 100644
69458index 0000000..30ababb
69459--- /dev/null
69460+++ b/grsecurity/Makefile
69461@@ -0,0 +1,54 @@
69462+# grsecurity – access control and security hardening for Linux
69463+# All code in this directory and various hooks located throughout the Linux kernel are
69464+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
69465+# http://www.grsecurity.net spender@grsecurity.net
69466+#
69467+# This program is free software; you can redistribute it and/or
69468+# modify it under the terms of the GNU General Public License version 2
69469+# as published by the Free Software Foundation.
69470+#
69471+# This program is distributed in the hope that it will be useful,
69472+# but WITHOUT ANY WARRANTY; without even the implied warranty of
69473+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69474+# GNU General Public License for more details.
69475+#
69476+# You should have received a copy of the GNU General Public License
69477+# along with this program; if not, write to the Free Software
69478+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
69479+
69480+KBUILD_CFLAGS += -Werror
69481+
69482+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
69483+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
69484+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
69485+ grsec_usb.o grsec_ipc.o grsec_proc.o
69486+
69487+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
69488+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
69489+ gracl_learn.o grsec_log.o gracl_policy.o
69490+ifdef CONFIG_COMPAT
69491+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
69492+endif
69493+
69494+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
69495+
69496+ifdef CONFIG_NET
69497+obj-y += grsec_sock.o
69498+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
69499+endif
69500+
69501+ifndef CONFIG_GRKERNSEC
69502+obj-y += grsec_disabled.o
69503+endif
69504+
69505+ifdef CONFIG_GRKERNSEC_HIDESYM
69506+extra-y := grsec_hidesym.o
69507+$(obj)/grsec_hidesym.o:
69508+ @-chmod -f 500 /boot
69509+ @-chmod -f 500 /lib/modules
69510+ @-chmod -f 500 /lib64/modules
69511+ @-chmod -f 500 /lib32/modules
69512+ @-chmod -f 700 .
69513+ @-chmod -f 700 $(objtree)
69514+ @echo ' grsec: protected kernel image paths'
69515+endif
69516diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
69517new file mode 100644
69518index 0000000..6ae3aa0
69519--- /dev/null
69520+++ b/grsecurity/gracl.c
69521@@ -0,0 +1,2703 @@
69522+#include <linux/kernel.h>
69523+#include <linux/module.h>
69524+#include <linux/sched.h>
69525+#include <linux/mm.h>
69526+#include <linux/file.h>
69527+#include <linux/fs.h>
69528+#include <linux/namei.h>
69529+#include <linux/mount.h>
69530+#include <linux/tty.h>
69531+#include <linux/proc_fs.h>
69532+#include <linux/lglock.h>
69533+#include <linux/slab.h>
69534+#include <linux/vmalloc.h>
69535+#include <linux/types.h>
69536+#include <linux/sysctl.h>
69537+#include <linux/netdevice.h>
69538+#include <linux/ptrace.h>
69539+#include <linux/gracl.h>
69540+#include <linux/gralloc.h>
69541+#include <linux/security.h>
69542+#include <linux/grinternal.h>
69543+#include <linux/pid_namespace.h>
69544+#include <linux/stop_machine.h>
69545+#include <linux/fdtable.h>
69546+#include <linux/percpu.h>
69547+#include <linux/lglock.h>
69548+#include <linux/hugetlb.h>
69549+#include <linux/posix-timers.h>
69550+#include <linux/prefetch.h>
69551+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69552+#include <linux/magic.h>
69553+#include <linux/pagemap.h>
69554+#include "../fs/btrfs/async-thread.h"
69555+#include "../fs/btrfs/ctree.h"
69556+#include "../fs/btrfs/btrfs_inode.h"
69557+#endif
69558+#include "../fs/mount.h"
69559+
69560+#include <asm/uaccess.h>
69561+#include <asm/errno.h>
69562+#include <asm/mman.h>
69563+
69564+#define FOR_EACH_ROLE_START(role) \
69565+ role = running_polstate.role_list; \
69566+ while (role) {
69567+
69568+#define FOR_EACH_ROLE_END(role) \
69569+ role = role->prev; \
69570+ }
69571+
69572+extern struct path gr_real_root;
69573+
69574+static struct gr_policy_state running_polstate;
69575+struct gr_policy_state *polstate = &running_polstate;
69576+extern struct gr_alloc_state *current_alloc_state;
69577+
69578+extern char *gr_shared_page[4];
69579+DEFINE_RWLOCK(gr_inode_lock);
69580+
69581+static unsigned int gr_status __read_only = GR_STATUS_INIT;
69582+
69583+#ifdef CONFIG_NET
69584+extern struct vfsmount *sock_mnt;
69585+#endif
69586+
69587+extern struct vfsmount *pipe_mnt;
69588+extern struct vfsmount *shm_mnt;
69589+
69590+#ifdef CONFIG_HUGETLBFS
69591+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
69592+#endif
69593+
69594+extern u16 acl_sp_role_value;
69595+extern struct acl_object_label *fakefs_obj_rw;
69596+extern struct acl_object_label *fakefs_obj_rwx;
69597+
69598+int gr_acl_is_enabled(void)
69599+{
69600+ return (gr_status & GR_READY);
69601+}
69602+
69603+void gr_enable_rbac_system(void)
69604+{
69605+ pax_open_kernel();
69606+ gr_status |= GR_READY;
69607+ pax_close_kernel();
69608+}
69609+
69610+int gr_rbac_disable(void *unused)
69611+{
69612+ pax_open_kernel();
69613+ gr_status &= ~GR_READY;
69614+ pax_close_kernel();
69615+
69616+ return 0;
69617+}
69618+
69619+static inline dev_t __get_dev(const struct dentry *dentry)
69620+{
69621+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
69622+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
69623+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
69624+ else
69625+#endif
69626+ return dentry->d_sb->s_dev;
69627+}
69628+
69629+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
69630+{
69631+ return __get_dev(dentry);
69632+}
69633+
69634+static char gr_task_roletype_to_char(struct task_struct *task)
69635+{
69636+ switch (task->role->roletype &
69637+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
69638+ GR_ROLE_SPECIAL)) {
69639+ case GR_ROLE_DEFAULT:
69640+ return 'D';
69641+ case GR_ROLE_USER:
69642+ return 'U';
69643+ case GR_ROLE_GROUP:
69644+ return 'G';
69645+ case GR_ROLE_SPECIAL:
69646+ return 'S';
69647+ }
69648+
69649+ return 'X';
69650+}
69651+
69652+char gr_roletype_to_char(void)
69653+{
69654+ return gr_task_roletype_to_char(current);
69655+}
69656+
69657+__inline__ int
69658+gr_acl_tpe_check(void)
69659+{
69660+ if (unlikely(!(gr_status & GR_READY)))
69661+ return 0;
69662+ if (current->role->roletype & GR_ROLE_TPE)
69663+ return 1;
69664+ else
69665+ return 0;
69666+}
69667+
69668+int
69669+gr_handle_rawio(const struct inode *inode)
69670+{
69671+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
69672+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
69673+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
69674+ !capable(CAP_SYS_RAWIO))
69675+ return 1;
69676+#endif
69677+ return 0;
69678+}
69679+
69680+int
69681+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
69682+{
69683+ if (likely(lena != lenb))
69684+ return 0;
69685+
69686+ return !memcmp(a, b, lena);
69687+}
69688+
69689+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
69690+{
69691+ *buflen -= namelen;
69692+ if (*buflen < 0)
69693+ return -ENAMETOOLONG;
69694+ *buffer -= namelen;
69695+ memcpy(*buffer, str, namelen);
69696+ return 0;
69697+}
69698+
69699+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
69700+{
69701+ return prepend(buffer, buflen, name->name, name->len);
69702+}
69703+
69704+static int prepend_path(const struct path *path, struct path *root,
69705+ char **buffer, int *buflen)
69706+{
69707+ struct dentry *dentry = path->dentry;
69708+ struct vfsmount *vfsmnt = path->mnt;
69709+ struct mount *mnt = real_mount(vfsmnt);
69710+ bool slash = false;
69711+ int error = 0;
69712+
69713+ while (dentry != root->dentry || vfsmnt != root->mnt) {
69714+ struct dentry * parent;
69715+
69716+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
69717+ /* Global root? */
69718+ if (!mnt_has_parent(mnt)) {
69719+ goto out;
69720+ }
69721+ dentry = mnt->mnt_mountpoint;
69722+ mnt = mnt->mnt_parent;
69723+ vfsmnt = &mnt->mnt;
69724+ continue;
69725+ }
69726+ parent = dentry->d_parent;
69727+ prefetch(parent);
69728+ spin_lock(&dentry->d_lock);
69729+ error = prepend_name(buffer, buflen, &dentry->d_name);
69730+ spin_unlock(&dentry->d_lock);
69731+ if (!error)
69732+ error = prepend(buffer, buflen, "/", 1);
69733+ if (error)
69734+ break;
69735+
69736+ slash = true;
69737+ dentry = parent;
69738+ }
69739+
69740+out:
69741+ if (!error && !slash)
69742+ error = prepend(buffer, buflen, "/", 1);
69743+
69744+ return error;
69745+}
69746+
69747+/* this must be called with mount_lock and rename_lock held */
69748+
69749+static char *__our_d_path(const struct path *path, struct path *root,
69750+ char *buf, int buflen)
69751+{
69752+ char *res = buf + buflen;
69753+ int error;
69754+
69755+ prepend(&res, &buflen, "\0", 1);
69756+ error = prepend_path(path, root, &res, &buflen);
69757+ if (error)
69758+ return ERR_PTR(error);
69759+
69760+ return res;
69761+}
69762+
69763+static char *
69764+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
69765+{
69766+ char *retval;
69767+
69768+ retval = __our_d_path(path, root, buf, buflen);
69769+ if (unlikely(IS_ERR(retval)))
69770+ retval = strcpy(buf, "<path too long>");
69771+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
69772+ retval[1] = '\0';
69773+
69774+ return retval;
69775+}
69776+
69777+static char *
69778+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69779+ char *buf, int buflen)
69780+{
69781+ struct path path;
69782+ char *res;
69783+
69784+ path.dentry = (struct dentry *)dentry;
69785+ path.mnt = (struct vfsmount *)vfsmnt;
69786+
69787+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
69788+ by the RBAC system */
69789+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
69790+
69791+ return res;
69792+}
69793+
69794+static char *
69795+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
69796+ char *buf, int buflen)
69797+{
69798+ char *res;
69799+ struct path path;
69800+ struct path root;
69801+ struct task_struct *reaper = init_pid_ns.child_reaper;
69802+
69803+ path.dentry = (struct dentry *)dentry;
69804+ path.mnt = (struct vfsmount *)vfsmnt;
69805+
69806+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
69807+ get_fs_root(reaper->fs, &root);
69808+
69809+ read_seqlock_excl(&mount_lock);
69810+ write_seqlock(&rename_lock);
69811+ res = gen_full_path(&path, &root, buf, buflen);
69812+ write_sequnlock(&rename_lock);
69813+ read_sequnlock_excl(&mount_lock);
69814+
69815+ path_put(&root);
69816+ return res;
69817+}
69818+
69819+char *
69820+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69821+{
69822+ char *ret;
69823+ read_seqlock_excl(&mount_lock);
69824+ write_seqlock(&rename_lock);
69825+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69826+ PAGE_SIZE);
69827+ write_sequnlock(&rename_lock);
69828+ read_sequnlock_excl(&mount_lock);
69829+ return ret;
69830+}
69831+
69832+static char *
69833+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
69834+{
69835+ char *ret;
69836+ char *buf;
69837+ int buflen;
69838+
69839+ read_seqlock_excl(&mount_lock);
69840+ write_seqlock(&rename_lock);
69841+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
69842+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
69843+ buflen = (int)(ret - buf);
69844+ if (buflen >= 5)
69845+ prepend(&ret, &buflen, "/proc", 5);
69846+ else
69847+ ret = strcpy(buf, "<path too long>");
69848+ write_sequnlock(&rename_lock);
69849+ read_sequnlock_excl(&mount_lock);
69850+ return ret;
69851+}
69852+
69853+char *
69854+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
69855+{
69856+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
69857+ PAGE_SIZE);
69858+}
69859+
69860+char *
69861+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
69862+{
69863+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69864+ PAGE_SIZE);
69865+}
69866+
69867+char *
69868+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
69869+{
69870+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
69871+ PAGE_SIZE);
69872+}
69873+
69874+char *
69875+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
69876+{
69877+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
69878+ PAGE_SIZE);
69879+}
69880+
69881+char *
69882+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
69883+{
69884+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
69885+ PAGE_SIZE);
69886+}
69887+
69888+__inline__ __u32
69889+to_gr_audit(const __u32 reqmode)
69890+{
69891+ /* masks off auditable permission flags, then shifts them to create
69892+ auditing flags, and adds the special case of append auditing if
69893+ we're requesting write */
69894+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
69895+}
69896+
69897+struct acl_role_label *
69898+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
69899+ const gid_t gid)
69900+{
69901+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
69902+ struct acl_role_label *match;
69903+ struct role_allowed_ip *ipp;
69904+ unsigned int x;
69905+ u32 curr_ip = task->signal->saved_ip;
69906+
69907+ match = state->acl_role_set.r_hash[index];
69908+
69909+ while (match) {
69910+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
69911+ for (x = 0; x < match->domain_child_num; x++) {
69912+ if (match->domain_children[x] == uid)
69913+ goto found;
69914+ }
69915+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
69916+ break;
69917+ match = match->next;
69918+ }
69919+found:
69920+ if (match == NULL) {
69921+ try_group:
69922+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
69923+ match = state->acl_role_set.r_hash[index];
69924+
69925+ while (match) {
69926+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
69927+ for (x = 0; x < match->domain_child_num; x++) {
69928+ if (match->domain_children[x] == gid)
69929+ goto found2;
69930+ }
69931+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
69932+ break;
69933+ match = match->next;
69934+ }
69935+found2:
69936+ if (match == NULL)
69937+ match = state->default_role;
69938+ if (match->allowed_ips == NULL)
69939+ return match;
69940+ else {
69941+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69942+ if (likely
69943+ ((ntohl(curr_ip) & ipp->netmask) ==
69944+ (ntohl(ipp->addr) & ipp->netmask)))
69945+ return match;
69946+ }
69947+ match = state->default_role;
69948+ }
69949+ } else if (match->allowed_ips == NULL) {
69950+ return match;
69951+ } else {
69952+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
69953+ if (likely
69954+ ((ntohl(curr_ip) & ipp->netmask) ==
69955+ (ntohl(ipp->addr) & ipp->netmask)))
69956+ return match;
69957+ }
69958+ goto try_group;
69959+ }
69960+
69961+ return match;
69962+}
69963+
69964+static struct acl_role_label *
69965+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
69966+ const gid_t gid)
69967+{
69968+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
69969+}
69970+
69971+struct acl_subject_label *
69972+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
69973+ const struct acl_role_label *role)
69974+{
69975+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
69976+ struct acl_subject_label *match;
69977+
69978+ match = role->subj_hash[index];
69979+
69980+ while (match && (match->inode != ino || match->device != dev ||
69981+ (match->mode & GR_DELETED))) {
69982+ match = match->next;
69983+ }
69984+
69985+ if (match && !(match->mode & GR_DELETED))
69986+ return match;
69987+ else
69988+ return NULL;
69989+}
69990+
69991+struct acl_subject_label *
69992+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
69993+ const struct acl_role_label *role)
69994+{
69995+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
69996+ struct acl_subject_label *match;
69997+
69998+ match = role->subj_hash[index];
69999+
70000+ while (match && (match->inode != ino || match->device != dev ||
70001+ !(match->mode & GR_DELETED))) {
70002+ match = match->next;
70003+ }
70004+
70005+ if (match && (match->mode & GR_DELETED))
70006+ return match;
70007+ else
70008+ return NULL;
70009+}
70010+
70011+static struct acl_object_label *
70012+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
70013+ const struct acl_subject_label *subj)
70014+{
70015+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70016+ struct acl_object_label *match;
70017+
70018+ match = subj->obj_hash[index];
70019+
70020+ while (match && (match->inode != ino || match->device != dev ||
70021+ (match->mode & GR_DELETED))) {
70022+ match = match->next;
70023+ }
70024+
70025+ if (match && !(match->mode & GR_DELETED))
70026+ return match;
70027+ else
70028+ return NULL;
70029+}
70030+
70031+static struct acl_object_label *
70032+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
70033+ const struct acl_subject_label *subj)
70034+{
70035+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
70036+ struct acl_object_label *match;
70037+
70038+ match = subj->obj_hash[index];
70039+
70040+ while (match && (match->inode != ino || match->device != dev ||
70041+ !(match->mode & GR_DELETED))) {
70042+ match = match->next;
70043+ }
70044+
70045+ if (match && (match->mode & GR_DELETED))
70046+ return match;
70047+
70048+ match = subj->obj_hash[index];
70049+
70050+ while (match && (match->inode != ino || match->device != dev ||
70051+ (match->mode & GR_DELETED))) {
70052+ match = match->next;
70053+ }
70054+
70055+ if (match && !(match->mode & GR_DELETED))
70056+ return match;
70057+ else
70058+ return NULL;
70059+}
70060+
70061+struct name_entry *
70062+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
70063+{
70064+ unsigned int len = strlen(name);
70065+ unsigned int key = full_name_hash(name, len);
70066+ unsigned int index = key % state->name_set.n_size;
70067+ struct name_entry *match;
70068+
70069+ match = state->name_set.n_hash[index];
70070+
70071+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
70072+ match = match->next;
70073+
70074+ return match;
70075+}
70076+
70077+static struct name_entry *
70078+lookup_name_entry(const char *name)
70079+{
70080+ return __lookup_name_entry(&running_polstate, name);
70081+}
70082+
70083+static struct name_entry *
70084+lookup_name_entry_create(const char *name)
70085+{
70086+ unsigned int len = strlen(name);
70087+ unsigned int key = full_name_hash(name, len);
70088+ unsigned int index = key % running_polstate.name_set.n_size;
70089+ struct name_entry *match;
70090+
70091+ match = running_polstate.name_set.n_hash[index];
70092+
70093+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70094+ !match->deleted))
70095+ match = match->next;
70096+
70097+ if (match && match->deleted)
70098+ return match;
70099+
70100+ match = running_polstate.name_set.n_hash[index];
70101+
70102+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
70103+ match->deleted))
70104+ match = match->next;
70105+
70106+ if (match && !match->deleted)
70107+ return match;
70108+ else
70109+ return NULL;
70110+}
70111+
70112+static struct inodev_entry *
70113+lookup_inodev_entry(const ino_t ino, const dev_t dev)
70114+{
70115+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
70116+ struct inodev_entry *match;
70117+
70118+ match = running_polstate.inodev_set.i_hash[index];
70119+
70120+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
70121+ match = match->next;
70122+
70123+ return match;
70124+}
70125+
70126+void
70127+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
70128+{
70129+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
70130+ state->inodev_set.i_size);
70131+ struct inodev_entry **curr;
70132+
70133+ entry->prev = NULL;
70134+
70135+ curr = &state->inodev_set.i_hash[index];
70136+ if (*curr != NULL)
70137+ (*curr)->prev = entry;
70138+
70139+ entry->next = *curr;
70140+ *curr = entry;
70141+
70142+ return;
70143+}
70144+
70145+static void
70146+insert_inodev_entry(struct inodev_entry *entry)
70147+{
70148+ __insert_inodev_entry(&running_polstate, entry);
70149+}
70150+
70151+void
70152+insert_acl_obj_label(struct acl_object_label *obj,
70153+ struct acl_subject_label *subj)
70154+{
70155+ unsigned int index =
70156+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
70157+ struct acl_object_label **curr;
70158+
70159+ obj->prev = NULL;
70160+
70161+ curr = &subj->obj_hash[index];
70162+ if (*curr != NULL)
70163+ (*curr)->prev = obj;
70164+
70165+ obj->next = *curr;
70166+ *curr = obj;
70167+
70168+ return;
70169+}
70170+
70171+void
70172+insert_acl_subj_label(struct acl_subject_label *obj,
70173+ struct acl_role_label *role)
70174+{
70175+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
70176+ struct acl_subject_label **curr;
70177+
70178+ obj->prev = NULL;
70179+
70180+ curr = &role->subj_hash[index];
70181+ if (*curr != NULL)
70182+ (*curr)->prev = obj;
70183+
70184+ obj->next = *curr;
70185+ *curr = obj;
70186+
70187+ return;
70188+}
70189+
70190+/* derived from glibc fnmatch() 0: match, 1: no match*/
70191+
70192+static int
70193+glob_match(const char *p, const char *n)
70194+{
70195+ char c;
70196+
70197+ while ((c = *p++) != '\0') {
70198+ switch (c) {
70199+ case '?':
70200+ if (*n == '\0')
70201+ return 1;
70202+ else if (*n == '/')
70203+ return 1;
70204+ break;
70205+ case '\\':
70206+ if (*n != c)
70207+ return 1;
70208+ break;
70209+ case '*':
70210+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
70211+ if (*n == '/')
70212+ return 1;
70213+ else if (c == '?') {
70214+ if (*n == '\0')
70215+ return 1;
70216+ else
70217+ ++n;
70218+ }
70219+ }
70220+ if (c == '\0') {
70221+ return 0;
70222+ } else {
70223+ const char *endp;
70224+
70225+ if ((endp = strchr(n, '/')) == NULL)
70226+ endp = n + strlen(n);
70227+
70228+ if (c == '[') {
70229+ for (--p; n < endp; ++n)
70230+ if (!glob_match(p, n))
70231+ return 0;
70232+ } else if (c == '/') {
70233+ while (*n != '\0' && *n != '/')
70234+ ++n;
70235+ if (*n == '/' && !glob_match(p, n + 1))
70236+ return 0;
70237+ } else {
70238+ for (--p; n < endp; ++n)
70239+ if (*n == c && !glob_match(p, n))
70240+ return 0;
70241+ }
70242+
70243+ return 1;
70244+ }
70245+ case '[':
70246+ {
70247+ int not;
70248+ char cold;
70249+
70250+ if (*n == '\0' || *n == '/')
70251+ return 1;
70252+
70253+ not = (*p == '!' || *p == '^');
70254+ if (not)
70255+ ++p;
70256+
70257+ c = *p++;
70258+ for (;;) {
70259+ unsigned char fn = (unsigned char)*n;
70260+
70261+ if (c == '\0')
70262+ return 1;
70263+ else {
70264+ if (c == fn)
70265+ goto matched;
70266+ cold = c;
70267+ c = *p++;
70268+
70269+ if (c == '-' && *p != ']') {
70270+ unsigned char cend = *p++;
70271+
70272+ if (cend == '\0')
70273+ return 1;
70274+
70275+ if (cold <= fn && fn <= cend)
70276+ goto matched;
70277+
70278+ c = *p++;
70279+ }
70280+ }
70281+
70282+ if (c == ']')
70283+ break;
70284+ }
70285+ if (!not)
70286+ return 1;
70287+ break;
70288+ matched:
70289+ while (c != ']') {
70290+ if (c == '\0')
70291+ return 1;
70292+
70293+ c = *p++;
70294+ }
70295+ if (not)
70296+ return 1;
70297+ }
70298+ break;
70299+ default:
70300+ if (c != *n)
70301+ return 1;
70302+ }
70303+
70304+ ++n;
70305+ }
70306+
70307+ if (*n == '\0')
70308+ return 0;
70309+
70310+ if (*n == '/')
70311+ return 0;
70312+
70313+ return 1;
70314+}
70315+
70316+static struct acl_object_label *
70317+chk_glob_label(struct acl_object_label *globbed,
70318+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
70319+{
70320+ struct acl_object_label *tmp;
70321+
70322+ if (*path == NULL)
70323+ *path = gr_to_filename_nolock(dentry, mnt);
70324+
70325+ tmp = globbed;
70326+
70327+ while (tmp) {
70328+ if (!glob_match(tmp->filename, *path))
70329+ return tmp;
70330+ tmp = tmp->next;
70331+ }
70332+
70333+ return NULL;
70334+}
70335+
70336+static struct acl_object_label *
70337+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70338+ const ino_t curr_ino, const dev_t curr_dev,
70339+ const struct acl_subject_label *subj, char **path, const int checkglob)
70340+{
70341+ struct acl_subject_label *tmpsubj;
70342+ struct acl_object_label *retval;
70343+ struct acl_object_label *retval2;
70344+
70345+ tmpsubj = (struct acl_subject_label *) subj;
70346+ read_lock(&gr_inode_lock);
70347+ do {
70348+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
70349+ if (retval) {
70350+ if (checkglob && retval->globbed) {
70351+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
70352+ if (retval2)
70353+ retval = retval2;
70354+ }
70355+ break;
70356+ }
70357+ } while ((tmpsubj = tmpsubj->parent_subject));
70358+ read_unlock(&gr_inode_lock);
70359+
70360+ return retval;
70361+}
70362+
70363+static __inline__ struct acl_object_label *
70364+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
70365+ struct dentry *curr_dentry,
70366+ const struct acl_subject_label *subj, char **path, const int checkglob)
70367+{
70368+ int newglob = checkglob;
70369+ ino_t inode;
70370+ dev_t device;
70371+
70372+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
70373+ as we don't want a / * rule to match instead of the / object
70374+ don't do this for create lookups that call this function though, since they're looking up
70375+ on the parent and thus need globbing checks on all paths
70376+ */
70377+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
70378+ newglob = GR_NO_GLOB;
70379+
70380+ spin_lock(&curr_dentry->d_lock);
70381+ inode = curr_dentry->d_inode->i_ino;
70382+ device = __get_dev(curr_dentry);
70383+ spin_unlock(&curr_dentry->d_lock);
70384+
70385+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
70386+}
70387+
70388+#ifdef CONFIG_HUGETLBFS
70389+static inline bool
70390+is_hugetlbfs_mnt(const struct vfsmount *mnt)
70391+{
70392+ int i;
70393+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
70394+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
70395+ return true;
70396+ }
70397+
70398+ return false;
70399+}
70400+#endif
70401+
70402+static struct acl_object_label *
70403+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70404+ const struct acl_subject_label *subj, char *path, const int checkglob)
70405+{
70406+ struct dentry *dentry = (struct dentry *) l_dentry;
70407+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70408+ struct mount *real_mnt = real_mount(mnt);
70409+ struct acl_object_label *retval;
70410+ struct dentry *parent;
70411+
70412+ read_seqlock_excl(&mount_lock);
70413+ write_seqlock(&rename_lock);
70414+
70415+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
70416+#ifdef CONFIG_NET
70417+ mnt == sock_mnt ||
70418+#endif
70419+#ifdef CONFIG_HUGETLBFS
70420+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
70421+#endif
70422+ /* ignore Eric Biederman */
70423+ IS_PRIVATE(l_dentry->d_inode))) {
70424+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
70425+ goto out;
70426+ }
70427+
70428+ for (;;) {
70429+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70430+ break;
70431+
70432+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70433+ if (!mnt_has_parent(real_mnt))
70434+ break;
70435+
70436+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70437+ if (retval != NULL)
70438+ goto out;
70439+
70440+ dentry = real_mnt->mnt_mountpoint;
70441+ real_mnt = real_mnt->mnt_parent;
70442+ mnt = &real_mnt->mnt;
70443+ continue;
70444+ }
70445+
70446+ parent = dentry->d_parent;
70447+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70448+ if (retval != NULL)
70449+ goto out;
70450+
70451+ dentry = parent;
70452+ }
70453+
70454+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
70455+
70456+ /* gr_real_root is pinned so we don't have to hold a reference */
70457+ if (retval == NULL)
70458+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
70459+out:
70460+ write_sequnlock(&rename_lock);
70461+ read_sequnlock_excl(&mount_lock);
70462+
70463+ BUG_ON(retval == NULL);
70464+
70465+ return retval;
70466+}
70467+
70468+static __inline__ struct acl_object_label *
70469+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70470+ const struct acl_subject_label *subj)
70471+{
70472+ char *path = NULL;
70473+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
70474+}
70475+
70476+static __inline__ struct acl_object_label *
70477+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70478+ const struct acl_subject_label *subj)
70479+{
70480+ char *path = NULL;
70481+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
70482+}
70483+
70484+static __inline__ struct acl_object_label *
70485+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70486+ const struct acl_subject_label *subj, char *path)
70487+{
70488+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
70489+}
70490+
70491+struct acl_subject_label *
70492+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
70493+ const struct acl_role_label *role)
70494+{
70495+ struct dentry *dentry = (struct dentry *) l_dentry;
70496+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
70497+ struct mount *real_mnt = real_mount(mnt);
70498+ struct acl_subject_label *retval;
70499+ struct dentry *parent;
70500+
70501+ read_seqlock_excl(&mount_lock);
70502+ write_seqlock(&rename_lock);
70503+
70504+ for (;;) {
70505+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
70506+ break;
70507+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
70508+ if (!mnt_has_parent(real_mnt))
70509+ break;
70510+
70511+ spin_lock(&dentry->d_lock);
70512+ read_lock(&gr_inode_lock);
70513+ retval =
70514+ lookup_acl_subj_label(dentry->d_inode->i_ino,
70515+ __get_dev(dentry), role);
70516+ read_unlock(&gr_inode_lock);
70517+ spin_unlock(&dentry->d_lock);
70518+ if (retval != NULL)
70519+ goto out;
70520+
70521+ dentry = real_mnt->mnt_mountpoint;
70522+ real_mnt = real_mnt->mnt_parent;
70523+ mnt = &real_mnt->mnt;
70524+ continue;
70525+ }
70526+
70527+ spin_lock(&dentry->d_lock);
70528+ read_lock(&gr_inode_lock);
70529+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70530+ __get_dev(dentry), role);
70531+ read_unlock(&gr_inode_lock);
70532+ parent = dentry->d_parent;
70533+ spin_unlock(&dentry->d_lock);
70534+
70535+ if (retval != NULL)
70536+ goto out;
70537+
70538+ dentry = parent;
70539+ }
70540+
70541+ spin_lock(&dentry->d_lock);
70542+ read_lock(&gr_inode_lock);
70543+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
70544+ __get_dev(dentry), role);
70545+ read_unlock(&gr_inode_lock);
70546+ spin_unlock(&dentry->d_lock);
70547+
70548+ if (unlikely(retval == NULL)) {
70549+ /* gr_real_root is pinned, we don't need to hold a reference */
70550+ read_lock(&gr_inode_lock);
70551+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
70552+ __get_dev(gr_real_root.dentry), role);
70553+ read_unlock(&gr_inode_lock);
70554+ }
70555+out:
70556+ write_sequnlock(&rename_lock);
70557+ read_sequnlock_excl(&mount_lock);
70558+
70559+ BUG_ON(retval == NULL);
70560+
70561+ return retval;
70562+}
70563+
70564+void
70565+assign_special_role(const char *rolename)
70566+{
70567+ struct acl_object_label *obj;
70568+ struct acl_role_label *r;
70569+ struct acl_role_label *assigned = NULL;
70570+ struct task_struct *tsk;
70571+ struct file *filp;
70572+
70573+ FOR_EACH_ROLE_START(r)
70574+ if (!strcmp(rolename, r->rolename) &&
70575+ (r->roletype & GR_ROLE_SPECIAL)) {
70576+ assigned = r;
70577+ break;
70578+ }
70579+ FOR_EACH_ROLE_END(r)
70580+
70581+ if (!assigned)
70582+ return;
70583+
70584+ read_lock(&tasklist_lock);
70585+ read_lock(&grsec_exec_file_lock);
70586+
70587+ tsk = current->real_parent;
70588+ if (tsk == NULL)
70589+ goto out_unlock;
70590+
70591+ filp = tsk->exec_file;
70592+ if (filp == NULL)
70593+ goto out_unlock;
70594+
70595+ tsk->is_writable = 0;
70596+ tsk->inherited = 0;
70597+
70598+ tsk->acl_sp_role = 1;
70599+ tsk->acl_role_id = ++acl_sp_role_value;
70600+ tsk->role = assigned;
70601+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
70602+
70603+ /* ignore additional mmap checks for processes that are writable
70604+ by the default ACL */
70605+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
70606+ if (unlikely(obj->mode & GR_WRITE))
70607+ tsk->is_writable = 1;
70608+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
70609+ if (unlikely(obj->mode & GR_WRITE))
70610+ tsk->is_writable = 1;
70611+
70612+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70613+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
70614+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
70615+#endif
70616+
70617+out_unlock:
70618+ read_unlock(&grsec_exec_file_lock);
70619+ read_unlock(&tasklist_lock);
70620+ return;
70621+}
70622+
70623+
70624+static void
70625+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
70626+{
70627+ struct task_struct *task = current;
70628+ const struct cred *cred = current_cred();
70629+
70630+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
70631+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70632+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70633+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
70634+
70635+ return;
70636+}
70637+
70638+static void
70639+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
70640+{
70641+ struct task_struct *task = current;
70642+ const struct cred *cred = current_cred();
70643+
70644+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70645+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70646+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70647+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
70648+
70649+ return;
70650+}
70651+
70652+static void
70653+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
70654+{
70655+ struct task_struct *task = current;
70656+ const struct cred *cred = current_cred();
70657+
70658+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
70659+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
70660+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
70661+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
70662+
70663+ return;
70664+}
70665+
70666+static void
70667+gr_set_proc_res(struct task_struct *task)
70668+{
70669+ struct acl_subject_label *proc;
70670+ unsigned short i;
70671+
70672+ proc = task->acl;
70673+
70674+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
70675+ return;
70676+
70677+ for (i = 0; i < RLIM_NLIMITS; i++) {
70678+ if (!(proc->resmask & (1U << i)))
70679+ continue;
70680+
70681+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
70682+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
70683+
70684+ if (i == RLIMIT_CPU)
70685+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
70686+ }
70687+
70688+ return;
70689+}
70690+
70691+/* both of the below must be called with
70692+ rcu_read_lock();
70693+ read_lock(&tasklist_lock);
70694+ read_lock(&grsec_exec_file_lock);
70695+*/
70696+
70697+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
70698+{
70699+ char *tmpname;
70700+ struct acl_subject_label *tmpsubj;
70701+ struct file *filp;
70702+ struct name_entry *nmatch;
70703+
70704+ filp = task->exec_file;
70705+ if (filp == NULL)
70706+ return NULL;
70707+
70708+ /* the following is to apply the correct subject
70709+ on binaries running when the RBAC system
70710+ is enabled, when the binaries have been
70711+ replaced or deleted since their execution
70712+ -----
70713+ when the RBAC system starts, the inode/dev
70714+ from exec_file will be one the RBAC system
70715+ is unaware of. It only knows the inode/dev
70716+ of the present file on disk, or the absence
70717+ of it.
70718+ */
70719+
70720+ if (filename)
70721+ nmatch = __lookup_name_entry(state, filename);
70722+ else {
70723+ preempt_disable();
70724+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
70725+
70726+ nmatch = __lookup_name_entry(state, tmpname);
70727+ preempt_enable();
70728+ }
70729+ tmpsubj = NULL;
70730+ if (nmatch) {
70731+ if (nmatch->deleted)
70732+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
70733+ else
70734+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
70735+ }
70736+ /* this also works for the reload case -- if we don't match a potentially inherited subject
70737+ then we fall back to a normal lookup based on the binary's ino/dev
70738+ */
70739+ if (tmpsubj == NULL)
70740+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
70741+
70742+ return tmpsubj;
70743+}
70744+
70745+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
70746+{
70747+ return __gr_get_subject_for_task(&running_polstate, task, filename);
70748+}
70749+
70750+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
70751+{
70752+ struct acl_object_label *obj;
70753+ struct file *filp;
70754+
70755+ filp = task->exec_file;
70756+
70757+ task->acl = subj;
70758+ task->is_writable = 0;
70759+ /* ignore additional mmap checks for processes that are writable
70760+ by the default ACL */
70761+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
70762+ if (unlikely(obj->mode & GR_WRITE))
70763+ task->is_writable = 1;
70764+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
70765+ if (unlikely(obj->mode & GR_WRITE))
70766+ task->is_writable = 1;
70767+
70768+ gr_set_proc_res(task);
70769+
70770+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70771+ 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);
70772+#endif
70773+}
70774+
70775+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
70776+{
70777+ __gr_apply_subject_to_task(&running_polstate, task, subj);
70778+}
70779+
70780+__u32
70781+gr_search_file(const struct dentry * dentry, const __u32 mode,
70782+ const struct vfsmount * mnt)
70783+{
70784+ __u32 retval = mode;
70785+ struct acl_subject_label *curracl;
70786+ struct acl_object_label *currobj;
70787+
70788+ if (unlikely(!(gr_status & GR_READY)))
70789+ return (mode & ~GR_AUDITS);
70790+
70791+ curracl = current->acl;
70792+
70793+ currobj = chk_obj_label(dentry, mnt, curracl);
70794+ retval = currobj->mode & mode;
70795+
70796+ /* if we're opening a specified transfer file for writing
70797+ (e.g. /dev/initctl), then transfer our role to init
70798+ */
70799+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
70800+ current->role->roletype & GR_ROLE_PERSIST)) {
70801+ struct task_struct *task = init_pid_ns.child_reaper;
70802+
70803+ if (task->role != current->role) {
70804+ struct acl_subject_label *subj;
70805+
70806+ task->acl_sp_role = 0;
70807+ task->acl_role_id = current->acl_role_id;
70808+ task->role = current->role;
70809+ rcu_read_lock();
70810+ read_lock(&grsec_exec_file_lock);
70811+ subj = gr_get_subject_for_task(task, NULL);
70812+ gr_apply_subject_to_task(task, subj);
70813+ read_unlock(&grsec_exec_file_lock);
70814+ rcu_read_unlock();
70815+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
70816+ }
70817+ }
70818+
70819+ if (unlikely
70820+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
70821+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
70822+ __u32 new_mode = mode;
70823+
70824+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70825+
70826+ retval = new_mode;
70827+
70828+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
70829+ new_mode |= GR_INHERIT;
70830+
70831+ if (!(mode & GR_NOLEARN))
70832+ gr_log_learn(dentry, mnt, new_mode);
70833+ }
70834+
70835+ return retval;
70836+}
70837+
70838+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
70839+ const struct dentry *parent,
70840+ const struct vfsmount *mnt)
70841+{
70842+ struct name_entry *match;
70843+ struct acl_object_label *matchpo;
70844+ struct acl_subject_label *curracl;
70845+ char *path;
70846+
70847+ if (unlikely(!(gr_status & GR_READY)))
70848+ return NULL;
70849+
70850+ preempt_disable();
70851+ path = gr_to_filename_rbac(new_dentry, mnt);
70852+ match = lookup_name_entry_create(path);
70853+
70854+ curracl = current->acl;
70855+
70856+ if (match) {
70857+ read_lock(&gr_inode_lock);
70858+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
70859+ read_unlock(&gr_inode_lock);
70860+
70861+ if (matchpo) {
70862+ preempt_enable();
70863+ return matchpo;
70864+ }
70865+ }
70866+
70867+ // lookup parent
70868+
70869+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
70870+
70871+ preempt_enable();
70872+ return matchpo;
70873+}
70874+
70875+__u32
70876+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
70877+ const struct vfsmount * mnt, const __u32 mode)
70878+{
70879+ struct acl_object_label *matchpo;
70880+ __u32 retval;
70881+
70882+ if (unlikely(!(gr_status & GR_READY)))
70883+ return (mode & ~GR_AUDITS);
70884+
70885+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
70886+
70887+ retval = matchpo->mode & mode;
70888+
70889+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
70890+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
70891+ __u32 new_mode = mode;
70892+
70893+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
70894+
70895+ gr_log_learn(new_dentry, mnt, new_mode);
70896+ return new_mode;
70897+ }
70898+
70899+ return retval;
70900+}
70901+
70902+__u32
70903+gr_check_link(const struct dentry * new_dentry,
70904+ const struct dentry * parent_dentry,
70905+ const struct vfsmount * parent_mnt,
70906+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
70907+{
70908+ struct acl_object_label *obj;
70909+ __u32 oldmode, newmode;
70910+ __u32 needmode;
70911+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
70912+ GR_DELETE | GR_INHERIT;
70913+
70914+ if (unlikely(!(gr_status & GR_READY)))
70915+ return (GR_CREATE | GR_LINK);
70916+
70917+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
70918+ oldmode = obj->mode;
70919+
70920+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
70921+ newmode = obj->mode;
70922+
70923+ needmode = newmode & checkmodes;
70924+
70925+ // old name for hardlink must have at least the permissions of the new name
70926+ if ((oldmode & needmode) != needmode)
70927+ goto bad;
70928+
70929+ // if old name had restrictions/auditing, make sure the new name does as well
70930+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
70931+
70932+ // don't allow hardlinking of suid/sgid/fcapped files without permission
70933+ if (is_privileged_binary(old_dentry))
70934+ needmode |= GR_SETID;
70935+
70936+ if ((newmode & needmode) != needmode)
70937+ goto bad;
70938+
70939+ // enforce minimum permissions
70940+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
70941+ return newmode;
70942+bad:
70943+ needmode = oldmode;
70944+ if (is_privileged_binary(old_dentry))
70945+ needmode |= GR_SETID;
70946+
70947+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
70948+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
70949+ return (GR_CREATE | GR_LINK);
70950+ } else if (newmode & GR_SUPPRESS)
70951+ return GR_SUPPRESS;
70952+ else
70953+ return 0;
70954+}
70955+
70956+int
70957+gr_check_hidden_task(const struct task_struct *task)
70958+{
70959+ if (unlikely(!(gr_status & GR_READY)))
70960+ return 0;
70961+
70962+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
70963+ return 1;
70964+
70965+ return 0;
70966+}
70967+
70968+int
70969+gr_check_protected_task(const struct task_struct *task)
70970+{
70971+ if (unlikely(!(gr_status & GR_READY) || !task))
70972+ return 0;
70973+
70974+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
70975+ task->acl != current->acl)
70976+ return 1;
70977+
70978+ return 0;
70979+}
70980+
70981+int
70982+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
70983+{
70984+ struct task_struct *p;
70985+ int ret = 0;
70986+
70987+ if (unlikely(!(gr_status & GR_READY) || !pid))
70988+ return ret;
70989+
70990+ read_lock(&tasklist_lock);
70991+ do_each_pid_task(pid, type, p) {
70992+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
70993+ p->acl != current->acl) {
70994+ ret = 1;
70995+ goto out;
70996+ }
70997+ } while_each_pid_task(pid, type, p);
70998+out:
70999+ read_unlock(&tasklist_lock);
71000+
71001+ return ret;
71002+}
71003+
71004+void
71005+gr_copy_label(struct task_struct *tsk)
71006+{
71007+ struct task_struct *p = current;
71008+
71009+ tsk->inherited = p->inherited;
71010+ tsk->acl_sp_role = 0;
71011+ tsk->acl_role_id = p->acl_role_id;
71012+ tsk->acl = p->acl;
71013+ tsk->role = p->role;
71014+ tsk->signal->used_accept = 0;
71015+ tsk->signal->curr_ip = p->signal->curr_ip;
71016+ tsk->signal->saved_ip = p->signal->saved_ip;
71017+ if (p->exec_file)
71018+ get_file(p->exec_file);
71019+ tsk->exec_file = p->exec_file;
71020+ tsk->is_writable = p->is_writable;
71021+ if (unlikely(p->signal->used_accept)) {
71022+ p->signal->curr_ip = 0;
71023+ p->signal->saved_ip = 0;
71024+ }
71025+
71026+ return;
71027+}
71028+
71029+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
71030+
71031+int
71032+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
71033+{
71034+ unsigned int i;
71035+ __u16 num;
71036+ uid_t *uidlist;
71037+ uid_t curuid;
71038+ int realok = 0;
71039+ int effectiveok = 0;
71040+ int fsok = 0;
71041+ uid_t globalreal, globaleffective, globalfs;
71042+
71043+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
71044+ struct user_struct *user;
71045+
71046+ if (!uid_valid(real))
71047+ goto skipit;
71048+
71049+ /* find user based on global namespace */
71050+
71051+ globalreal = GR_GLOBAL_UID(real);
71052+
71053+ user = find_user(make_kuid(&init_user_ns, globalreal));
71054+ if (user == NULL)
71055+ goto skipit;
71056+
71057+ if (gr_process_kernel_setuid_ban(user)) {
71058+ /* for find_user */
71059+ free_uid(user);
71060+ return 1;
71061+ }
71062+
71063+ /* for find_user */
71064+ free_uid(user);
71065+
71066+skipit:
71067+#endif
71068+
71069+ if (unlikely(!(gr_status & GR_READY)))
71070+ return 0;
71071+
71072+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71073+ gr_log_learn_uid_change(real, effective, fs);
71074+
71075+ num = current->acl->user_trans_num;
71076+ uidlist = current->acl->user_transitions;
71077+
71078+ if (uidlist == NULL)
71079+ return 0;
71080+
71081+ if (!uid_valid(real)) {
71082+ realok = 1;
71083+ globalreal = (uid_t)-1;
71084+ } else {
71085+ globalreal = GR_GLOBAL_UID(real);
71086+ }
71087+ if (!uid_valid(effective)) {
71088+ effectiveok = 1;
71089+ globaleffective = (uid_t)-1;
71090+ } else {
71091+ globaleffective = GR_GLOBAL_UID(effective);
71092+ }
71093+ if (!uid_valid(fs)) {
71094+ fsok = 1;
71095+ globalfs = (uid_t)-1;
71096+ } else {
71097+ globalfs = GR_GLOBAL_UID(fs);
71098+ }
71099+
71100+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
71101+ for (i = 0; i < num; i++) {
71102+ curuid = uidlist[i];
71103+ if (globalreal == curuid)
71104+ realok = 1;
71105+ if (globaleffective == curuid)
71106+ effectiveok = 1;
71107+ if (globalfs == curuid)
71108+ fsok = 1;
71109+ }
71110+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
71111+ for (i = 0; i < num; i++) {
71112+ curuid = uidlist[i];
71113+ if (globalreal == curuid)
71114+ break;
71115+ if (globaleffective == curuid)
71116+ break;
71117+ if (globalfs == curuid)
71118+ break;
71119+ }
71120+ /* not in deny list */
71121+ if (i == num) {
71122+ realok = 1;
71123+ effectiveok = 1;
71124+ fsok = 1;
71125+ }
71126+ }
71127+
71128+ if (realok && effectiveok && fsok)
71129+ return 0;
71130+ else {
71131+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71132+ return 1;
71133+ }
71134+}
71135+
71136+int
71137+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
71138+{
71139+ unsigned int i;
71140+ __u16 num;
71141+ gid_t *gidlist;
71142+ gid_t curgid;
71143+ int realok = 0;
71144+ int effectiveok = 0;
71145+ int fsok = 0;
71146+ gid_t globalreal, globaleffective, globalfs;
71147+
71148+ if (unlikely(!(gr_status & GR_READY)))
71149+ return 0;
71150+
71151+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
71152+ gr_log_learn_gid_change(real, effective, fs);
71153+
71154+ num = current->acl->group_trans_num;
71155+ gidlist = current->acl->group_transitions;
71156+
71157+ if (gidlist == NULL)
71158+ return 0;
71159+
71160+ if (!gid_valid(real)) {
71161+ realok = 1;
71162+ globalreal = (gid_t)-1;
71163+ } else {
71164+ globalreal = GR_GLOBAL_GID(real);
71165+ }
71166+ if (!gid_valid(effective)) {
71167+ effectiveok = 1;
71168+ globaleffective = (gid_t)-1;
71169+ } else {
71170+ globaleffective = GR_GLOBAL_GID(effective);
71171+ }
71172+ if (!gid_valid(fs)) {
71173+ fsok = 1;
71174+ globalfs = (gid_t)-1;
71175+ } else {
71176+ globalfs = GR_GLOBAL_GID(fs);
71177+ }
71178+
71179+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
71180+ for (i = 0; i < num; i++) {
71181+ curgid = gidlist[i];
71182+ if (globalreal == curgid)
71183+ realok = 1;
71184+ if (globaleffective == curgid)
71185+ effectiveok = 1;
71186+ if (globalfs == curgid)
71187+ fsok = 1;
71188+ }
71189+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
71190+ for (i = 0; i < num; i++) {
71191+ curgid = gidlist[i];
71192+ if (globalreal == curgid)
71193+ break;
71194+ if (globaleffective == curgid)
71195+ break;
71196+ if (globalfs == curgid)
71197+ break;
71198+ }
71199+ /* not in deny list */
71200+ if (i == num) {
71201+ realok = 1;
71202+ effectiveok = 1;
71203+ fsok = 1;
71204+ }
71205+ }
71206+
71207+ if (realok && effectiveok && fsok)
71208+ return 0;
71209+ else {
71210+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
71211+ return 1;
71212+ }
71213+}
71214+
71215+extern int gr_acl_is_capable(const int cap);
71216+
71217+void
71218+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
71219+{
71220+ struct acl_role_label *role = task->role;
71221+ struct acl_subject_label *subj = NULL;
71222+ struct acl_object_label *obj;
71223+ struct file *filp;
71224+ uid_t uid;
71225+ gid_t gid;
71226+
71227+ if (unlikely(!(gr_status & GR_READY)))
71228+ return;
71229+
71230+ uid = GR_GLOBAL_UID(kuid);
71231+ gid = GR_GLOBAL_GID(kgid);
71232+
71233+ filp = task->exec_file;
71234+
71235+ /* kernel process, we'll give them the kernel role */
71236+ if (unlikely(!filp)) {
71237+ task->role = running_polstate.kernel_role;
71238+ task->acl = running_polstate.kernel_role->root_label;
71239+ return;
71240+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
71241+ /* save the current ip at time of role lookup so that the proper
71242+ IP will be learned for role_allowed_ip */
71243+ task->signal->saved_ip = task->signal->curr_ip;
71244+ role = lookup_acl_role_label(task, uid, gid);
71245+ }
71246+
71247+ /* don't change the role if we're not a privileged process */
71248+ if (role && task->role != role &&
71249+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
71250+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
71251+ return;
71252+
71253+ /* perform subject lookup in possibly new role
71254+ we can use this result below in the case where role == task->role
71255+ */
71256+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
71257+
71258+ /* if we changed uid/gid, but result in the same role
71259+ and are using inheritance, don't lose the inherited subject
71260+ if current subject is other than what normal lookup
71261+ would result in, we arrived via inheritance, don't
71262+ lose subject
71263+ */
71264+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
71265+ (subj == task->acl)))
71266+ task->acl = subj;
71267+
71268+ /* leave task->inherited unaffected */
71269+
71270+ task->role = role;
71271+
71272+ task->is_writable = 0;
71273+
71274+ /* ignore additional mmap checks for processes that are writable
71275+ by the default ACL */
71276+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71277+ if (unlikely(obj->mode & GR_WRITE))
71278+ task->is_writable = 1;
71279+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
71280+ if (unlikely(obj->mode & GR_WRITE))
71281+ task->is_writable = 1;
71282+
71283+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71284+ 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);
71285+#endif
71286+
71287+ gr_set_proc_res(task);
71288+
71289+ return;
71290+}
71291+
71292+int
71293+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
71294+ const int unsafe_flags)
71295+{
71296+ struct task_struct *task = current;
71297+ struct acl_subject_label *newacl;
71298+ struct acl_object_label *obj;
71299+ __u32 retmode;
71300+
71301+ if (unlikely(!(gr_status & GR_READY)))
71302+ return 0;
71303+
71304+ newacl = chk_subj_label(dentry, mnt, task->role);
71305+
71306+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
71307+ did an exec
71308+ */
71309+ rcu_read_lock();
71310+ read_lock(&tasklist_lock);
71311+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
71312+ (task->parent->acl->mode & GR_POVERRIDE))) {
71313+ read_unlock(&tasklist_lock);
71314+ rcu_read_unlock();
71315+ goto skip_check;
71316+ }
71317+ read_unlock(&tasklist_lock);
71318+ rcu_read_unlock();
71319+
71320+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
71321+ !(task->role->roletype & GR_ROLE_GOD) &&
71322+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
71323+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
71324+ if (unsafe_flags & LSM_UNSAFE_SHARE)
71325+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
71326+ else
71327+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
71328+ return -EACCES;
71329+ }
71330+
71331+skip_check:
71332+
71333+ obj = chk_obj_label(dentry, mnt, task->acl);
71334+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
71335+
71336+ if (!(task->acl->mode & GR_INHERITLEARN) &&
71337+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
71338+ if (obj->nested)
71339+ task->acl = obj->nested;
71340+ else
71341+ task->acl = newacl;
71342+ task->inherited = 0;
71343+ } else {
71344+ task->inherited = 1;
71345+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
71346+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
71347+ }
71348+
71349+ task->is_writable = 0;
71350+
71351+ /* ignore additional mmap checks for processes that are writable
71352+ by the default ACL */
71353+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
71354+ if (unlikely(obj->mode & GR_WRITE))
71355+ task->is_writable = 1;
71356+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
71357+ if (unlikely(obj->mode & GR_WRITE))
71358+ task->is_writable = 1;
71359+
71360+ gr_set_proc_res(task);
71361+
71362+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71363+ 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);
71364+#endif
71365+ return 0;
71366+}
71367+
71368+/* always called with valid inodev ptr */
71369+static void
71370+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
71371+{
71372+ struct acl_object_label *matchpo;
71373+ struct acl_subject_label *matchps;
71374+ struct acl_subject_label *subj;
71375+ struct acl_role_label *role;
71376+ unsigned int x;
71377+
71378+ FOR_EACH_ROLE_START(role)
71379+ FOR_EACH_SUBJECT_START(role, subj, x)
71380+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71381+ matchpo->mode |= GR_DELETED;
71382+ FOR_EACH_SUBJECT_END(subj,x)
71383+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
71384+ /* nested subjects aren't in the role's subj_hash table */
71385+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
71386+ matchpo->mode |= GR_DELETED;
71387+ FOR_EACH_NESTED_SUBJECT_END(subj)
71388+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
71389+ matchps->mode |= GR_DELETED;
71390+ FOR_EACH_ROLE_END(role)
71391+
71392+ inodev->nentry->deleted = 1;
71393+
71394+ return;
71395+}
71396+
71397+void
71398+gr_handle_delete(const ino_t ino, const dev_t dev)
71399+{
71400+ struct inodev_entry *inodev;
71401+
71402+ if (unlikely(!(gr_status & GR_READY)))
71403+ return;
71404+
71405+ write_lock(&gr_inode_lock);
71406+ inodev = lookup_inodev_entry(ino, dev);
71407+ if (inodev != NULL)
71408+ do_handle_delete(inodev, ino, dev);
71409+ write_unlock(&gr_inode_lock);
71410+
71411+ return;
71412+}
71413+
71414+static void
71415+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
71416+ const ino_t newinode, const dev_t newdevice,
71417+ struct acl_subject_label *subj)
71418+{
71419+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
71420+ struct acl_object_label *match;
71421+
71422+ match = subj->obj_hash[index];
71423+
71424+ while (match && (match->inode != oldinode ||
71425+ match->device != olddevice ||
71426+ !(match->mode & GR_DELETED)))
71427+ match = match->next;
71428+
71429+ if (match && (match->inode == oldinode)
71430+ && (match->device == olddevice)
71431+ && (match->mode & GR_DELETED)) {
71432+ if (match->prev == NULL) {
71433+ subj->obj_hash[index] = match->next;
71434+ if (match->next != NULL)
71435+ match->next->prev = NULL;
71436+ } else {
71437+ match->prev->next = match->next;
71438+ if (match->next != NULL)
71439+ match->next->prev = match->prev;
71440+ }
71441+ match->prev = NULL;
71442+ match->next = NULL;
71443+ match->inode = newinode;
71444+ match->device = newdevice;
71445+ match->mode &= ~GR_DELETED;
71446+
71447+ insert_acl_obj_label(match, subj);
71448+ }
71449+
71450+ return;
71451+}
71452+
71453+static void
71454+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
71455+ const ino_t newinode, const dev_t newdevice,
71456+ struct acl_role_label *role)
71457+{
71458+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
71459+ struct acl_subject_label *match;
71460+
71461+ match = role->subj_hash[index];
71462+
71463+ while (match && (match->inode != oldinode ||
71464+ match->device != olddevice ||
71465+ !(match->mode & GR_DELETED)))
71466+ match = match->next;
71467+
71468+ if (match && (match->inode == oldinode)
71469+ && (match->device == olddevice)
71470+ && (match->mode & GR_DELETED)) {
71471+ if (match->prev == NULL) {
71472+ role->subj_hash[index] = match->next;
71473+ if (match->next != NULL)
71474+ match->next->prev = NULL;
71475+ } else {
71476+ match->prev->next = match->next;
71477+ if (match->next != NULL)
71478+ match->next->prev = match->prev;
71479+ }
71480+ match->prev = NULL;
71481+ match->next = NULL;
71482+ match->inode = newinode;
71483+ match->device = newdevice;
71484+ match->mode &= ~GR_DELETED;
71485+
71486+ insert_acl_subj_label(match, role);
71487+ }
71488+
71489+ return;
71490+}
71491+
71492+static void
71493+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
71494+ const ino_t newinode, const dev_t newdevice)
71495+{
71496+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
71497+ struct inodev_entry *match;
71498+
71499+ match = running_polstate.inodev_set.i_hash[index];
71500+
71501+ while (match && (match->nentry->inode != oldinode ||
71502+ match->nentry->device != olddevice || !match->nentry->deleted))
71503+ match = match->next;
71504+
71505+ if (match && (match->nentry->inode == oldinode)
71506+ && (match->nentry->device == olddevice) &&
71507+ match->nentry->deleted) {
71508+ if (match->prev == NULL) {
71509+ running_polstate.inodev_set.i_hash[index] = match->next;
71510+ if (match->next != NULL)
71511+ match->next->prev = NULL;
71512+ } else {
71513+ match->prev->next = match->next;
71514+ if (match->next != NULL)
71515+ match->next->prev = match->prev;
71516+ }
71517+ match->prev = NULL;
71518+ match->next = NULL;
71519+ match->nentry->inode = newinode;
71520+ match->nentry->device = newdevice;
71521+ match->nentry->deleted = 0;
71522+
71523+ insert_inodev_entry(match);
71524+ }
71525+
71526+ return;
71527+}
71528+
71529+static void
71530+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
71531+{
71532+ struct acl_subject_label *subj;
71533+ struct acl_role_label *role;
71534+ unsigned int x;
71535+
71536+ FOR_EACH_ROLE_START(role)
71537+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
71538+
71539+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
71540+ if ((subj->inode == ino) && (subj->device == dev)) {
71541+ subj->inode = ino;
71542+ subj->device = dev;
71543+ }
71544+ /* nested subjects aren't in the role's subj_hash table */
71545+ update_acl_obj_label(matchn->inode, matchn->device,
71546+ ino, dev, subj);
71547+ FOR_EACH_NESTED_SUBJECT_END(subj)
71548+ FOR_EACH_SUBJECT_START(role, subj, x)
71549+ update_acl_obj_label(matchn->inode, matchn->device,
71550+ ino, dev, subj);
71551+ FOR_EACH_SUBJECT_END(subj,x)
71552+ FOR_EACH_ROLE_END(role)
71553+
71554+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
71555+
71556+ return;
71557+}
71558+
71559+static void
71560+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
71561+ const struct vfsmount *mnt)
71562+{
71563+ ino_t ino = dentry->d_inode->i_ino;
71564+ dev_t dev = __get_dev(dentry);
71565+
71566+ __do_handle_create(matchn, ino, dev);
71567+
71568+ return;
71569+}
71570+
71571+void
71572+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
71573+{
71574+ struct name_entry *matchn;
71575+
71576+ if (unlikely(!(gr_status & GR_READY)))
71577+ return;
71578+
71579+ preempt_disable();
71580+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
71581+
71582+ if (unlikely((unsigned long)matchn)) {
71583+ write_lock(&gr_inode_lock);
71584+ do_handle_create(matchn, dentry, mnt);
71585+ write_unlock(&gr_inode_lock);
71586+ }
71587+ preempt_enable();
71588+
71589+ return;
71590+}
71591+
71592+void
71593+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
71594+{
71595+ struct name_entry *matchn;
71596+
71597+ if (unlikely(!(gr_status & GR_READY)))
71598+ return;
71599+
71600+ preempt_disable();
71601+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
71602+
71603+ if (unlikely((unsigned long)matchn)) {
71604+ write_lock(&gr_inode_lock);
71605+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
71606+ write_unlock(&gr_inode_lock);
71607+ }
71608+ preempt_enable();
71609+
71610+ return;
71611+}
71612+
71613+void
71614+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
71615+ struct dentry *old_dentry,
71616+ struct dentry *new_dentry,
71617+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
71618+{
71619+ struct name_entry *matchn;
71620+ struct name_entry *matchn2 = NULL;
71621+ struct inodev_entry *inodev;
71622+ struct inode *inode = new_dentry->d_inode;
71623+ ino_t old_ino = old_dentry->d_inode->i_ino;
71624+ dev_t old_dev = __get_dev(old_dentry);
71625+ unsigned int exchange = flags & RENAME_EXCHANGE;
71626+
71627+ /* vfs_rename swaps the name and parent link for old_dentry and
71628+ new_dentry
71629+ at this point, old_dentry has the new name, parent link, and inode
71630+ for the renamed file
71631+ if a file is being replaced by a rename, new_dentry has the inode
71632+ and name for the replaced file
71633+ */
71634+
71635+ if (unlikely(!(gr_status & GR_READY)))
71636+ return;
71637+
71638+ preempt_disable();
71639+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
71640+
71641+ /* exchange cases:
71642+ a filename exists for the source, but not dest
71643+ do a recreate on source
71644+ a filename exists for the dest, but not source
71645+ do a recreate on dest
71646+ a filename exists for both source and dest
71647+ delete source and dest, then create source and dest
71648+ a filename exists for neither source nor dest
71649+ no updates needed
71650+
71651+ the name entry lookups get us the old inode/dev associated with
71652+ each name, so do the deletes first (if possible) so that when
71653+ we do the create, we pick up on the right entries
71654+ */
71655+
71656+ if (exchange)
71657+ matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
71658+
71659+ /* we wouldn't have to check d_inode if it weren't for
71660+ NFS silly-renaming
71661+ */
71662+
71663+ write_lock(&gr_inode_lock);
71664+ if (unlikely((replace || exchange) && inode)) {
71665+ ino_t new_ino = inode->i_ino;
71666+ dev_t new_dev = __get_dev(new_dentry);
71667+
71668+ inodev = lookup_inodev_entry(new_ino, new_dev);
71669+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
71670+ do_handle_delete(inodev, new_ino, new_dev);
71671+ }
71672+
71673+ inodev = lookup_inodev_entry(old_ino, old_dev);
71674+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
71675+ do_handle_delete(inodev, old_ino, old_dev);
71676+
71677+ if (unlikely(matchn != NULL))
71678+ do_handle_create(matchn, old_dentry, mnt);
71679+
71680+ if (unlikely(matchn2 != NULL))
71681+ do_handle_create(matchn2, new_dentry, mnt);
71682+
71683+ write_unlock(&gr_inode_lock);
71684+ preempt_enable();
71685+
71686+ return;
71687+}
71688+
71689+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
71690+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
71691+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
71692+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
71693+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
71694+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
71695+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
71696+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
71697+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
71698+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
71699+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
71700+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
71701+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
71702+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
71703+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
71704+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
71705+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
71706+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
71707+};
71708+
71709+void
71710+gr_learn_resource(const struct task_struct *task,
71711+ const int res, const unsigned long wanted, const int gt)
71712+{
71713+ struct acl_subject_label *acl;
71714+ const struct cred *cred;
71715+
71716+ if (unlikely((gr_status & GR_READY) &&
71717+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
71718+ goto skip_reslog;
71719+
71720+ gr_log_resource(task, res, wanted, gt);
71721+skip_reslog:
71722+
71723+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
71724+ return;
71725+
71726+ acl = task->acl;
71727+
71728+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
71729+ !(acl->resmask & (1U << (unsigned short) res))))
71730+ return;
71731+
71732+ if (wanted >= acl->res[res].rlim_cur) {
71733+ unsigned long res_add;
71734+
71735+ res_add = wanted + res_learn_bumps[res];
71736+
71737+ acl->res[res].rlim_cur = res_add;
71738+
71739+ if (wanted > acl->res[res].rlim_max)
71740+ acl->res[res].rlim_max = res_add;
71741+
71742+ /* only log the subject filename, since resource logging is supported for
71743+ single-subject learning only */
71744+ rcu_read_lock();
71745+ cred = __task_cred(task);
71746+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
71747+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
71748+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
71749+ "", (unsigned long) res, &task->signal->saved_ip);
71750+ rcu_read_unlock();
71751+ }
71752+
71753+ return;
71754+}
71755+EXPORT_SYMBOL_GPL(gr_learn_resource);
71756+#endif
71757+
71758+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
71759+void
71760+pax_set_initial_flags(struct linux_binprm *bprm)
71761+{
71762+ struct task_struct *task = current;
71763+ struct acl_subject_label *proc;
71764+ unsigned long flags;
71765+
71766+ if (unlikely(!(gr_status & GR_READY)))
71767+ return;
71768+
71769+ flags = pax_get_flags(task);
71770+
71771+ proc = task->acl;
71772+
71773+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
71774+ flags &= ~MF_PAX_PAGEEXEC;
71775+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
71776+ flags &= ~MF_PAX_SEGMEXEC;
71777+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
71778+ flags &= ~MF_PAX_RANDMMAP;
71779+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
71780+ flags &= ~MF_PAX_EMUTRAMP;
71781+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
71782+ flags &= ~MF_PAX_MPROTECT;
71783+
71784+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
71785+ flags |= MF_PAX_PAGEEXEC;
71786+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
71787+ flags |= MF_PAX_SEGMEXEC;
71788+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
71789+ flags |= MF_PAX_RANDMMAP;
71790+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
71791+ flags |= MF_PAX_EMUTRAMP;
71792+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
71793+ flags |= MF_PAX_MPROTECT;
71794+
71795+ pax_set_flags(task, flags);
71796+
71797+ return;
71798+}
71799+#endif
71800+
71801+int
71802+gr_handle_proc_ptrace(struct task_struct *task)
71803+{
71804+ struct file *filp;
71805+ struct task_struct *tmp = task;
71806+ struct task_struct *curtemp = current;
71807+ __u32 retmode;
71808+
71809+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71810+ if (unlikely(!(gr_status & GR_READY)))
71811+ return 0;
71812+#endif
71813+
71814+ read_lock(&tasklist_lock);
71815+ read_lock(&grsec_exec_file_lock);
71816+ filp = task->exec_file;
71817+
71818+ while (task_pid_nr(tmp) > 0) {
71819+ if (tmp == curtemp)
71820+ break;
71821+ tmp = tmp->real_parent;
71822+ }
71823+
71824+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71825+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
71826+ read_unlock(&grsec_exec_file_lock);
71827+ read_unlock(&tasklist_lock);
71828+ return 1;
71829+ }
71830+
71831+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71832+ if (!(gr_status & GR_READY)) {
71833+ read_unlock(&grsec_exec_file_lock);
71834+ read_unlock(&tasklist_lock);
71835+ return 0;
71836+ }
71837+#endif
71838+
71839+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
71840+ read_unlock(&grsec_exec_file_lock);
71841+ read_unlock(&tasklist_lock);
71842+
71843+ if (retmode & GR_NOPTRACE)
71844+ return 1;
71845+
71846+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
71847+ && (current->acl != task->acl || (current->acl != current->role->root_label
71848+ && task_pid_nr(current) != task_pid_nr(task))))
71849+ return 1;
71850+
71851+ return 0;
71852+}
71853+
71854+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
71855+{
71856+ if (unlikely(!(gr_status & GR_READY)))
71857+ return;
71858+
71859+ if (!(current->role->roletype & GR_ROLE_GOD))
71860+ return;
71861+
71862+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
71863+ p->role->rolename, gr_task_roletype_to_char(p),
71864+ p->acl->filename);
71865+}
71866+
71867+int
71868+gr_handle_ptrace(struct task_struct *task, const long request)
71869+{
71870+ struct task_struct *tmp = task;
71871+ struct task_struct *curtemp = current;
71872+ __u32 retmode;
71873+
71874+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
71875+ if (unlikely(!(gr_status & GR_READY)))
71876+ return 0;
71877+#endif
71878+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
71879+ read_lock(&tasklist_lock);
71880+ while (task_pid_nr(tmp) > 0) {
71881+ if (tmp == curtemp)
71882+ break;
71883+ tmp = tmp->real_parent;
71884+ }
71885+
71886+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
71887+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
71888+ read_unlock(&tasklist_lock);
71889+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71890+ return 1;
71891+ }
71892+ read_unlock(&tasklist_lock);
71893+ }
71894+
71895+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
71896+ if (!(gr_status & GR_READY))
71897+ return 0;
71898+#endif
71899+
71900+ read_lock(&grsec_exec_file_lock);
71901+ if (unlikely(!task->exec_file)) {
71902+ read_unlock(&grsec_exec_file_lock);
71903+ return 0;
71904+ }
71905+
71906+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
71907+ read_unlock(&grsec_exec_file_lock);
71908+
71909+ if (retmode & GR_NOPTRACE) {
71910+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71911+ return 1;
71912+ }
71913+
71914+ if (retmode & GR_PTRACERD) {
71915+ switch (request) {
71916+ case PTRACE_SEIZE:
71917+ case PTRACE_POKETEXT:
71918+ case PTRACE_POKEDATA:
71919+ case PTRACE_POKEUSR:
71920+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
71921+ case PTRACE_SETREGS:
71922+ case PTRACE_SETFPREGS:
71923+#endif
71924+#ifdef CONFIG_X86
71925+ case PTRACE_SETFPXREGS:
71926+#endif
71927+#ifdef CONFIG_ALTIVEC
71928+ case PTRACE_SETVRREGS:
71929+#endif
71930+ return 1;
71931+ default:
71932+ return 0;
71933+ }
71934+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
71935+ !(current->role->roletype & GR_ROLE_GOD) &&
71936+ (current->acl != task->acl)) {
71937+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
71938+ return 1;
71939+ }
71940+
71941+ return 0;
71942+}
71943+
71944+static int is_writable_mmap(const struct file *filp)
71945+{
71946+ struct task_struct *task = current;
71947+ struct acl_object_label *obj, *obj2;
71948+
71949+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
71950+ !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))) {
71951+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
71952+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
71953+ task->role->root_label);
71954+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
71955+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
71956+ return 1;
71957+ }
71958+ }
71959+ return 0;
71960+}
71961+
71962+int
71963+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
71964+{
71965+ __u32 mode;
71966+
71967+ if (unlikely(!file || !(prot & PROT_EXEC)))
71968+ return 1;
71969+
71970+ if (is_writable_mmap(file))
71971+ return 0;
71972+
71973+ mode =
71974+ gr_search_file(file->f_path.dentry,
71975+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
71976+ file->f_path.mnt);
71977+
71978+ if (!gr_tpe_allow(file))
71979+ return 0;
71980+
71981+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
71982+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71983+ return 0;
71984+ } else if (unlikely(!(mode & GR_EXEC))) {
71985+ return 0;
71986+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
71987+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
71988+ return 1;
71989+ }
71990+
71991+ return 1;
71992+}
71993+
71994+int
71995+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
71996+{
71997+ __u32 mode;
71998+
71999+ if (unlikely(!file || !(prot & PROT_EXEC)))
72000+ return 1;
72001+
72002+ if (is_writable_mmap(file))
72003+ return 0;
72004+
72005+ mode =
72006+ gr_search_file(file->f_path.dentry,
72007+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
72008+ file->f_path.mnt);
72009+
72010+ if (!gr_tpe_allow(file))
72011+ return 0;
72012+
72013+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
72014+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72015+ return 0;
72016+ } else if (unlikely(!(mode & GR_EXEC))) {
72017+ return 0;
72018+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
72019+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
72020+ return 1;
72021+ }
72022+
72023+ return 1;
72024+}
72025+
72026+void
72027+gr_acl_handle_psacct(struct task_struct *task, const long code)
72028+{
72029+ unsigned long runtime, cputime;
72030+ cputime_t utime, stime;
72031+ unsigned int wday, cday;
72032+ __u8 whr, chr;
72033+ __u8 wmin, cmin;
72034+ __u8 wsec, csec;
72035+ struct timespec curtime, starttime;
72036+
72037+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
72038+ !(task->acl->mode & GR_PROCACCT)))
72039+ return;
72040+
72041+ curtime = ns_to_timespec(ktime_get_ns());
72042+ starttime = ns_to_timespec(task->start_time);
72043+ runtime = curtime.tv_sec - starttime.tv_sec;
72044+ wday = runtime / (60 * 60 * 24);
72045+ runtime -= wday * (60 * 60 * 24);
72046+ whr = runtime / (60 * 60);
72047+ runtime -= whr * (60 * 60);
72048+ wmin = runtime / 60;
72049+ runtime -= wmin * 60;
72050+ wsec = runtime;
72051+
72052+ task_cputime(task, &utime, &stime);
72053+ cputime = cputime_to_secs(utime + stime);
72054+ cday = cputime / (60 * 60 * 24);
72055+ cputime -= cday * (60 * 60 * 24);
72056+ chr = cputime / (60 * 60);
72057+ cputime -= chr * (60 * 60);
72058+ cmin = cputime / 60;
72059+ cputime -= cmin * 60;
72060+ csec = cputime;
72061+
72062+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
72063+
72064+ return;
72065+}
72066+
72067+#ifdef CONFIG_TASKSTATS
72068+int gr_is_taskstats_denied(int pid)
72069+{
72070+ struct task_struct *task;
72071+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72072+ const struct cred *cred;
72073+#endif
72074+ int ret = 0;
72075+
72076+ /* restrict taskstats viewing to un-chrooted root users
72077+ who have the 'view' subject flag if the RBAC system is enabled
72078+ */
72079+
72080+ rcu_read_lock();
72081+ read_lock(&tasklist_lock);
72082+ task = find_task_by_vpid(pid);
72083+ if (task) {
72084+#ifdef CONFIG_GRKERNSEC_CHROOT
72085+ if (proc_is_chrooted(task))
72086+ ret = -EACCES;
72087+#endif
72088+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72089+ cred = __task_cred(task);
72090+#ifdef CONFIG_GRKERNSEC_PROC_USER
72091+ if (gr_is_global_nonroot(cred->uid))
72092+ ret = -EACCES;
72093+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
72094+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
72095+ ret = -EACCES;
72096+#endif
72097+#endif
72098+ if (gr_status & GR_READY) {
72099+ if (!(task->acl->mode & GR_VIEW))
72100+ ret = -EACCES;
72101+ }
72102+ } else
72103+ ret = -ENOENT;
72104+
72105+ read_unlock(&tasklist_lock);
72106+ rcu_read_unlock();
72107+
72108+ return ret;
72109+}
72110+#endif
72111+
72112+/* AUXV entries are filled via a descendant of search_binary_handler
72113+ after we've already applied the subject for the target
72114+*/
72115+int gr_acl_enable_at_secure(void)
72116+{
72117+ if (unlikely(!(gr_status & GR_READY)))
72118+ return 0;
72119+
72120+ if (current->acl->mode & GR_ATSECURE)
72121+ return 1;
72122+
72123+ return 0;
72124+}
72125+
72126+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
72127+{
72128+ struct task_struct *task = current;
72129+ struct dentry *dentry = file->f_path.dentry;
72130+ struct vfsmount *mnt = file->f_path.mnt;
72131+ struct acl_object_label *obj, *tmp;
72132+ struct acl_subject_label *subj;
72133+ unsigned int bufsize;
72134+ int is_not_root;
72135+ char *path;
72136+ dev_t dev = __get_dev(dentry);
72137+
72138+ if (unlikely(!(gr_status & GR_READY)))
72139+ return 1;
72140+
72141+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
72142+ return 1;
72143+
72144+ /* ignore Eric Biederman */
72145+ if (IS_PRIVATE(dentry->d_inode))
72146+ return 1;
72147+
72148+ subj = task->acl;
72149+ read_lock(&gr_inode_lock);
72150+ do {
72151+ obj = lookup_acl_obj_label(ino, dev, subj);
72152+ if (obj != NULL) {
72153+ read_unlock(&gr_inode_lock);
72154+ return (obj->mode & GR_FIND) ? 1 : 0;
72155+ }
72156+ } while ((subj = subj->parent_subject));
72157+ read_unlock(&gr_inode_lock);
72158+
72159+ /* this is purely an optimization since we're looking for an object
72160+ for the directory we're doing a readdir on
72161+ if it's possible for any globbed object to match the entry we're
72162+ filling into the directory, then the object we find here will be
72163+ an anchor point with attached globbed objects
72164+ */
72165+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
72166+ if (obj->globbed == NULL)
72167+ return (obj->mode & GR_FIND) ? 1 : 0;
72168+
72169+ is_not_root = ((obj->filename[0] == '/') &&
72170+ (obj->filename[1] == '\0')) ? 0 : 1;
72171+ bufsize = PAGE_SIZE - namelen - is_not_root;
72172+
72173+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
72174+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
72175+ return 1;
72176+
72177+ preempt_disable();
72178+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
72179+ bufsize);
72180+
72181+ bufsize = strlen(path);
72182+
72183+ /* if base is "/", don't append an additional slash */
72184+ if (is_not_root)
72185+ *(path + bufsize) = '/';
72186+ memcpy(path + bufsize + is_not_root, name, namelen);
72187+ *(path + bufsize + namelen + is_not_root) = '\0';
72188+
72189+ tmp = obj->globbed;
72190+ while (tmp) {
72191+ if (!glob_match(tmp->filename, path)) {
72192+ preempt_enable();
72193+ return (tmp->mode & GR_FIND) ? 1 : 0;
72194+ }
72195+ tmp = tmp->next;
72196+ }
72197+ preempt_enable();
72198+ return (obj->mode & GR_FIND) ? 1 : 0;
72199+}
72200+
72201+void gr_put_exec_file(struct task_struct *task)
72202+{
72203+ struct file *filp;
72204+
72205+ write_lock(&grsec_exec_file_lock);
72206+ filp = task->exec_file;
72207+ task->exec_file = NULL;
72208+ write_unlock(&grsec_exec_file_lock);
72209+
72210+ if (filp)
72211+ fput(filp);
72212+
72213+ return;
72214+}
72215+
72216+
72217+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
72218+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
72219+#endif
72220+#ifdef CONFIG_SECURITY
72221+EXPORT_SYMBOL_GPL(gr_check_user_change);
72222+EXPORT_SYMBOL_GPL(gr_check_group_change);
72223+#endif
72224+
72225diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
72226new file mode 100644
72227index 0000000..18ffbbd
72228--- /dev/null
72229+++ b/grsecurity/gracl_alloc.c
72230@@ -0,0 +1,105 @@
72231+#include <linux/kernel.h>
72232+#include <linux/mm.h>
72233+#include <linux/slab.h>
72234+#include <linux/vmalloc.h>
72235+#include <linux/gracl.h>
72236+#include <linux/grsecurity.h>
72237+
72238+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
72239+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
72240+
72241+static __inline__ int
72242+alloc_pop(void)
72243+{
72244+ if (current_alloc_state->alloc_stack_next == 1)
72245+ return 0;
72246+
72247+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
72248+
72249+ current_alloc_state->alloc_stack_next--;
72250+
72251+ return 1;
72252+}
72253+
72254+static __inline__ int
72255+alloc_push(void *buf)
72256+{
72257+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
72258+ return 1;
72259+
72260+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
72261+
72262+ current_alloc_state->alloc_stack_next++;
72263+
72264+ return 0;
72265+}
72266+
72267+void *
72268+acl_alloc(unsigned long len)
72269+{
72270+ void *ret = NULL;
72271+
72272+ if (!len || len > PAGE_SIZE)
72273+ goto out;
72274+
72275+ ret = kmalloc(len, GFP_KERNEL);
72276+
72277+ if (ret) {
72278+ if (alloc_push(ret)) {
72279+ kfree(ret);
72280+ ret = NULL;
72281+ }
72282+ }
72283+
72284+out:
72285+ return ret;
72286+}
72287+
72288+void *
72289+acl_alloc_num(unsigned long num, unsigned long len)
72290+{
72291+ if (!len || (num > (PAGE_SIZE / len)))
72292+ return NULL;
72293+
72294+ return acl_alloc(num * len);
72295+}
72296+
72297+void
72298+acl_free_all(void)
72299+{
72300+ if (!current_alloc_state->alloc_stack)
72301+ return;
72302+
72303+ while (alloc_pop()) ;
72304+
72305+ if (current_alloc_state->alloc_stack) {
72306+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
72307+ kfree(current_alloc_state->alloc_stack);
72308+ else
72309+ vfree(current_alloc_state->alloc_stack);
72310+ }
72311+
72312+ current_alloc_state->alloc_stack = NULL;
72313+ current_alloc_state->alloc_stack_size = 1;
72314+ current_alloc_state->alloc_stack_next = 1;
72315+
72316+ return;
72317+}
72318+
72319+int
72320+acl_alloc_stack_init(unsigned long size)
72321+{
72322+ if ((size * sizeof (void *)) <= PAGE_SIZE)
72323+ current_alloc_state->alloc_stack =
72324+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
72325+ else
72326+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
72327+
72328+ current_alloc_state->alloc_stack_size = size;
72329+ current_alloc_state->alloc_stack_next = 1;
72330+
72331+ if (!current_alloc_state->alloc_stack)
72332+ return 0;
72333+ else
72334+ return 1;
72335+}
72336diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
72337new file mode 100644
72338index 0000000..1a94c11
72339--- /dev/null
72340+++ b/grsecurity/gracl_cap.c
72341@@ -0,0 +1,127 @@
72342+#include <linux/kernel.h>
72343+#include <linux/module.h>
72344+#include <linux/sched.h>
72345+#include <linux/gracl.h>
72346+#include <linux/grsecurity.h>
72347+#include <linux/grinternal.h>
72348+
72349+extern const char *captab_log[];
72350+extern int captab_log_entries;
72351+
72352+int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
72353+{
72354+ struct acl_subject_label *curracl;
72355+
72356+ if (!gr_acl_is_enabled())
72357+ return 1;
72358+
72359+ curracl = task->acl;
72360+
72361+ if (curracl->mode & (GR_LEARN | GR_INHERITLEARN)) {
72362+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
72363+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
72364+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
72365+ gr_to_filename(task->exec_file->f_path.dentry,
72366+ task->exec_file->f_path.mnt) : curracl->filename,
72367+ curracl->filename, 0UL,
72368+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
72369+ return 1;
72370+ }
72371+
72372+ return 0;
72373+}
72374+
72375+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72376+{
72377+ struct acl_subject_label *curracl;
72378+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72379+ kernel_cap_t cap_audit = __cap_empty_set;
72380+
72381+ if (!gr_acl_is_enabled())
72382+ return 1;
72383+
72384+ curracl = task->acl;
72385+
72386+ cap_drop = curracl->cap_lower;
72387+ cap_mask = curracl->cap_mask;
72388+ cap_audit = curracl->cap_invert_audit;
72389+
72390+ while ((curracl = curracl->parent_subject)) {
72391+ /* if the cap isn't specified in the current computed mask but is specified in the
72392+ current level subject, and is lowered in the current level subject, then add
72393+ it to the set of dropped capabilities
72394+ otherwise, add the current level subject's mask to the current computed mask
72395+ */
72396+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72397+ cap_raise(cap_mask, cap);
72398+ if (cap_raised(curracl->cap_lower, cap))
72399+ cap_raise(cap_drop, cap);
72400+ if (cap_raised(curracl->cap_invert_audit, cap))
72401+ cap_raise(cap_audit, cap);
72402+ }
72403+ }
72404+
72405+ if (!cap_raised(cap_drop, cap)) {
72406+ if (cap_raised(cap_audit, cap))
72407+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
72408+ return 1;
72409+ }
72410+
72411+ /* only learn the capability use if the process has the capability in the
72412+ general case, the two uses in sys.c of gr_learn_cap are an exception
72413+ to this rule to ensure any role transition involves what the full-learned
72414+ policy believes in a privileged process
72415+ */
72416+ if (cap_raised(cred->cap_effective, cap) && gr_learn_cap(task, cred, cap))
72417+ return 1;
72418+
72419+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
72420+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
72421+
72422+ return 0;
72423+}
72424+
72425+int
72426+gr_acl_is_capable(const int cap)
72427+{
72428+ return gr_task_acl_is_capable(current, current_cred(), cap);
72429+}
72430+
72431+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
72432+{
72433+ struct acl_subject_label *curracl;
72434+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
72435+
72436+ if (!gr_acl_is_enabled())
72437+ return 1;
72438+
72439+ curracl = task->acl;
72440+
72441+ cap_drop = curracl->cap_lower;
72442+ cap_mask = curracl->cap_mask;
72443+
72444+ while ((curracl = curracl->parent_subject)) {
72445+ /* if the cap isn't specified in the current computed mask but is specified in the
72446+ current level subject, and is lowered in the current level subject, then add
72447+ it to the set of dropped capabilities
72448+ otherwise, add the current level subject's mask to the current computed mask
72449+ */
72450+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
72451+ cap_raise(cap_mask, cap);
72452+ if (cap_raised(curracl->cap_lower, cap))
72453+ cap_raise(cap_drop, cap);
72454+ }
72455+ }
72456+
72457+ if (!cap_raised(cap_drop, cap))
72458+ return 1;
72459+
72460+ return 0;
72461+}
72462+
72463+int
72464+gr_acl_is_capable_nolog(const int cap)
72465+{
72466+ return gr_task_acl_is_capable_nolog(current, cap);
72467+}
72468+
72469diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
72470new file mode 100644
72471index 0000000..ca25605
72472--- /dev/null
72473+++ b/grsecurity/gracl_compat.c
72474@@ -0,0 +1,270 @@
72475+#include <linux/kernel.h>
72476+#include <linux/gracl.h>
72477+#include <linux/compat.h>
72478+#include <linux/gracl_compat.h>
72479+
72480+#include <asm/uaccess.h>
72481+
72482+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
72483+{
72484+ struct gr_arg_wrapper_compat uwrapcompat;
72485+
72486+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
72487+ return -EFAULT;
72488+
72489+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
72490+ (uwrapcompat.version != 0x2901)) ||
72491+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
72492+ return -EINVAL;
72493+
72494+ uwrap->arg = compat_ptr(uwrapcompat.arg);
72495+ uwrap->version = uwrapcompat.version;
72496+ uwrap->size = sizeof(struct gr_arg);
72497+
72498+ return 0;
72499+}
72500+
72501+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
72502+{
72503+ struct gr_arg_compat argcompat;
72504+
72505+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
72506+ return -EFAULT;
72507+
72508+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
72509+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
72510+ arg->role_db.num_roles = argcompat.role_db.num_roles;
72511+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
72512+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
72513+ arg->role_db.num_objects = argcompat.role_db.num_objects;
72514+
72515+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
72516+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
72517+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
72518+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
72519+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
72520+ arg->segv_device = argcompat.segv_device;
72521+ arg->segv_inode = argcompat.segv_inode;
72522+ arg->segv_uid = argcompat.segv_uid;
72523+ arg->num_sprole_pws = argcompat.num_sprole_pws;
72524+ arg->mode = argcompat.mode;
72525+
72526+ return 0;
72527+}
72528+
72529+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
72530+{
72531+ struct acl_object_label_compat objcompat;
72532+
72533+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
72534+ return -EFAULT;
72535+
72536+ obj->filename = compat_ptr(objcompat.filename);
72537+ obj->inode = objcompat.inode;
72538+ obj->device = objcompat.device;
72539+ obj->mode = objcompat.mode;
72540+
72541+ obj->nested = compat_ptr(objcompat.nested);
72542+ obj->globbed = compat_ptr(objcompat.globbed);
72543+
72544+ obj->prev = compat_ptr(objcompat.prev);
72545+ obj->next = compat_ptr(objcompat.next);
72546+
72547+ return 0;
72548+}
72549+
72550+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
72551+{
72552+ unsigned int i;
72553+ struct acl_subject_label_compat subjcompat;
72554+
72555+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
72556+ return -EFAULT;
72557+
72558+ subj->filename = compat_ptr(subjcompat.filename);
72559+ subj->inode = subjcompat.inode;
72560+ subj->device = subjcompat.device;
72561+ subj->mode = subjcompat.mode;
72562+ subj->cap_mask = subjcompat.cap_mask;
72563+ subj->cap_lower = subjcompat.cap_lower;
72564+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
72565+
72566+ for (i = 0; i < GR_NLIMITS; i++) {
72567+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
72568+ subj->res[i].rlim_cur = RLIM_INFINITY;
72569+ else
72570+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
72571+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
72572+ subj->res[i].rlim_max = RLIM_INFINITY;
72573+ else
72574+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
72575+ }
72576+ subj->resmask = subjcompat.resmask;
72577+
72578+ subj->user_trans_type = subjcompat.user_trans_type;
72579+ subj->group_trans_type = subjcompat.group_trans_type;
72580+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
72581+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
72582+ subj->user_trans_num = subjcompat.user_trans_num;
72583+ subj->group_trans_num = subjcompat.group_trans_num;
72584+
72585+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
72586+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
72587+ subj->ip_type = subjcompat.ip_type;
72588+ subj->ips = compat_ptr(subjcompat.ips);
72589+ subj->ip_num = subjcompat.ip_num;
72590+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
72591+
72592+ subj->crashes = subjcompat.crashes;
72593+ subj->expires = subjcompat.expires;
72594+
72595+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
72596+ subj->hash = compat_ptr(subjcompat.hash);
72597+ subj->prev = compat_ptr(subjcompat.prev);
72598+ subj->next = compat_ptr(subjcompat.next);
72599+
72600+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
72601+ subj->obj_hash_size = subjcompat.obj_hash_size;
72602+ subj->pax_flags = subjcompat.pax_flags;
72603+
72604+ return 0;
72605+}
72606+
72607+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
72608+{
72609+ struct acl_role_label_compat rolecompat;
72610+
72611+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
72612+ return -EFAULT;
72613+
72614+ role->rolename = compat_ptr(rolecompat.rolename);
72615+ role->uidgid = rolecompat.uidgid;
72616+ role->roletype = rolecompat.roletype;
72617+
72618+ role->auth_attempts = rolecompat.auth_attempts;
72619+ role->expires = rolecompat.expires;
72620+
72621+ role->root_label = compat_ptr(rolecompat.root_label);
72622+ role->hash = compat_ptr(rolecompat.hash);
72623+
72624+ role->prev = compat_ptr(rolecompat.prev);
72625+ role->next = compat_ptr(rolecompat.next);
72626+
72627+ role->transitions = compat_ptr(rolecompat.transitions);
72628+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
72629+ role->domain_children = compat_ptr(rolecompat.domain_children);
72630+ role->domain_child_num = rolecompat.domain_child_num;
72631+
72632+ role->umask = rolecompat.umask;
72633+
72634+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
72635+ role->subj_hash_size = rolecompat.subj_hash_size;
72636+
72637+ return 0;
72638+}
72639+
72640+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
72641+{
72642+ struct role_allowed_ip_compat roleip_compat;
72643+
72644+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
72645+ return -EFAULT;
72646+
72647+ roleip->addr = roleip_compat.addr;
72648+ roleip->netmask = roleip_compat.netmask;
72649+
72650+ roleip->prev = compat_ptr(roleip_compat.prev);
72651+ roleip->next = compat_ptr(roleip_compat.next);
72652+
72653+ return 0;
72654+}
72655+
72656+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
72657+{
72658+ struct role_transition_compat trans_compat;
72659+
72660+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
72661+ return -EFAULT;
72662+
72663+ trans->rolename = compat_ptr(trans_compat.rolename);
72664+
72665+ trans->prev = compat_ptr(trans_compat.prev);
72666+ trans->next = compat_ptr(trans_compat.next);
72667+
72668+ return 0;
72669+
72670+}
72671+
72672+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
72673+{
72674+ struct gr_hash_struct_compat hash_compat;
72675+
72676+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
72677+ return -EFAULT;
72678+
72679+ hash->table = compat_ptr(hash_compat.table);
72680+ hash->nametable = compat_ptr(hash_compat.nametable);
72681+ hash->first = compat_ptr(hash_compat.first);
72682+
72683+ hash->table_size = hash_compat.table_size;
72684+ hash->used_size = hash_compat.used_size;
72685+
72686+ hash->type = hash_compat.type;
72687+
72688+ return 0;
72689+}
72690+
72691+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
72692+{
72693+ compat_uptr_t ptrcompat;
72694+
72695+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
72696+ return -EFAULT;
72697+
72698+ *(void **)ptr = compat_ptr(ptrcompat);
72699+
72700+ return 0;
72701+}
72702+
72703+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
72704+{
72705+ struct acl_ip_label_compat ip_compat;
72706+
72707+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
72708+ return -EFAULT;
72709+
72710+ ip->iface = compat_ptr(ip_compat.iface);
72711+ ip->addr = ip_compat.addr;
72712+ ip->netmask = ip_compat.netmask;
72713+ ip->low = ip_compat.low;
72714+ ip->high = ip_compat.high;
72715+ ip->mode = ip_compat.mode;
72716+ ip->type = ip_compat.type;
72717+
72718+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
72719+
72720+ ip->prev = compat_ptr(ip_compat.prev);
72721+ ip->next = compat_ptr(ip_compat.next);
72722+
72723+ return 0;
72724+}
72725+
72726+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
72727+{
72728+ struct sprole_pw_compat pw_compat;
72729+
72730+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
72731+ return -EFAULT;
72732+
72733+ pw->rolename = compat_ptr(pw_compat.rolename);
72734+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
72735+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
72736+
72737+ return 0;
72738+}
72739+
72740+size_t get_gr_arg_wrapper_size_compat(void)
72741+{
72742+ return sizeof(struct gr_arg_wrapper_compat);
72743+}
72744+
72745diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
72746new file mode 100644
72747index 0000000..4008fdc
72748--- /dev/null
72749+++ b/grsecurity/gracl_fs.c
72750@@ -0,0 +1,445 @@
72751+#include <linux/kernel.h>
72752+#include <linux/sched.h>
72753+#include <linux/types.h>
72754+#include <linux/fs.h>
72755+#include <linux/file.h>
72756+#include <linux/stat.h>
72757+#include <linux/grsecurity.h>
72758+#include <linux/grinternal.h>
72759+#include <linux/gracl.h>
72760+
72761+umode_t
72762+gr_acl_umask(void)
72763+{
72764+ if (unlikely(!gr_acl_is_enabled()))
72765+ return 0;
72766+
72767+ return current->role->umask;
72768+}
72769+
72770+__u32
72771+gr_acl_handle_hidden_file(const struct dentry * dentry,
72772+ const struct vfsmount * mnt)
72773+{
72774+ __u32 mode;
72775+
72776+ if (unlikely(d_is_negative(dentry)))
72777+ return GR_FIND;
72778+
72779+ mode =
72780+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
72781+
72782+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
72783+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72784+ return mode;
72785+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
72786+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
72787+ return 0;
72788+ } else if (unlikely(!(mode & GR_FIND)))
72789+ return 0;
72790+
72791+ return GR_FIND;
72792+}
72793+
72794+__u32
72795+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
72796+ int acc_mode)
72797+{
72798+ __u32 reqmode = GR_FIND;
72799+ __u32 mode;
72800+
72801+ if (unlikely(d_is_negative(dentry)))
72802+ return reqmode;
72803+
72804+ if (acc_mode & MAY_APPEND)
72805+ reqmode |= GR_APPEND;
72806+ else if (acc_mode & MAY_WRITE)
72807+ reqmode |= GR_WRITE;
72808+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
72809+ reqmode |= GR_READ;
72810+
72811+ mode =
72812+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72813+ mnt);
72814+
72815+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72816+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72817+ reqmode & GR_READ ? " reading" : "",
72818+ reqmode & GR_WRITE ? " writing" : reqmode &
72819+ GR_APPEND ? " appending" : "");
72820+ return reqmode;
72821+ } else
72822+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72823+ {
72824+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
72825+ reqmode & GR_READ ? " reading" : "",
72826+ reqmode & GR_WRITE ? " writing" : reqmode &
72827+ GR_APPEND ? " appending" : "");
72828+ return 0;
72829+ } else if (unlikely((mode & reqmode) != reqmode))
72830+ return 0;
72831+
72832+ return reqmode;
72833+}
72834+
72835+__u32
72836+gr_acl_handle_creat(const struct dentry * dentry,
72837+ const struct dentry * p_dentry,
72838+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
72839+ const int imode)
72840+{
72841+ __u32 reqmode = GR_WRITE | GR_CREATE;
72842+ __u32 mode;
72843+
72844+ if (acc_mode & MAY_APPEND)
72845+ reqmode |= GR_APPEND;
72846+ // if a directory was required or the directory already exists, then
72847+ // don't count this open as a read
72848+ if ((acc_mode & MAY_READ) &&
72849+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
72850+ reqmode |= GR_READ;
72851+ if ((open_flags & O_CREAT) &&
72852+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
72853+ reqmode |= GR_SETID;
72854+
72855+ mode =
72856+ gr_check_create(dentry, p_dentry, p_mnt,
72857+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
72858+
72859+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72860+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72861+ reqmode & GR_READ ? " reading" : "",
72862+ reqmode & GR_WRITE ? " writing" : reqmode &
72863+ GR_APPEND ? " appending" : "");
72864+ return reqmode;
72865+ } else
72866+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72867+ {
72868+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
72869+ reqmode & GR_READ ? " reading" : "",
72870+ reqmode & GR_WRITE ? " writing" : reqmode &
72871+ GR_APPEND ? " appending" : "");
72872+ return 0;
72873+ } else if (unlikely((mode & reqmode) != reqmode))
72874+ return 0;
72875+
72876+ return reqmode;
72877+}
72878+
72879+__u32
72880+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
72881+ const int fmode)
72882+{
72883+ __u32 mode, reqmode = GR_FIND;
72884+
72885+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
72886+ reqmode |= GR_EXEC;
72887+ if (fmode & S_IWOTH)
72888+ reqmode |= GR_WRITE;
72889+ if (fmode & S_IROTH)
72890+ reqmode |= GR_READ;
72891+
72892+ mode =
72893+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
72894+ mnt);
72895+
72896+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
72897+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72898+ reqmode & GR_READ ? " reading" : "",
72899+ reqmode & GR_WRITE ? " writing" : "",
72900+ reqmode & GR_EXEC ? " executing" : "");
72901+ return reqmode;
72902+ } else
72903+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
72904+ {
72905+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
72906+ reqmode & GR_READ ? " reading" : "",
72907+ reqmode & GR_WRITE ? " writing" : "",
72908+ reqmode & GR_EXEC ? " executing" : "");
72909+ return 0;
72910+ } else if (unlikely((mode & reqmode) != reqmode))
72911+ return 0;
72912+
72913+ return reqmode;
72914+}
72915+
72916+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
72917+{
72918+ __u32 mode;
72919+
72920+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
72921+
72922+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
72923+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
72924+ return mode;
72925+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
72926+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
72927+ return 0;
72928+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
72929+ return 0;
72930+
72931+ return (reqmode);
72932+}
72933+
72934+__u32
72935+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
72936+{
72937+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
72938+}
72939+
72940+__u32
72941+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
72942+{
72943+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
72944+}
72945+
72946+__u32
72947+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
72948+{
72949+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
72950+}
72951+
72952+__u32
72953+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
72954+{
72955+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
72956+}
72957+
72958+__u32
72959+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
72960+ umode_t *modeptr)
72961+{
72962+ umode_t mode;
72963+
72964+ *modeptr &= ~gr_acl_umask();
72965+ mode = *modeptr;
72966+
72967+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
72968+ return 1;
72969+
72970+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
72971+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
72972+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
72973+ GR_CHMOD_ACL_MSG);
72974+ } else {
72975+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
72976+ }
72977+}
72978+
72979+__u32
72980+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
72981+{
72982+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
72983+}
72984+
72985+__u32
72986+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
72987+{
72988+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
72989+}
72990+
72991+__u32
72992+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
72993+{
72994+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
72995+}
72996+
72997+__u32
72998+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
72999+{
73000+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
73001+}
73002+
73003+__u32
73004+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
73005+{
73006+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
73007+ GR_UNIXCONNECT_ACL_MSG);
73008+}
73009+
73010+/* hardlinks require at minimum create and link permission,
73011+ any additional privilege required is based on the
73012+ privilege of the file being linked to
73013+*/
73014+__u32
73015+gr_acl_handle_link(const struct dentry * new_dentry,
73016+ const struct dentry * parent_dentry,
73017+ const struct vfsmount * parent_mnt,
73018+ const struct dentry * old_dentry,
73019+ const struct vfsmount * old_mnt, const struct filename *to)
73020+{
73021+ __u32 mode;
73022+ __u32 needmode = GR_CREATE | GR_LINK;
73023+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
73024+
73025+ mode =
73026+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
73027+ old_mnt);
73028+
73029+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
73030+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73031+ return mode;
73032+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73033+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
73034+ return 0;
73035+ } else if (unlikely((mode & needmode) != needmode))
73036+ return 0;
73037+
73038+ return 1;
73039+}
73040+
73041+__u32
73042+gr_acl_handle_symlink(const struct dentry * new_dentry,
73043+ const struct dentry * parent_dentry,
73044+ const struct vfsmount * parent_mnt, const struct filename *from)
73045+{
73046+ __u32 needmode = GR_WRITE | GR_CREATE;
73047+ __u32 mode;
73048+
73049+ mode =
73050+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
73051+ GR_CREATE | GR_AUDIT_CREATE |
73052+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
73053+
73054+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
73055+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73056+ return mode;
73057+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
73058+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
73059+ return 0;
73060+ } else if (unlikely((mode & needmode) != needmode))
73061+ return 0;
73062+
73063+ return (GR_WRITE | GR_CREATE);
73064+}
73065+
73066+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)
73067+{
73068+ __u32 mode;
73069+
73070+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
73071+
73072+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
73073+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
73074+ return mode;
73075+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
73076+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
73077+ return 0;
73078+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
73079+ return 0;
73080+
73081+ return (reqmode);
73082+}
73083+
73084+__u32
73085+gr_acl_handle_mknod(const struct dentry * new_dentry,
73086+ const struct dentry * parent_dentry,
73087+ const struct vfsmount * parent_mnt,
73088+ const int mode)
73089+{
73090+ __u32 reqmode = GR_WRITE | GR_CREATE;
73091+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
73092+ reqmode |= GR_SETID;
73093+
73094+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73095+ reqmode, GR_MKNOD_ACL_MSG);
73096+}
73097+
73098+__u32
73099+gr_acl_handle_mkdir(const struct dentry *new_dentry,
73100+ const struct dentry *parent_dentry,
73101+ const struct vfsmount *parent_mnt)
73102+{
73103+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
73104+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
73105+}
73106+
73107+#define RENAME_CHECK_SUCCESS(old, new) \
73108+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
73109+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
73110+
73111+int
73112+gr_acl_handle_rename(struct dentry *new_dentry,
73113+ struct dentry *parent_dentry,
73114+ const struct vfsmount *parent_mnt,
73115+ struct dentry *old_dentry,
73116+ struct inode *old_parent_inode,
73117+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
73118+{
73119+ __u32 comp1, comp2;
73120+ int error = 0;
73121+
73122+ if (unlikely(!gr_acl_is_enabled()))
73123+ return 0;
73124+
73125+ if (flags & RENAME_EXCHANGE) {
73126+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73127+ GR_AUDIT_READ | GR_AUDIT_WRITE |
73128+ GR_SUPPRESS, parent_mnt);
73129+ comp2 =
73130+ gr_search_file(old_dentry,
73131+ GR_READ | GR_WRITE | GR_AUDIT_READ |
73132+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73133+ } else if (d_is_negative(new_dentry)) {
73134+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
73135+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
73136+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
73137+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
73138+ GR_DELETE | GR_AUDIT_DELETE |
73139+ GR_AUDIT_READ | GR_AUDIT_WRITE |
73140+ GR_SUPPRESS, old_mnt);
73141+ } else {
73142+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
73143+ GR_CREATE | GR_DELETE |
73144+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
73145+ GR_AUDIT_READ | GR_AUDIT_WRITE |
73146+ GR_SUPPRESS, parent_mnt);
73147+ comp2 =
73148+ gr_search_file(old_dentry,
73149+ GR_READ | GR_WRITE | GR_AUDIT_READ |
73150+ GR_DELETE | GR_AUDIT_DELETE |
73151+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
73152+ }
73153+
73154+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
73155+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
73156+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73157+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
73158+ && !(comp2 & GR_SUPPRESS)) {
73159+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
73160+ error = -EACCES;
73161+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
73162+ error = -EACCES;
73163+
73164+ return error;
73165+}
73166+
73167+void
73168+gr_acl_handle_exit(void)
73169+{
73170+ u16 id;
73171+ char *rolename;
73172+
73173+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
73174+ !(current->role->roletype & GR_ROLE_PERSIST))) {
73175+ id = current->acl_role_id;
73176+ rolename = current->role->rolename;
73177+ gr_set_acls(1);
73178+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
73179+ }
73180+
73181+ gr_put_exec_file(current);
73182+ return;
73183+}
73184+
73185+int
73186+gr_acl_handle_procpidmem(const struct task_struct *task)
73187+{
73188+ if (unlikely(!gr_acl_is_enabled()))
73189+ return 0;
73190+
73191+ if (task != current && task->acl->mode & GR_PROTPROCFD)
73192+ return -EACCES;
73193+
73194+ return 0;
73195+}
73196diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
73197new file mode 100644
73198index 0000000..f056b81
73199--- /dev/null
73200+++ b/grsecurity/gracl_ip.c
73201@@ -0,0 +1,386 @@
73202+#include <linux/kernel.h>
73203+#include <asm/uaccess.h>
73204+#include <asm/errno.h>
73205+#include <net/sock.h>
73206+#include <linux/file.h>
73207+#include <linux/fs.h>
73208+#include <linux/net.h>
73209+#include <linux/in.h>
73210+#include <linux/skbuff.h>
73211+#include <linux/ip.h>
73212+#include <linux/udp.h>
73213+#include <linux/types.h>
73214+#include <linux/sched.h>
73215+#include <linux/netdevice.h>
73216+#include <linux/inetdevice.h>
73217+#include <linux/gracl.h>
73218+#include <linux/grsecurity.h>
73219+#include <linux/grinternal.h>
73220+
73221+#define GR_BIND 0x01
73222+#define GR_CONNECT 0x02
73223+#define GR_INVERT 0x04
73224+#define GR_BINDOVERRIDE 0x08
73225+#define GR_CONNECTOVERRIDE 0x10
73226+#define GR_SOCK_FAMILY 0x20
73227+
73228+static const char * gr_protocols[IPPROTO_MAX] = {
73229+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
73230+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
73231+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
73232+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
73233+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
73234+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
73235+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
73236+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
73237+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
73238+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
73239+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
73240+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
73241+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
73242+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
73243+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
73244+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
73245+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
73246+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
73247+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
73248+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
73249+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
73250+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
73251+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
73252+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
73253+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
73254+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
73255+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
73256+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
73257+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
73258+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
73259+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
73260+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
73261+ };
73262+
73263+static const char * gr_socktypes[SOCK_MAX] = {
73264+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
73265+ "unknown:7", "unknown:8", "unknown:9", "packet"
73266+ };
73267+
73268+static const char * gr_sockfamilies[AF_MAX+1] = {
73269+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
73270+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
73271+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
73272+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
73273+ };
73274+
73275+const char *
73276+gr_proto_to_name(unsigned char proto)
73277+{
73278+ return gr_protocols[proto];
73279+}
73280+
73281+const char *
73282+gr_socktype_to_name(unsigned char type)
73283+{
73284+ return gr_socktypes[type];
73285+}
73286+
73287+const char *
73288+gr_sockfamily_to_name(unsigned char family)
73289+{
73290+ return gr_sockfamilies[family];
73291+}
73292+
73293+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
73294+
73295+int
73296+gr_search_socket(const int domain, const int type, const int protocol)
73297+{
73298+ struct acl_subject_label *curr;
73299+ const struct cred *cred = current_cred();
73300+
73301+ if (unlikely(!gr_acl_is_enabled()))
73302+ goto exit;
73303+
73304+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
73305+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
73306+ goto exit; // let the kernel handle it
73307+
73308+ curr = current->acl;
73309+
73310+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
73311+ /* the family is allowed, if this is PF_INET allow it only if
73312+ the extra sock type/protocol checks pass */
73313+ if (domain == PF_INET)
73314+ goto inet_check;
73315+ goto exit;
73316+ } else {
73317+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73318+ __u32 fakeip = 0;
73319+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73320+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
73321+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
73322+ gr_to_filename(current->exec_file->f_path.dentry,
73323+ current->exec_file->f_path.mnt) :
73324+ curr->filename, curr->filename,
73325+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
73326+ &current->signal->saved_ip);
73327+ goto exit;
73328+ }
73329+ goto exit_fail;
73330+ }
73331+
73332+inet_check:
73333+ /* the rest of this checking is for IPv4 only */
73334+ if (!curr->ips)
73335+ goto exit;
73336+
73337+ if ((curr->ip_type & (1U << type)) &&
73338+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
73339+ goto exit;
73340+
73341+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73342+ /* we don't place acls on raw sockets , and sometimes
73343+ dgram/ip sockets are opened for ioctl and not
73344+ bind/connect, so we'll fake a bind learn log */
73345+ if (type == SOCK_RAW || type == SOCK_PACKET) {
73346+ __u32 fakeip = 0;
73347+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73348+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
73349+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
73350+ gr_to_filename(current->exec_file->f_path.dentry,
73351+ current->exec_file->f_path.mnt) :
73352+ curr->filename, curr->filename,
73353+ &fakeip, 0, type,
73354+ protocol, GR_CONNECT, &current->signal->saved_ip);
73355+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
73356+ __u32 fakeip = 0;
73357+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73358+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
73359+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
73360+ gr_to_filename(current->exec_file->f_path.dentry,
73361+ current->exec_file->f_path.mnt) :
73362+ curr->filename, curr->filename,
73363+ &fakeip, 0, type,
73364+ protocol, GR_BIND, &current->signal->saved_ip);
73365+ }
73366+ /* we'll log when they use connect or bind */
73367+ goto exit;
73368+ }
73369+
73370+exit_fail:
73371+ if (domain == PF_INET)
73372+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
73373+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
73374+ else if (rcu_access_pointer(net_families[domain]) != NULL)
73375+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
73376+ gr_socktype_to_name(type), protocol);
73377+
73378+ return 0;
73379+exit:
73380+ return 1;
73381+}
73382+
73383+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)
73384+{
73385+ if ((ip->mode & mode) &&
73386+ (ip_port >= ip->low) &&
73387+ (ip_port <= ip->high) &&
73388+ ((ntohl(ip_addr) & our_netmask) ==
73389+ (ntohl(our_addr) & our_netmask))
73390+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
73391+ && (ip->type & (1U << type))) {
73392+ if (ip->mode & GR_INVERT)
73393+ return 2; // specifically denied
73394+ else
73395+ return 1; // allowed
73396+ }
73397+
73398+ return 0; // not specifically allowed, may continue parsing
73399+}
73400+
73401+static int
73402+gr_search_connectbind(const int full_mode, struct sock *sk,
73403+ struct sockaddr_in *addr, const int type)
73404+{
73405+ char iface[IFNAMSIZ] = {0};
73406+ struct acl_subject_label *curr;
73407+ struct acl_ip_label *ip;
73408+ struct inet_sock *isk;
73409+ struct net_device *dev;
73410+ struct in_device *idev;
73411+ unsigned long i;
73412+ int ret;
73413+ int mode = full_mode & (GR_BIND | GR_CONNECT);
73414+ __u32 ip_addr = 0;
73415+ __u32 our_addr;
73416+ __u32 our_netmask;
73417+ char *p;
73418+ __u16 ip_port = 0;
73419+ const struct cred *cred = current_cred();
73420+
73421+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
73422+ return 0;
73423+
73424+ curr = current->acl;
73425+ isk = inet_sk(sk);
73426+
73427+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
73428+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
73429+ addr->sin_addr.s_addr = curr->inaddr_any_override;
73430+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
73431+ struct sockaddr_in saddr;
73432+ int err;
73433+
73434+ saddr.sin_family = AF_INET;
73435+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
73436+ saddr.sin_port = isk->inet_sport;
73437+
73438+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73439+ if (err)
73440+ return err;
73441+
73442+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
73443+ if (err)
73444+ return err;
73445+ }
73446+
73447+ if (!curr->ips)
73448+ return 0;
73449+
73450+ ip_addr = addr->sin_addr.s_addr;
73451+ ip_port = ntohs(addr->sin_port);
73452+
73453+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
73454+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
73455+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
73456+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
73457+ gr_to_filename(current->exec_file->f_path.dentry,
73458+ current->exec_file->f_path.mnt) :
73459+ curr->filename, curr->filename,
73460+ &ip_addr, ip_port, type,
73461+ sk->sk_protocol, mode, &current->signal->saved_ip);
73462+ return 0;
73463+ }
73464+
73465+ for (i = 0; i < curr->ip_num; i++) {
73466+ ip = *(curr->ips + i);
73467+ if (ip->iface != NULL) {
73468+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
73469+ p = strchr(iface, ':');
73470+ if (p != NULL)
73471+ *p = '\0';
73472+ dev = dev_get_by_name(sock_net(sk), iface);
73473+ if (dev == NULL)
73474+ continue;
73475+ idev = in_dev_get(dev);
73476+ if (idev == NULL) {
73477+ dev_put(dev);
73478+ continue;
73479+ }
73480+ rcu_read_lock();
73481+ for_ifa(idev) {
73482+ if (!strcmp(ip->iface, ifa->ifa_label)) {
73483+ our_addr = ifa->ifa_address;
73484+ our_netmask = 0xffffffff;
73485+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73486+ if (ret == 1) {
73487+ rcu_read_unlock();
73488+ in_dev_put(idev);
73489+ dev_put(dev);
73490+ return 0;
73491+ } else if (ret == 2) {
73492+ rcu_read_unlock();
73493+ in_dev_put(idev);
73494+ dev_put(dev);
73495+ goto denied;
73496+ }
73497+ }
73498+ } endfor_ifa(idev);
73499+ rcu_read_unlock();
73500+ in_dev_put(idev);
73501+ dev_put(dev);
73502+ } else {
73503+ our_addr = ip->addr;
73504+ our_netmask = ip->netmask;
73505+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
73506+ if (ret == 1)
73507+ return 0;
73508+ else if (ret == 2)
73509+ goto denied;
73510+ }
73511+ }
73512+
73513+denied:
73514+ if (mode == GR_BIND)
73515+ 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));
73516+ else if (mode == GR_CONNECT)
73517+ 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));
73518+
73519+ return -EACCES;
73520+}
73521+
73522+int
73523+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
73524+{
73525+ /* always allow disconnection of dgram sockets with connect */
73526+ if (addr->sin_family == AF_UNSPEC)
73527+ return 0;
73528+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
73529+}
73530+
73531+int
73532+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
73533+{
73534+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
73535+}
73536+
73537+int gr_search_listen(struct socket *sock)
73538+{
73539+ struct sock *sk = sock->sk;
73540+ struct sockaddr_in addr;
73541+
73542+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73543+ addr.sin_port = inet_sk(sk)->inet_sport;
73544+
73545+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73546+}
73547+
73548+int gr_search_accept(struct socket *sock)
73549+{
73550+ struct sock *sk = sock->sk;
73551+ struct sockaddr_in addr;
73552+
73553+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
73554+ addr.sin_port = inet_sk(sk)->inet_sport;
73555+
73556+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
73557+}
73558+
73559+int
73560+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
73561+{
73562+ if (addr)
73563+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
73564+ else {
73565+ struct sockaddr_in sin;
73566+ const struct inet_sock *inet = inet_sk(sk);
73567+
73568+ sin.sin_addr.s_addr = inet->inet_daddr;
73569+ sin.sin_port = inet->inet_dport;
73570+
73571+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73572+ }
73573+}
73574+
73575+int
73576+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
73577+{
73578+ struct sockaddr_in sin;
73579+
73580+ if (unlikely(skb->len < sizeof (struct udphdr)))
73581+ return 0; // skip this packet
73582+
73583+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
73584+ sin.sin_port = udp_hdr(skb)->source;
73585+
73586+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
73587+}
73588diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
73589new file mode 100644
73590index 0000000..25f54ef
73591--- /dev/null
73592+++ b/grsecurity/gracl_learn.c
73593@@ -0,0 +1,207 @@
73594+#include <linux/kernel.h>
73595+#include <linux/mm.h>
73596+#include <linux/sched.h>
73597+#include <linux/poll.h>
73598+#include <linux/string.h>
73599+#include <linux/file.h>
73600+#include <linux/types.h>
73601+#include <linux/vmalloc.h>
73602+#include <linux/grinternal.h>
73603+
73604+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
73605+ size_t count, loff_t *ppos);
73606+extern int gr_acl_is_enabled(void);
73607+
73608+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
73609+static int gr_learn_attached;
73610+
73611+/* use a 512k buffer */
73612+#define LEARN_BUFFER_SIZE (512 * 1024)
73613+
73614+static DEFINE_SPINLOCK(gr_learn_lock);
73615+static DEFINE_MUTEX(gr_learn_user_mutex);
73616+
73617+/* we need to maintain two buffers, so that the kernel context of grlearn
73618+ uses a semaphore around the userspace copying, and the other kernel contexts
73619+ use a spinlock when copying into the buffer, since they cannot sleep
73620+*/
73621+static char *learn_buffer;
73622+static char *learn_buffer_user;
73623+static int learn_buffer_len;
73624+static int learn_buffer_user_len;
73625+
73626+static ssize_t
73627+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
73628+{
73629+ DECLARE_WAITQUEUE(wait, current);
73630+ ssize_t retval = 0;
73631+
73632+ add_wait_queue(&learn_wait, &wait);
73633+ set_current_state(TASK_INTERRUPTIBLE);
73634+ do {
73635+ mutex_lock(&gr_learn_user_mutex);
73636+ spin_lock(&gr_learn_lock);
73637+ if (learn_buffer_len)
73638+ break;
73639+ spin_unlock(&gr_learn_lock);
73640+ mutex_unlock(&gr_learn_user_mutex);
73641+ if (file->f_flags & O_NONBLOCK) {
73642+ retval = -EAGAIN;
73643+ goto out;
73644+ }
73645+ if (signal_pending(current)) {
73646+ retval = -ERESTARTSYS;
73647+ goto out;
73648+ }
73649+
73650+ schedule();
73651+ } while (1);
73652+
73653+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
73654+ learn_buffer_user_len = learn_buffer_len;
73655+ retval = learn_buffer_len;
73656+ learn_buffer_len = 0;
73657+
73658+ spin_unlock(&gr_learn_lock);
73659+
73660+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
73661+ retval = -EFAULT;
73662+
73663+ mutex_unlock(&gr_learn_user_mutex);
73664+out:
73665+ set_current_state(TASK_RUNNING);
73666+ remove_wait_queue(&learn_wait, &wait);
73667+ return retval;
73668+}
73669+
73670+static unsigned int
73671+poll_learn(struct file * file, poll_table * wait)
73672+{
73673+ poll_wait(file, &learn_wait, wait);
73674+
73675+ if (learn_buffer_len)
73676+ return (POLLIN | POLLRDNORM);
73677+
73678+ return 0;
73679+}
73680+
73681+void
73682+gr_clear_learn_entries(void)
73683+{
73684+ char *tmp;
73685+
73686+ mutex_lock(&gr_learn_user_mutex);
73687+ spin_lock(&gr_learn_lock);
73688+ tmp = learn_buffer;
73689+ learn_buffer = NULL;
73690+ spin_unlock(&gr_learn_lock);
73691+ if (tmp)
73692+ vfree(tmp);
73693+ if (learn_buffer_user != NULL) {
73694+ vfree(learn_buffer_user);
73695+ learn_buffer_user = NULL;
73696+ }
73697+ learn_buffer_len = 0;
73698+ mutex_unlock(&gr_learn_user_mutex);
73699+
73700+ return;
73701+}
73702+
73703+void
73704+gr_add_learn_entry(const char *fmt, ...)
73705+{
73706+ va_list args;
73707+ unsigned int len;
73708+
73709+ if (!gr_learn_attached)
73710+ return;
73711+
73712+ spin_lock(&gr_learn_lock);
73713+
73714+ /* leave a gap at the end so we know when it's "full" but don't have to
73715+ compute the exact length of the string we're trying to append
73716+ */
73717+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
73718+ spin_unlock(&gr_learn_lock);
73719+ wake_up_interruptible(&learn_wait);
73720+ return;
73721+ }
73722+ if (learn_buffer == NULL) {
73723+ spin_unlock(&gr_learn_lock);
73724+ return;
73725+ }
73726+
73727+ va_start(args, fmt);
73728+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
73729+ va_end(args);
73730+
73731+ learn_buffer_len += len + 1;
73732+
73733+ spin_unlock(&gr_learn_lock);
73734+ wake_up_interruptible(&learn_wait);
73735+
73736+ return;
73737+}
73738+
73739+static int
73740+open_learn(struct inode *inode, struct file *file)
73741+{
73742+ if (file->f_mode & FMODE_READ && gr_learn_attached)
73743+ return -EBUSY;
73744+ if (file->f_mode & FMODE_READ) {
73745+ int retval = 0;
73746+ mutex_lock(&gr_learn_user_mutex);
73747+ if (learn_buffer == NULL)
73748+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
73749+ if (learn_buffer_user == NULL)
73750+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
73751+ if (learn_buffer == NULL) {
73752+ retval = -ENOMEM;
73753+ goto out_error;
73754+ }
73755+ if (learn_buffer_user == NULL) {
73756+ retval = -ENOMEM;
73757+ goto out_error;
73758+ }
73759+ learn_buffer_len = 0;
73760+ learn_buffer_user_len = 0;
73761+ gr_learn_attached = 1;
73762+out_error:
73763+ mutex_unlock(&gr_learn_user_mutex);
73764+ return retval;
73765+ }
73766+ return 0;
73767+}
73768+
73769+static int
73770+close_learn(struct inode *inode, struct file *file)
73771+{
73772+ if (file->f_mode & FMODE_READ) {
73773+ char *tmp = NULL;
73774+ mutex_lock(&gr_learn_user_mutex);
73775+ spin_lock(&gr_learn_lock);
73776+ tmp = learn_buffer;
73777+ learn_buffer = NULL;
73778+ spin_unlock(&gr_learn_lock);
73779+ if (tmp)
73780+ vfree(tmp);
73781+ if (learn_buffer_user != NULL) {
73782+ vfree(learn_buffer_user);
73783+ learn_buffer_user = NULL;
73784+ }
73785+ learn_buffer_len = 0;
73786+ learn_buffer_user_len = 0;
73787+ gr_learn_attached = 0;
73788+ mutex_unlock(&gr_learn_user_mutex);
73789+ }
73790+
73791+ return 0;
73792+}
73793+
73794+const struct file_operations grsec_fops = {
73795+ .read = read_learn,
73796+ .write = write_grsec_handler,
73797+ .open = open_learn,
73798+ .release = close_learn,
73799+ .poll = poll_learn,
73800+};
73801diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
73802new file mode 100644
73803index 0000000..3f8ade0
73804--- /dev/null
73805+++ b/grsecurity/gracl_policy.c
73806@@ -0,0 +1,1782 @@
73807+#include <linux/kernel.h>
73808+#include <linux/module.h>
73809+#include <linux/sched.h>
73810+#include <linux/mm.h>
73811+#include <linux/file.h>
73812+#include <linux/fs.h>
73813+#include <linux/namei.h>
73814+#include <linux/mount.h>
73815+#include <linux/tty.h>
73816+#include <linux/proc_fs.h>
73817+#include <linux/lglock.h>
73818+#include <linux/slab.h>
73819+#include <linux/vmalloc.h>
73820+#include <linux/types.h>
73821+#include <linux/sysctl.h>
73822+#include <linux/netdevice.h>
73823+#include <linux/ptrace.h>
73824+#include <linux/gracl.h>
73825+#include <linux/gralloc.h>
73826+#include <linux/security.h>
73827+#include <linux/grinternal.h>
73828+#include <linux/pid_namespace.h>
73829+#include <linux/stop_machine.h>
73830+#include <linux/fdtable.h>
73831+#include <linux/percpu.h>
73832+#include <linux/lglock.h>
73833+#include <linux/hugetlb.h>
73834+#include <linux/posix-timers.h>
73835+#include "../fs/mount.h"
73836+
73837+#include <asm/uaccess.h>
73838+#include <asm/errno.h>
73839+#include <asm/mman.h>
73840+
73841+extern struct gr_policy_state *polstate;
73842+
73843+#define FOR_EACH_ROLE_START(role) \
73844+ role = polstate->role_list; \
73845+ while (role) {
73846+
73847+#define FOR_EACH_ROLE_END(role) \
73848+ role = role->prev; \
73849+ }
73850+
73851+struct path gr_real_root;
73852+
73853+extern struct gr_alloc_state *current_alloc_state;
73854+
73855+u16 acl_sp_role_value;
73856+
73857+static DEFINE_MUTEX(gr_dev_mutex);
73858+
73859+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
73860+extern void gr_clear_learn_entries(void);
73861+
73862+struct gr_arg *gr_usermode __read_only;
73863+unsigned char *gr_system_salt __read_only;
73864+unsigned char *gr_system_sum __read_only;
73865+
73866+static unsigned int gr_auth_attempts = 0;
73867+static unsigned long gr_auth_expires = 0UL;
73868+
73869+struct acl_object_label *fakefs_obj_rw;
73870+struct acl_object_label *fakefs_obj_rwx;
73871+
73872+extern int gr_init_uidset(void);
73873+extern void gr_free_uidset(void);
73874+extern void gr_remove_uid(uid_t uid);
73875+extern int gr_find_uid(uid_t uid);
73876+
73877+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
73878+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
73879+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
73880+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
73881+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);
73882+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
73883+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
73884+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
73885+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
73886+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73887+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
73888+extern void assign_special_role(const char *rolename);
73889+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
73890+extern int gr_rbac_disable(void *unused);
73891+extern void gr_enable_rbac_system(void);
73892+
73893+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
73894+{
73895+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
73896+ return -EFAULT;
73897+
73898+ return 0;
73899+}
73900+
73901+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
73902+{
73903+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
73904+ return -EFAULT;
73905+
73906+ return 0;
73907+}
73908+
73909+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
73910+{
73911+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
73912+ return -EFAULT;
73913+
73914+ return 0;
73915+}
73916+
73917+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
73918+{
73919+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
73920+ return -EFAULT;
73921+
73922+ return 0;
73923+}
73924+
73925+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
73926+{
73927+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
73928+ return -EFAULT;
73929+
73930+ return 0;
73931+}
73932+
73933+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
73934+{
73935+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
73936+ return -EFAULT;
73937+
73938+ return 0;
73939+}
73940+
73941+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
73942+{
73943+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
73944+ return -EFAULT;
73945+
73946+ return 0;
73947+}
73948+
73949+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
73950+{
73951+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
73952+ return -EFAULT;
73953+
73954+ return 0;
73955+}
73956+
73957+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
73958+{
73959+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
73960+ return -EFAULT;
73961+
73962+ return 0;
73963+}
73964+
73965+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
73966+{
73967+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
73968+ return -EFAULT;
73969+
73970+ if (((uwrap->version != GRSECURITY_VERSION) &&
73971+ (uwrap->version != 0x2901)) ||
73972+ (uwrap->size != sizeof(struct gr_arg)))
73973+ return -EINVAL;
73974+
73975+ return 0;
73976+}
73977+
73978+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
73979+{
73980+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
73981+ return -EFAULT;
73982+
73983+ return 0;
73984+}
73985+
73986+static size_t get_gr_arg_wrapper_size_normal(void)
73987+{
73988+ return sizeof(struct gr_arg_wrapper);
73989+}
73990+
73991+#ifdef CONFIG_COMPAT
73992+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
73993+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
73994+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
73995+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
73996+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
73997+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
73998+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
73999+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
74000+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
74001+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
74002+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
74003+extern size_t get_gr_arg_wrapper_size_compat(void);
74004+
74005+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
74006+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
74007+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
74008+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
74009+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
74010+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
74011+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
74012+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
74013+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
74014+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
74015+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
74016+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
74017+
74018+#else
74019+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
74020+#define copy_gr_arg copy_gr_arg_normal
74021+#define copy_gr_hash_struct copy_gr_hash_struct_normal
74022+#define copy_acl_object_label copy_acl_object_label_normal
74023+#define copy_acl_subject_label copy_acl_subject_label_normal
74024+#define copy_acl_role_label copy_acl_role_label_normal
74025+#define copy_acl_ip_label copy_acl_ip_label_normal
74026+#define copy_pointer_from_array copy_pointer_from_array_normal
74027+#define copy_sprole_pw copy_sprole_pw_normal
74028+#define copy_role_transition copy_role_transition_normal
74029+#define copy_role_allowed_ip copy_role_allowed_ip_normal
74030+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
74031+#endif
74032+
74033+static struct acl_subject_label *
74034+lookup_subject_map(const struct acl_subject_label *userp)
74035+{
74036+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
74037+ struct subject_map *match;
74038+
74039+ match = polstate->subj_map_set.s_hash[index];
74040+
74041+ while (match && match->user != userp)
74042+ match = match->next;
74043+
74044+ if (match != NULL)
74045+ return match->kernel;
74046+ else
74047+ return NULL;
74048+}
74049+
74050+static void
74051+insert_subj_map_entry(struct subject_map *subjmap)
74052+{
74053+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
74054+ struct subject_map **curr;
74055+
74056+ subjmap->prev = NULL;
74057+
74058+ curr = &polstate->subj_map_set.s_hash[index];
74059+ if (*curr != NULL)
74060+ (*curr)->prev = subjmap;
74061+
74062+ subjmap->next = *curr;
74063+ *curr = subjmap;
74064+
74065+ return;
74066+}
74067+
74068+static void
74069+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
74070+{
74071+ unsigned int index =
74072+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
74073+ struct acl_role_label **curr;
74074+ struct acl_role_label *tmp, *tmp2;
74075+
74076+ curr = &polstate->acl_role_set.r_hash[index];
74077+
74078+ /* simple case, slot is empty, just set it to our role */
74079+ if (*curr == NULL) {
74080+ *curr = role;
74081+ } else {
74082+ /* example:
74083+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
74084+ 2 -> 3
74085+ */
74086+ /* first check to see if we can already be reached via this slot */
74087+ tmp = *curr;
74088+ while (tmp && tmp != role)
74089+ tmp = tmp->next;
74090+ if (tmp == role) {
74091+ /* we don't need to add ourselves to this slot's chain */
74092+ return;
74093+ }
74094+ /* we need to add ourselves to this chain, two cases */
74095+ if (role->next == NULL) {
74096+ /* simple case, append the current chain to our role */
74097+ role->next = *curr;
74098+ *curr = role;
74099+ } else {
74100+ /* 1 -> 2 -> 3 -> 4
74101+ 2 -> 3 -> 4
74102+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
74103+ */
74104+ /* trickier case: walk our role's chain until we find
74105+ the role for the start of the current slot's chain */
74106+ tmp = role;
74107+ tmp2 = *curr;
74108+ while (tmp->next && tmp->next != tmp2)
74109+ tmp = tmp->next;
74110+ if (tmp->next == tmp2) {
74111+ /* from example above, we found 3, so just
74112+ replace this slot's chain with ours */
74113+ *curr = role;
74114+ } else {
74115+ /* we didn't find a subset of our role's chain
74116+ in the current slot's chain, so append their
74117+ chain to ours, and set us as the first role in
74118+ the slot's chain
74119+
74120+ we could fold this case with the case above,
74121+ but making it explicit for clarity
74122+ */
74123+ tmp->next = tmp2;
74124+ *curr = role;
74125+ }
74126+ }
74127+ }
74128+
74129+ return;
74130+}
74131+
74132+static void
74133+insert_acl_role_label(struct acl_role_label *role)
74134+{
74135+ int i;
74136+
74137+ if (polstate->role_list == NULL) {
74138+ polstate->role_list = role;
74139+ role->prev = NULL;
74140+ } else {
74141+ role->prev = polstate->role_list;
74142+ polstate->role_list = role;
74143+ }
74144+
74145+ /* used for hash chains */
74146+ role->next = NULL;
74147+
74148+ if (role->roletype & GR_ROLE_DOMAIN) {
74149+ for (i = 0; i < role->domain_child_num; i++)
74150+ __insert_acl_role_label(role, role->domain_children[i]);
74151+ } else
74152+ __insert_acl_role_label(role, role->uidgid);
74153+}
74154+
74155+static int
74156+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
74157+{
74158+ struct name_entry **curr, *nentry;
74159+ struct inodev_entry *ientry;
74160+ unsigned int len = strlen(name);
74161+ unsigned int key = full_name_hash(name, len);
74162+ unsigned int index = key % polstate->name_set.n_size;
74163+
74164+ curr = &polstate->name_set.n_hash[index];
74165+
74166+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
74167+ curr = &((*curr)->next);
74168+
74169+ if (*curr != NULL)
74170+ return 1;
74171+
74172+ nentry = acl_alloc(sizeof (struct name_entry));
74173+ if (nentry == NULL)
74174+ return 0;
74175+ ientry = acl_alloc(sizeof (struct inodev_entry));
74176+ if (ientry == NULL)
74177+ return 0;
74178+ ientry->nentry = nentry;
74179+
74180+ nentry->key = key;
74181+ nentry->name = name;
74182+ nentry->inode = inode;
74183+ nentry->device = device;
74184+ nentry->len = len;
74185+ nentry->deleted = deleted;
74186+
74187+ nentry->prev = NULL;
74188+ curr = &polstate->name_set.n_hash[index];
74189+ if (*curr != NULL)
74190+ (*curr)->prev = nentry;
74191+ nentry->next = *curr;
74192+ *curr = nentry;
74193+
74194+ /* insert us into the table searchable by inode/dev */
74195+ __insert_inodev_entry(polstate, ientry);
74196+
74197+ return 1;
74198+}
74199+
74200+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
74201+
74202+static void *
74203+create_table(__u32 * len, int elementsize)
74204+{
74205+ unsigned int table_sizes[] = {
74206+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
74207+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
74208+ 4194301, 8388593, 16777213, 33554393, 67108859
74209+ };
74210+ void *newtable = NULL;
74211+ unsigned int pwr = 0;
74212+
74213+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
74214+ table_sizes[pwr] <= *len)
74215+ pwr++;
74216+
74217+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
74218+ return newtable;
74219+
74220+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
74221+ newtable =
74222+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
74223+ else
74224+ newtable = vmalloc(table_sizes[pwr] * elementsize);
74225+
74226+ *len = table_sizes[pwr];
74227+
74228+ return newtable;
74229+}
74230+
74231+static int
74232+init_variables(const struct gr_arg *arg, bool reload)
74233+{
74234+ struct task_struct *reaper = init_pid_ns.child_reaper;
74235+ unsigned int stacksize;
74236+
74237+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
74238+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
74239+ polstate->name_set.n_size = arg->role_db.num_objects;
74240+ polstate->inodev_set.i_size = arg->role_db.num_objects;
74241+
74242+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
74243+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
74244+ return 1;
74245+
74246+ if (!reload) {
74247+ if (!gr_init_uidset())
74248+ return 1;
74249+ }
74250+
74251+ /* set up the stack that holds allocation info */
74252+
74253+ stacksize = arg->role_db.num_pointers + 5;
74254+
74255+ if (!acl_alloc_stack_init(stacksize))
74256+ return 1;
74257+
74258+ if (!reload) {
74259+ /* grab reference for the real root dentry and vfsmount */
74260+ get_fs_root(reaper->fs, &gr_real_root);
74261+
74262+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74263+ 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);
74264+#endif
74265+
74266+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74267+ if (fakefs_obj_rw == NULL)
74268+ return 1;
74269+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
74270+
74271+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
74272+ if (fakefs_obj_rwx == NULL)
74273+ return 1;
74274+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
74275+ }
74276+
74277+ polstate->subj_map_set.s_hash =
74278+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
74279+ polstate->acl_role_set.r_hash =
74280+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
74281+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
74282+ polstate->inodev_set.i_hash =
74283+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
74284+
74285+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
74286+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
74287+ return 1;
74288+
74289+ memset(polstate->subj_map_set.s_hash, 0,
74290+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
74291+ memset(polstate->acl_role_set.r_hash, 0,
74292+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
74293+ memset(polstate->name_set.n_hash, 0,
74294+ sizeof (struct name_entry *) * polstate->name_set.n_size);
74295+ memset(polstate->inodev_set.i_hash, 0,
74296+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
74297+
74298+ return 0;
74299+}
74300+
74301+/* free information not needed after startup
74302+ currently contains user->kernel pointer mappings for subjects
74303+*/
74304+
74305+static void
74306+free_init_variables(void)
74307+{
74308+ __u32 i;
74309+
74310+ if (polstate->subj_map_set.s_hash) {
74311+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
74312+ if (polstate->subj_map_set.s_hash[i]) {
74313+ kfree(polstate->subj_map_set.s_hash[i]);
74314+ polstate->subj_map_set.s_hash[i] = NULL;
74315+ }
74316+ }
74317+
74318+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
74319+ PAGE_SIZE)
74320+ kfree(polstate->subj_map_set.s_hash);
74321+ else
74322+ vfree(polstate->subj_map_set.s_hash);
74323+ }
74324+
74325+ return;
74326+}
74327+
74328+static void
74329+free_variables(bool reload)
74330+{
74331+ struct acl_subject_label *s;
74332+ struct acl_role_label *r;
74333+ struct task_struct *task, *task2;
74334+ unsigned int x;
74335+
74336+ if (!reload) {
74337+ gr_clear_learn_entries();
74338+
74339+ read_lock(&tasklist_lock);
74340+ do_each_thread(task2, task) {
74341+ task->acl_sp_role = 0;
74342+ task->acl_role_id = 0;
74343+ task->inherited = 0;
74344+ task->acl = NULL;
74345+ task->role = NULL;
74346+ } while_each_thread(task2, task);
74347+ read_unlock(&tasklist_lock);
74348+
74349+ kfree(fakefs_obj_rw);
74350+ fakefs_obj_rw = NULL;
74351+ kfree(fakefs_obj_rwx);
74352+ fakefs_obj_rwx = NULL;
74353+
74354+ /* release the reference to the real root dentry and vfsmount */
74355+ path_put(&gr_real_root);
74356+ memset(&gr_real_root, 0, sizeof(gr_real_root));
74357+ }
74358+
74359+ /* free all object hash tables */
74360+
74361+ FOR_EACH_ROLE_START(r)
74362+ if (r->subj_hash == NULL)
74363+ goto next_role;
74364+ FOR_EACH_SUBJECT_START(r, s, x)
74365+ if (s->obj_hash == NULL)
74366+ break;
74367+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74368+ kfree(s->obj_hash);
74369+ else
74370+ vfree(s->obj_hash);
74371+ FOR_EACH_SUBJECT_END(s, x)
74372+ FOR_EACH_NESTED_SUBJECT_START(r, s)
74373+ if (s->obj_hash == NULL)
74374+ break;
74375+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
74376+ kfree(s->obj_hash);
74377+ else
74378+ vfree(s->obj_hash);
74379+ FOR_EACH_NESTED_SUBJECT_END(s)
74380+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
74381+ kfree(r->subj_hash);
74382+ else
74383+ vfree(r->subj_hash);
74384+ r->subj_hash = NULL;
74385+next_role:
74386+ FOR_EACH_ROLE_END(r)
74387+
74388+ acl_free_all();
74389+
74390+ if (polstate->acl_role_set.r_hash) {
74391+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
74392+ PAGE_SIZE)
74393+ kfree(polstate->acl_role_set.r_hash);
74394+ else
74395+ vfree(polstate->acl_role_set.r_hash);
74396+ }
74397+ if (polstate->name_set.n_hash) {
74398+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
74399+ PAGE_SIZE)
74400+ kfree(polstate->name_set.n_hash);
74401+ else
74402+ vfree(polstate->name_set.n_hash);
74403+ }
74404+
74405+ if (polstate->inodev_set.i_hash) {
74406+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
74407+ PAGE_SIZE)
74408+ kfree(polstate->inodev_set.i_hash);
74409+ else
74410+ vfree(polstate->inodev_set.i_hash);
74411+ }
74412+
74413+ if (!reload)
74414+ gr_free_uidset();
74415+
74416+ memset(&polstate->name_set, 0, sizeof (struct name_db));
74417+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
74418+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
74419+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
74420+
74421+ polstate->default_role = NULL;
74422+ polstate->kernel_role = NULL;
74423+ polstate->role_list = NULL;
74424+
74425+ return;
74426+}
74427+
74428+static struct acl_subject_label *
74429+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
74430+
74431+static int alloc_and_copy_string(char **name, unsigned int maxlen)
74432+{
74433+ unsigned int len = strnlen_user(*name, maxlen);
74434+ char *tmp;
74435+
74436+ if (!len || len >= maxlen)
74437+ return -EINVAL;
74438+
74439+ if ((tmp = (char *) acl_alloc(len)) == NULL)
74440+ return -ENOMEM;
74441+
74442+ if (copy_from_user(tmp, *name, len))
74443+ return -EFAULT;
74444+
74445+ tmp[len-1] = '\0';
74446+ *name = tmp;
74447+
74448+ return 0;
74449+}
74450+
74451+static int
74452+copy_user_glob(struct acl_object_label *obj)
74453+{
74454+ struct acl_object_label *g_tmp, **guser;
74455+ int error;
74456+
74457+ if (obj->globbed == NULL)
74458+ return 0;
74459+
74460+ guser = &obj->globbed;
74461+ while (*guser) {
74462+ g_tmp = (struct acl_object_label *)
74463+ acl_alloc(sizeof (struct acl_object_label));
74464+ if (g_tmp == NULL)
74465+ return -ENOMEM;
74466+
74467+ if (copy_acl_object_label(g_tmp, *guser))
74468+ return -EFAULT;
74469+
74470+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
74471+ if (error)
74472+ return error;
74473+
74474+ *guser = g_tmp;
74475+ guser = &(g_tmp->next);
74476+ }
74477+
74478+ return 0;
74479+}
74480+
74481+static int
74482+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
74483+ struct acl_role_label *role)
74484+{
74485+ struct acl_object_label *o_tmp;
74486+ int ret;
74487+
74488+ while (userp) {
74489+ if ((o_tmp = (struct acl_object_label *)
74490+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
74491+ return -ENOMEM;
74492+
74493+ if (copy_acl_object_label(o_tmp, userp))
74494+ return -EFAULT;
74495+
74496+ userp = o_tmp->prev;
74497+
74498+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
74499+ if (ret)
74500+ return ret;
74501+
74502+ insert_acl_obj_label(o_tmp, subj);
74503+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
74504+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
74505+ return -ENOMEM;
74506+
74507+ ret = copy_user_glob(o_tmp);
74508+ if (ret)
74509+ return ret;
74510+
74511+ if (o_tmp->nested) {
74512+ int already_copied;
74513+
74514+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
74515+ if (IS_ERR(o_tmp->nested))
74516+ return PTR_ERR(o_tmp->nested);
74517+
74518+ /* insert into nested subject list if we haven't copied this one yet
74519+ to prevent duplicate entries */
74520+ if (!already_copied) {
74521+ o_tmp->nested->next = role->hash->first;
74522+ role->hash->first = o_tmp->nested;
74523+ }
74524+ }
74525+ }
74526+
74527+ return 0;
74528+}
74529+
74530+static __u32
74531+count_user_subjs(struct acl_subject_label *userp)
74532+{
74533+ struct acl_subject_label s_tmp;
74534+ __u32 num = 0;
74535+
74536+ while (userp) {
74537+ if (copy_acl_subject_label(&s_tmp, userp))
74538+ break;
74539+
74540+ userp = s_tmp.prev;
74541+ }
74542+
74543+ return num;
74544+}
74545+
74546+static int
74547+copy_user_allowedips(struct acl_role_label *rolep)
74548+{
74549+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
74550+
74551+ ruserip = rolep->allowed_ips;
74552+
74553+ while (ruserip) {
74554+ rlast = rtmp;
74555+
74556+ if ((rtmp = (struct role_allowed_ip *)
74557+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
74558+ return -ENOMEM;
74559+
74560+ if (copy_role_allowed_ip(rtmp, ruserip))
74561+ return -EFAULT;
74562+
74563+ ruserip = rtmp->prev;
74564+
74565+ if (!rlast) {
74566+ rtmp->prev = NULL;
74567+ rolep->allowed_ips = rtmp;
74568+ } else {
74569+ rlast->next = rtmp;
74570+ rtmp->prev = rlast;
74571+ }
74572+
74573+ if (!ruserip)
74574+ rtmp->next = NULL;
74575+ }
74576+
74577+ return 0;
74578+}
74579+
74580+static int
74581+copy_user_transitions(struct acl_role_label *rolep)
74582+{
74583+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
74584+ int error;
74585+
74586+ rusertp = rolep->transitions;
74587+
74588+ while (rusertp) {
74589+ rlast = rtmp;
74590+
74591+ if ((rtmp = (struct role_transition *)
74592+ acl_alloc(sizeof (struct role_transition))) == NULL)
74593+ return -ENOMEM;
74594+
74595+ if (copy_role_transition(rtmp, rusertp))
74596+ return -EFAULT;
74597+
74598+ rusertp = rtmp->prev;
74599+
74600+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
74601+ if (error)
74602+ return error;
74603+
74604+ if (!rlast) {
74605+ rtmp->prev = NULL;
74606+ rolep->transitions = rtmp;
74607+ } else {
74608+ rlast->next = rtmp;
74609+ rtmp->prev = rlast;
74610+ }
74611+
74612+ if (!rusertp)
74613+ rtmp->next = NULL;
74614+ }
74615+
74616+ return 0;
74617+}
74618+
74619+static __u32 count_user_objs(const struct acl_object_label __user *userp)
74620+{
74621+ struct acl_object_label o_tmp;
74622+ __u32 num = 0;
74623+
74624+ while (userp) {
74625+ if (copy_acl_object_label(&o_tmp, userp))
74626+ break;
74627+
74628+ userp = o_tmp.prev;
74629+ num++;
74630+ }
74631+
74632+ return num;
74633+}
74634+
74635+static struct acl_subject_label *
74636+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
74637+{
74638+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
74639+ __u32 num_objs;
74640+ struct acl_ip_label **i_tmp, *i_utmp2;
74641+ struct gr_hash_struct ghash;
74642+ struct subject_map *subjmap;
74643+ unsigned int i_num;
74644+ int err;
74645+
74646+ if (already_copied != NULL)
74647+ *already_copied = 0;
74648+
74649+ s_tmp = lookup_subject_map(userp);
74650+
74651+ /* we've already copied this subject into the kernel, just return
74652+ the reference to it, and don't copy it over again
74653+ */
74654+ if (s_tmp) {
74655+ if (already_copied != NULL)
74656+ *already_copied = 1;
74657+ return(s_tmp);
74658+ }
74659+
74660+ if ((s_tmp = (struct acl_subject_label *)
74661+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
74662+ return ERR_PTR(-ENOMEM);
74663+
74664+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
74665+ if (subjmap == NULL)
74666+ return ERR_PTR(-ENOMEM);
74667+
74668+ subjmap->user = userp;
74669+ subjmap->kernel = s_tmp;
74670+ insert_subj_map_entry(subjmap);
74671+
74672+ if (copy_acl_subject_label(s_tmp, userp))
74673+ return ERR_PTR(-EFAULT);
74674+
74675+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
74676+ if (err)
74677+ return ERR_PTR(err);
74678+
74679+ if (!strcmp(s_tmp->filename, "/"))
74680+ role->root_label = s_tmp;
74681+
74682+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
74683+ return ERR_PTR(-EFAULT);
74684+
74685+ /* copy user and group transition tables */
74686+
74687+ if (s_tmp->user_trans_num) {
74688+ uid_t *uidlist;
74689+
74690+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
74691+ if (uidlist == NULL)
74692+ return ERR_PTR(-ENOMEM);
74693+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
74694+ return ERR_PTR(-EFAULT);
74695+
74696+ s_tmp->user_transitions = uidlist;
74697+ }
74698+
74699+ if (s_tmp->group_trans_num) {
74700+ gid_t *gidlist;
74701+
74702+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
74703+ if (gidlist == NULL)
74704+ return ERR_PTR(-ENOMEM);
74705+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
74706+ return ERR_PTR(-EFAULT);
74707+
74708+ s_tmp->group_transitions = gidlist;
74709+ }
74710+
74711+ /* set up object hash table */
74712+ num_objs = count_user_objs(ghash.first);
74713+
74714+ s_tmp->obj_hash_size = num_objs;
74715+ s_tmp->obj_hash =
74716+ (struct acl_object_label **)
74717+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
74718+
74719+ if (!s_tmp->obj_hash)
74720+ return ERR_PTR(-ENOMEM);
74721+
74722+ memset(s_tmp->obj_hash, 0,
74723+ s_tmp->obj_hash_size *
74724+ sizeof (struct acl_object_label *));
74725+
74726+ /* add in objects */
74727+ err = copy_user_objs(ghash.first, s_tmp, role);
74728+
74729+ if (err)
74730+ return ERR_PTR(err);
74731+
74732+ /* set pointer for parent subject */
74733+ if (s_tmp->parent_subject) {
74734+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
74735+
74736+ if (IS_ERR(s_tmp2))
74737+ return s_tmp2;
74738+
74739+ s_tmp->parent_subject = s_tmp2;
74740+ }
74741+
74742+ /* add in ip acls */
74743+
74744+ if (!s_tmp->ip_num) {
74745+ s_tmp->ips = NULL;
74746+ goto insert;
74747+ }
74748+
74749+ i_tmp =
74750+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
74751+ sizeof (struct acl_ip_label *));
74752+
74753+ if (!i_tmp)
74754+ return ERR_PTR(-ENOMEM);
74755+
74756+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
74757+ *(i_tmp + i_num) =
74758+ (struct acl_ip_label *)
74759+ acl_alloc(sizeof (struct acl_ip_label));
74760+ if (!*(i_tmp + i_num))
74761+ return ERR_PTR(-ENOMEM);
74762+
74763+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
74764+ return ERR_PTR(-EFAULT);
74765+
74766+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
74767+ return ERR_PTR(-EFAULT);
74768+
74769+ if ((*(i_tmp + i_num))->iface == NULL)
74770+ continue;
74771+
74772+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
74773+ if (err)
74774+ return ERR_PTR(err);
74775+ }
74776+
74777+ s_tmp->ips = i_tmp;
74778+
74779+insert:
74780+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
74781+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
74782+ return ERR_PTR(-ENOMEM);
74783+
74784+ return s_tmp;
74785+}
74786+
74787+static int
74788+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
74789+{
74790+ struct acl_subject_label s_pre;
74791+ struct acl_subject_label * ret;
74792+ int err;
74793+
74794+ while (userp) {
74795+ if (copy_acl_subject_label(&s_pre, userp))
74796+ return -EFAULT;
74797+
74798+ ret = do_copy_user_subj(userp, role, NULL);
74799+
74800+ err = PTR_ERR(ret);
74801+ if (IS_ERR(ret))
74802+ return err;
74803+
74804+ insert_acl_subj_label(ret, role);
74805+
74806+ userp = s_pre.prev;
74807+ }
74808+
74809+ return 0;
74810+}
74811+
74812+static int
74813+copy_user_acl(struct gr_arg *arg)
74814+{
74815+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
74816+ struct acl_subject_label *subj_list;
74817+ struct sprole_pw *sptmp;
74818+ struct gr_hash_struct *ghash;
74819+ uid_t *domainlist;
74820+ unsigned int r_num;
74821+ int err = 0;
74822+ __u16 i;
74823+ __u32 num_subjs;
74824+
74825+ /* we need a default and kernel role */
74826+ if (arg->role_db.num_roles < 2)
74827+ return -EINVAL;
74828+
74829+ /* copy special role authentication info from userspace */
74830+
74831+ polstate->num_sprole_pws = arg->num_sprole_pws;
74832+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
74833+
74834+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
74835+ return -ENOMEM;
74836+
74837+ for (i = 0; i < polstate->num_sprole_pws; i++) {
74838+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
74839+ if (!sptmp)
74840+ return -ENOMEM;
74841+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
74842+ return -EFAULT;
74843+
74844+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
74845+ if (err)
74846+ return err;
74847+
74848+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
74849+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
74850+#endif
74851+
74852+ polstate->acl_special_roles[i] = sptmp;
74853+ }
74854+
74855+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
74856+
74857+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
74858+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
74859+
74860+ if (!r_tmp)
74861+ return -ENOMEM;
74862+
74863+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
74864+ return -EFAULT;
74865+
74866+ if (copy_acl_role_label(r_tmp, r_utmp2))
74867+ return -EFAULT;
74868+
74869+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
74870+ if (err)
74871+ return err;
74872+
74873+ if (!strcmp(r_tmp->rolename, "default")
74874+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
74875+ polstate->default_role = r_tmp;
74876+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
74877+ polstate->kernel_role = r_tmp;
74878+ }
74879+
74880+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
74881+ return -ENOMEM;
74882+
74883+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
74884+ return -EFAULT;
74885+
74886+ r_tmp->hash = ghash;
74887+
74888+ num_subjs = count_user_subjs(r_tmp->hash->first);
74889+
74890+ r_tmp->subj_hash_size = num_subjs;
74891+ r_tmp->subj_hash =
74892+ (struct acl_subject_label **)
74893+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
74894+
74895+ if (!r_tmp->subj_hash)
74896+ return -ENOMEM;
74897+
74898+ err = copy_user_allowedips(r_tmp);
74899+ if (err)
74900+ return err;
74901+
74902+ /* copy domain info */
74903+ if (r_tmp->domain_children != NULL) {
74904+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
74905+ if (domainlist == NULL)
74906+ return -ENOMEM;
74907+
74908+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
74909+ return -EFAULT;
74910+
74911+ r_tmp->domain_children = domainlist;
74912+ }
74913+
74914+ err = copy_user_transitions(r_tmp);
74915+ if (err)
74916+ return err;
74917+
74918+ memset(r_tmp->subj_hash, 0,
74919+ r_tmp->subj_hash_size *
74920+ sizeof (struct acl_subject_label *));
74921+
74922+ /* acquire the list of subjects, then NULL out
74923+ the list prior to parsing the subjects for this role,
74924+ as during this parsing the list is replaced with a list
74925+ of *nested* subjects for the role
74926+ */
74927+ subj_list = r_tmp->hash->first;
74928+
74929+ /* set nested subject list to null */
74930+ r_tmp->hash->first = NULL;
74931+
74932+ err = copy_user_subjs(subj_list, r_tmp);
74933+
74934+ if (err)
74935+ return err;
74936+
74937+ insert_acl_role_label(r_tmp);
74938+ }
74939+
74940+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
74941+ return -EINVAL;
74942+
74943+ return err;
74944+}
74945+
74946+static int gracl_reload_apply_policies(void *reload)
74947+{
74948+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
74949+ struct task_struct *task, *task2;
74950+ struct acl_role_label *role, *rtmp;
74951+ struct acl_subject_label *subj;
74952+ const struct cred *cred;
74953+ int role_applied;
74954+ int ret = 0;
74955+
74956+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
74957+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
74958+
74959+ /* first make sure we'll be able to apply the new policy cleanly */
74960+ do_each_thread(task2, task) {
74961+ if (task->exec_file == NULL)
74962+ continue;
74963+ role_applied = 0;
74964+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
74965+ /* preserve special roles */
74966+ FOR_EACH_ROLE_START(role)
74967+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
74968+ rtmp = task->role;
74969+ task->role = role;
74970+ role_applied = 1;
74971+ break;
74972+ }
74973+ FOR_EACH_ROLE_END(role)
74974+ }
74975+ if (!role_applied) {
74976+ cred = __task_cred(task);
74977+ rtmp = task->role;
74978+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
74979+ }
74980+ /* this handles non-nested inherited subjects, nested subjects will still
74981+ be dropped currently */
74982+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
74983+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
74984+ /* change the role back so that we've made no modifications to the policy */
74985+ task->role = rtmp;
74986+
74987+ if (subj == NULL || task->tmpacl == NULL) {
74988+ ret = -EINVAL;
74989+ goto out;
74990+ }
74991+ } while_each_thread(task2, task);
74992+
74993+ /* now actually apply the policy */
74994+
74995+ do_each_thread(task2, task) {
74996+ if (task->exec_file) {
74997+ role_applied = 0;
74998+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
74999+ /* preserve special roles */
75000+ FOR_EACH_ROLE_START(role)
75001+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
75002+ task->role = role;
75003+ role_applied = 1;
75004+ break;
75005+ }
75006+ FOR_EACH_ROLE_END(role)
75007+ }
75008+ if (!role_applied) {
75009+ cred = __task_cred(task);
75010+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75011+ }
75012+ /* this handles non-nested inherited subjects, nested subjects will still
75013+ be dropped currently */
75014+ if (!reload_state->oldmode && task->inherited)
75015+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
75016+ else {
75017+ /* looked up and tagged to the task previously */
75018+ subj = task->tmpacl;
75019+ }
75020+ /* subj will be non-null */
75021+ __gr_apply_subject_to_task(polstate, task, subj);
75022+ if (reload_state->oldmode) {
75023+ task->acl_role_id = 0;
75024+ task->acl_sp_role = 0;
75025+ task->inherited = 0;
75026+ }
75027+ } else {
75028+ // it's a kernel process
75029+ task->role = polstate->kernel_role;
75030+ task->acl = polstate->kernel_role->root_label;
75031+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75032+ task->acl->mode &= ~GR_PROCFIND;
75033+#endif
75034+ }
75035+ } while_each_thread(task2, task);
75036+
75037+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
75038+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
75039+
75040+out:
75041+
75042+ return ret;
75043+}
75044+
75045+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
75046+{
75047+ struct gr_reload_state new_reload_state = { };
75048+ int err;
75049+
75050+ new_reload_state.oldpolicy_ptr = polstate;
75051+ new_reload_state.oldalloc_ptr = current_alloc_state;
75052+ new_reload_state.oldmode = oldmode;
75053+
75054+ current_alloc_state = &new_reload_state.newalloc;
75055+ polstate = &new_reload_state.newpolicy;
75056+
75057+ /* everything relevant is now saved off, copy in the new policy */
75058+ if (init_variables(args, true)) {
75059+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75060+ err = -ENOMEM;
75061+ goto error;
75062+ }
75063+
75064+ err = copy_user_acl(args);
75065+ free_init_variables();
75066+ if (err)
75067+ goto error;
75068+ /* the new policy is copied in, with the old policy available via saved_state
75069+ first go through applying roles, making sure to preserve special roles
75070+ then apply new subjects, making sure to preserve inherited and nested subjects,
75071+ though currently only inherited subjects will be preserved
75072+ */
75073+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
75074+ if (err)
75075+ goto error;
75076+
75077+ /* we've now applied the new policy, so restore the old policy state to free it */
75078+ polstate = &new_reload_state.oldpolicy;
75079+ current_alloc_state = &new_reload_state.oldalloc;
75080+ free_variables(true);
75081+
75082+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
75083+ to running_polstate/current_alloc_state inside stop_machine
75084+ */
75085+ err = 0;
75086+ goto out;
75087+error:
75088+ /* on error of loading the new policy, we'll just keep the previous
75089+ policy set around
75090+ */
75091+ free_variables(true);
75092+
75093+ /* doesn't affect runtime, but maintains consistent state */
75094+out:
75095+ polstate = new_reload_state.oldpolicy_ptr;
75096+ current_alloc_state = new_reload_state.oldalloc_ptr;
75097+
75098+ return err;
75099+}
75100+
75101+static int
75102+gracl_init(struct gr_arg *args)
75103+{
75104+ int error = 0;
75105+
75106+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
75107+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
75108+
75109+ if (init_variables(args, false)) {
75110+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
75111+ error = -ENOMEM;
75112+ goto out;
75113+ }
75114+
75115+ error = copy_user_acl(args);
75116+ free_init_variables();
75117+ if (error)
75118+ goto out;
75119+
75120+ error = gr_set_acls(0);
75121+ if (error)
75122+ goto out;
75123+
75124+ gr_enable_rbac_system();
75125+
75126+ return 0;
75127+
75128+out:
75129+ free_variables(false);
75130+ return error;
75131+}
75132+
75133+static int
75134+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
75135+ unsigned char **sum)
75136+{
75137+ struct acl_role_label *r;
75138+ struct role_allowed_ip *ipp;
75139+ struct role_transition *trans;
75140+ unsigned int i;
75141+ int found = 0;
75142+ u32 curr_ip = current->signal->curr_ip;
75143+
75144+ current->signal->saved_ip = curr_ip;
75145+
75146+ /* check transition table */
75147+
75148+ for (trans = current->role->transitions; trans; trans = trans->next) {
75149+ if (!strcmp(rolename, trans->rolename)) {
75150+ found = 1;
75151+ break;
75152+ }
75153+ }
75154+
75155+ if (!found)
75156+ return 0;
75157+
75158+ /* handle special roles that do not require authentication
75159+ and check ip */
75160+
75161+ FOR_EACH_ROLE_START(r)
75162+ if (!strcmp(rolename, r->rolename) &&
75163+ (r->roletype & GR_ROLE_SPECIAL)) {
75164+ found = 0;
75165+ if (r->allowed_ips != NULL) {
75166+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
75167+ if ((ntohl(curr_ip) & ipp->netmask) ==
75168+ (ntohl(ipp->addr) & ipp->netmask))
75169+ found = 1;
75170+ }
75171+ } else
75172+ found = 2;
75173+ if (!found)
75174+ return 0;
75175+
75176+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
75177+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
75178+ *salt = NULL;
75179+ *sum = NULL;
75180+ return 1;
75181+ }
75182+ }
75183+ FOR_EACH_ROLE_END(r)
75184+
75185+ for (i = 0; i < polstate->num_sprole_pws; i++) {
75186+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
75187+ *salt = polstate->acl_special_roles[i]->salt;
75188+ *sum = polstate->acl_special_roles[i]->sum;
75189+ return 1;
75190+ }
75191+ }
75192+
75193+ return 0;
75194+}
75195+
75196+int gr_check_secure_terminal(struct task_struct *task)
75197+{
75198+ struct task_struct *p, *p2, *p3;
75199+ struct files_struct *files;
75200+ struct fdtable *fdt;
75201+ struct file *our_file = NULL, *file;
75202+ int i;
75203+
75204+ if (task->signal->tty == NULL)
75205+ return 1;
75206+
75207+ files = get_files_struct(task);
75208+ if (files != NULL) {
75209+ rcu_read_lock();
75210+ fdt = files_fdtable(files);
75211+ for (i=0; i < fdt->max_fds; i++) {
75212+ file = fcheck_files(files, i);
75213+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
75214+ get_file(file);
75215+ our_file = file;
75216+ }
75217+ }
75218+ rcu_read_unlock();
75219+ put_files_struct(files);
75220+ }
75221+
75222+ if (our_file == NULL)
75223+ return 1;
75224+
75225+ read_lock(&tasklist_lock);
75226+ do_each_thread(p2, p) {
75227+ files = get_files_struct(p);
75228+ if (files == NULL ||
75229+ (p->signal && p->signal->tty == task->signal->tty)) {
75230+ if (files != NULL)
75231+ put_files_struct(files);
75232+ continue;
75233+ }
75234+ rcu_read_lock();
75235+ fdt = files_fdtable(files);
75236+ for (i=0; i < fdt->max_fds; i++) {
75237+ file = fcheck_files(files, i);
75238+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
75239+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
75240+ p3 = task;
75241+ while (task_pid_nr(p3) > 0) {
75242+ if (p3 == p)
75243+ break;
75244+ p3 = p3->real_parent;
75245+ }
75246+ if (p3 == p)
75247+ break;
75248+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
75249+ gr_handle_alertkill(p);
75250+ rcu_read_unlock();
75251+ put_files_struct(files);
75252+ read_unlock(&tasklist_lock);
75253+ fput(our_file);
75254+ return 0;
75255+ }
75256+ }
75257+ rcu_read_unlock();
75258+ put_files_struct(files);
75259+ } while_each_thread(p2, p);
75260+ read_unlock(&tasklist_lock);
75261+
75262+ fput(our_file);
75263+ return 1;
75264+}
75265+
75266+ssize_t
75267+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
75268+{
75269+ struct gr_arg_wrapper uwrap;
75270+ unsigned char *sprole_salt = NULL;
75271+ unsigned char *sprole_sum = NULL;
75272+ int error = 0;
75273+ int error2 = 0;
75274+ size_t req_count = 0;
75275+ unsigned char oldmode = 0;
75276+
75277+ mutex_lock(&gr_dev_mutex);
75278+
75279+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
75280+ error = -EPERM;
75281+ goto out;
75282+ }
75283+
75284+#ifdef CONFIG_COMPAT
75285+ pax_open_kernel();
75286+ if (is_compat_task()) {
75287+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
75288+ copy_gr_arg = &copy_gr_arg_compat;
75289+ copy_acl_object_label = &copy_acl_object_label_compat;
75290+ copy_acl_subject_label = &copy_acl_subject_label_compat;
75291+ copy_acl_role_label = &copy_acl_role_label_compat;
75292+ copy_acl_ip_label = &copy_acl_ip_label_compat;
75293+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
75294+ copy_role_transition = &copy_role_transition_compat;
75295+ copy_sprole_pw = &copy_sprole_pw_compat;
75296+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
75297+ copy_pointer_from_array = &copy_pointer_from_array_compat;
75298+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
75299+ } else {
75300+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
75301+ copy_gr_arg = &copy_gr_arg_normal;
75302+ copy_acl_object_label = &copy_acl_object_label_normal;
75303+ copy_acl_subject_label = &copy_acl_subject_label_normal;
75304+ copy_acl_role_label = &copy_acl_role_label_normal;
75305+ copy_acl_ip_label = &copy_acl_ip_label_normal;
75306+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
75307+ copy_role_transition = &copy_role_transition_normal;
75308+ copy_sprole_pw = &copy_sprole_pw_normal;
75309+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
75310+ copy_pointer_from_array = &copy_pointer_from_array_normal;
75311+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
75312+ }
75313+ pax_close_kernel();
75314+#endif
75315+
75316+ req_count = get_gr_arg_wrapper_size();
75317+
75318+ if (count != req_count) {
75319+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
75320+ error = -EINVAL;
75321+ goto out;
75322+ }
75323+
75324+
75325+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
75326+ gr_auth_expires = 0;
75327+ gr_auth_attempts = 0;
75328+ }
75329+
75330+ error = copy_gr_arg_wrapper(buf, &uwrap);
75331+ if (error)
75332+ goto out;
75333+
75334+ error = copy_gr_arg(uwrap.arg, gr_usermode);
75335+ if (error)
75336+ goto out;
75337+
75338+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75339+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75340+ time_after(gr_auth_expires, get_seconds())) {
75341+ error = -EBUSY;
75342+ goto out;
75343+ }
75344+
75345+ /* if non-root trying to do anything other than use a special role,
75346+ do not attempt authentication, do not count towards authentication
75347+ locking
75348+ */
75349+
75350+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
75351+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
75352+ gr_is_global_nonroot(current_uid())) {
75353+ error = -EPERM;
75354+ goto out;
75355+ }
75356+
75357+ /* ensure pw and special role name are null terminated */
75358+
75359+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
75360+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
75361+
75362+ /* Okay.
75363+ * We have our enough of the argument structure..(we have yet
75364+ * to copy_from_user the tables themselves) . Copy the tables
75365+ * only if we need them, i.e. for loading operations. */
75366+
75367+ switch (gr_usermode->mode) {
75368+ case GR_STATUS:
75369+ if (gr_acl_is_enabled()) {
75370+ error = 1;
75371+ if (!gr_check_secure_terminal(current))
75372+ error = 3;
75373+ } else
75374+ error = 2;
75375+ goto out;
75376+ case GR_SHUTDOWN:
75377+ if (gr_acl_is_enabled() && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75378+ stop_machine(gr_rbac_disable, NULL, NULL);
75379+ free_variables(false);
75380+ memset(gr_usermode, 0, sizeof(struct gr_arg));
75381+ memset(gr_system_salt, 0, GR_SALT_LEN);
75382+ memset(gr_system_sum, 0, GR_SHA_LEN);
75383+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
75384+ } else if (gr_acl_is_enabled()) {
75385+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
75386+ error = -EPERM;
75387+ } else {
75388+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
75389+ error = -EAGAIN;
75390+ }
75391+ break;
75392+ case GR_ENABLE:
75393+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(gr_usermode)))
75394+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
75395+ else {
75396+ if (gr_acl_is_enabled())
75397+ error = -EAGAIN;
75398+ else
75399+ error = error2;
75400+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
75401+ }
75402+ break;
75403+ case GR_OLDRELOAD:
75404+ oldmode = 1;
75405+ case GR_RELOAD:
75406+ if (!gr_acl_is_enabled()) {
75407+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
75408+ error = -EAGAIN;
75409+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75410+ error2 = gracl_reload(gr_usermode, oldmode);
75411+ if (!error2)
75412+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
75413+ else {
75414+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75415+ error = error2;
75416+ }
75417+ } else {
75418+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
75419+ error = -EPERM;
75420+ }
75421+ break;
75422+ case GR_SEGVMOD:
75423+ if (unlikely(!gr_acl_is_enabled())) {
75424+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
75425+ error = -EAGAIN;
75426+ break;
75427+ }
75428+
75429+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
75430+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
75431+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
75432+ struct acl_subject_label *segvacl;
75433+ segvacl =
75434+ lookup_acl_subj_label(gr_usermode->segv_inode,
75435+ gr_usermode->segv_device,
75436+ current->role);
75437+ if (segvacl) {
75438+ segvacl->crashes = 0;
75439+ segvacl->expires = 0;
75440+ }
75441+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
75442+ gr_remove_uid(gr_usermode->segv_uid);
75443+ }
75444+ } else {
75445+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
75446+ error = -EPERM;
75447+ }
75448+ break;
75449+ case GR_SPROLE:
75450+ case GR_SPROLEPAM:
75451+ if (unlikely(!gr_acl_is_enabled())) {
75452+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
75453+ error = -EAGAIN;
75454+ break;
75455+ }
75456+
75457+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
75458+ current->role->expires = 0;
75459+ current->role->auth_attempts = 0;
75460+ }
75461+
75462+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
75463+ time_after(current->role->expires, get_seconds())) {
75464+ error = -EBUSY;
75465+ goto out;
75466+ }
75467+
75468+ if (lookup_special_role_auth
75469+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
75470+ && ((!sprole_salt && !sprole_sum)
75471+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
75472+ char *p = "";
75473+ assign_special_role(gr_usermode->sp_role);
75474+ read_lock(&tasklist_lock);
75475+ if (current->real_parent)
75476+ p = current->real_parent->role->rolename;
75477+ read_unlock(&tasklist_lock);
75478+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
75479+ p, acl_sp_role_value);
75480+ } else {
75481+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
75482+ error = -EPERM;
75483+ if(!(current->role->auth_attempts++))
75484+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75485+
75486+ goto out;
75487+ }
75488+ break;
75489+ case GR_UNSPROLE:
75490+ if (unlikely(!gr_acl_is_enabled())) {
75491+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
75492+ error = -EAGAIN;
75493+ break;
75494+ }
75495+
75496+ if (current->role->roletype & GR_ROLE_SPECIAL) {
75497+ char *p = "";
75498+ int i = 0;
75499+
75500+ read_lock(&tasklist_lock);
75501+ if (current->real_parent) {
75502+ p = current->real_parent->role->rolename;
75503+ i = current->real_parent->acl_role_id;
75504+ }
75505+ read_unlock(&tasklist_lock);
75506+
75507+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
75508+ gr_set_acls(1);
75509+ } else {
75510+ error = -EPERM;
75511+ goto out;
75512+ }
75513+ break;
75514+ default:
75515+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
75516+ error = -EINVAL;
75517+ break;
75518+ }
75519+
75520+ if (error != -EPERM)
75521+ goto out;
75522+
75523+ if(!(gr_auth_attempts++))
75524+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
75525+
75526+ out:
75527+ mutex_unlock(&gr_dev_mutex);
75528+
75529+ if (!error)
75530+ error = req_count;
75531+
75532+ return error;
75533+}
75534+
75535+int
75536+gr_set_acls(const int type)
75537+{
75538+ struct task_struct *task, *task2;
75539+ struct acl_role_label *role = current->role;
75540+ struct acl_subject_label *subj;
75541+ __u16 acl_role_id = current->acl_role_id;
75542+ const struct cred *cred;
75543+ int ret;
75544+
75545+ rcu_read_lock();
75546+ read_lock(&tasklist_lock);
75547+ read_lock(&grsec_exec_file_lock);
75548+ do_each_thread(task2, task) {
75549+ /* check to see if we're called from the exit handler,
75550+ if so, only replace ACLs that have inherited the admin
75551+ ACL */
75552+
75553+ if (type && (task->role != role ||
75554+ task->acl_role_id != acl_role_id))
75555+ continue;
75556+
75557+ task->acl_role_id = 0;
75558+ task->acl_sp_role = 0;
75559+ task->inherited = 0;
75560+
75561+ if (task->exec_file) {
75562+ cred = __task_cred(task);
75563+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
75564+ subj = __gr_get_subject_for_task(polstate, task, NULL);
75565+ if (subj == NULL) {
75566+ ret = -EINVAL;
75567+ read_unlock(&grsec_exec_file_lock);
75568+ read_unlock(&tasklist_lock);
75569+ rcu_read_unlock();
75570+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
75571+ return ret;
75572+ }
75573+ __gr_apply_subject_to_task(polstate, task, subj);
75574+ } else {
75575+ // it's a kernel process
75576+ task->role = polstate->kernel_role;
75577+ task->acl = polstate->kernel_role->root_label;
75578+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
75579+ task->acl->mode &= ~GR_PROCFIND;
75580+#endif
75581+ }
75582+ } while_each_thread(task2, task);
75583+ read_unlock(&grsec_exec_file_lock);
75584+ read_unlock(&tasklist_lock);
75585+ rcu_read_unlock();
75586+
75587+ return 0;
75588+}
75589diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
75590new file mode 100644
75591index 0000000..39645c9
75592--- /dev/null
75593+++ b/grsecurity/gracl_res.c
75594@@ -0,0 +1,68 @@
75595+#include <linux/kernel.h>
75596+#include <linux/sched.h>
75597+#include <linux/gracl.h>
75598+#include <linux/grinternal.h>
75599+
75600+static const char *restab_log[] = {
75601+ [RLIMIT_CPU] = "RLIMIT_CPU",
75602+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
75603+ [RLIMIT_DATA] = "RLIMIT_DATA",
75604+ [RLIMIT_STACK] = "RLIMIT_STACK",
75605+ [RLIMIT_CORE] = "RLIMIT_CORE",
75606+ [RLIMIT_RSS] = "RLIMIT_RSS",
75607+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
75608+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
75609+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
75610+ [RLIMIT_AS] = "RLIMIT_AS",
75611+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
75612+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
75613+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
75614+ [RLIMIT_NICE] = "RLIMIT_NICE",
75615+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
75616+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
75617+ [GR_CRASH_RES] = "RLIMIT_CRASH"
75618+};
75619+
75620+void
75621+gr_log_resource(const struct task_struct *task,
75622+ const int res, const unsigned long wanted, const int gt)
75623+{
75624+ const struct cred *cred;
75625+ unsigned long rlim;
75626+
75627+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
75628+ return;
75629+
75630+ // not yet supported resource
75631+ if (unlikely(!restab_log[res]))
75632+ return;
75633+
75634+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
75635+ rlim = task_rlimit_max(task, res);
75636+ else
75637+ rlim = task_rlimit(task, res);
75638+
75639+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
75640+ return;
75641+
75642+ rcu_read_lock();
75643+ cred = __task_cred(task);
75644+
75645+ if (res == RLIMIT_NPROC &&
75646+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
75647+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
75648+ goto out_rcu_unlock;
75649+ else if (res == RLIMIT_MEMLOCK &&
75650+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
75651+ goto out_rcu_unlock;
75652+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
75653+ goto out_rcu_unlock;
75654+ rcu_read_unlock();
75655+
75656+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
75657+
75658+ return;
75659+out_rcu_unlock:
75660+ rcu_read_unlock();
75661+ return;
75662+}
75663diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
75664new file mode 100644
75665index 0000000..2040e61
75666--- /dev/null
75667+++ b/grsecurity/gracl_segv.c
75668@@ -0,0 +1,313 @@
75669+#include <linux/kernel.h>
75670+#include <linux/mm.h>
75671+#include <asm/uaccess.h>
75672+#include <asm/errno.h>
75673+#include <asm/mman.h>
75674+#include <net/sock.h>
75675+#include <linux/file.h>
75676+#include <linux/fs.h>
75677+#include <linux/net.h>
75678+#include <linux/in.h>
75679+#include <linux/slab.h>
75680+#include <linux/types.h>
75681+#include <linux/sched.h>
75682+#include <linux/timer.h>
75683+#include <linux/gracl.h>
75684+#include <linux/grsecurity.h>
75685+#include <linux/grinternal.h>
75686+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75687+#include <linux/magic.h>
75688+#include <linux/pagemap.h>
75689+#include "../fs/btrfs/async-thread.h"
75690+#include "../fs/btrfs/ctree.h"
75691+#include "../fs/btrfs/btrfs_inode.h"
75692+#endif
75693+
75694+static struct crash_uid *uid_set;
75695+static unsigned short uid_used;
75696+static DEFINE_SPINLOCK(gr_uid_lock);
75697+extern rwlock_t gr_inode_lock;
75698+extern struct acl_subject_label *
75699+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
75700+ struct acl_role_label *role);
75701+
75702+static inline dev_t __get_dev(const struct dentry *dentry)
75703+{
75704+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
75705+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
75706+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
75707+ else
75708+#endif
75709+ return dentry->d_sb->s_dev;
75710+}
75711+
75712+int
75713+gr_init_uidset(void)
75714+{
75715+ uid_set =
75716+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
75717+ uid_used = 0;
75718+
75719+ return uid_set ? 1 : 0;
75720+}
75721+
75722+void
75723+gr_free_uidset(void)
75724+{
75725+ if (uid_set) {
75726+ struct crash_uid *tmpset;
75727+ spin_lock(&gr_uid_lock);
75728+ tmpset = uid_set;
75729+ uid_set = NULL;
75730+ uid_used = 0;
75731+ spin_unlock(&gr_uid_lock);
75732+ if (tmpset)
75733+ kfree(tmpset);
75734+ }
75735+
75736+ return;
75737+}
75738+
75739+int
75740+gr_find_uid(const uid_t uid)
75741+{
75742+ struct crash_uid *tmp = uid_set;
75743+ uid_t buid;
75744+ int low = 0, high = uid_used - 1, mid;
75745+
75746+ while (high >= low) {
75747+ mid = (low + high) >> 1;
75748+ buid = tmp[mid].uid;
75749+ if (buid == uid)
75750+ return mid;
75751+ if (buid > uid)
75752+ high = mid - 1;
75753+ if (buid < uid)
75754+ low = mid + 1;
75755+ }
75756+
75757+ return -1;
75758+}
75759+
75760+static __inline__ void
75761+gr_insertsort(void)
75762+{
75763+ unsigned short i, j;
75764+ struct crash_uid index;
75765+
75766+ for (i = 1; i < uid_used; i++) {
75767+ index = uid_set[i];
75768+ j = i;
75769+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
75770+ uid_set[j] = uid_set[j - 1];
75771+ j--;
75772+ }
75773+ uid_set[j] = index;
75774+ }
75775+
75776+ return;
75777+}
75778+
75779+static __inline__ void
75780+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
75781+{
75782+ int loc;
75783+ uid_t uid = GR_GLOBAL_UID(kuid);
75784+
75785+ if (uid_used == GR_UIDTABLE_MAX)
75786+ return;
75787+
75788+ loc = gr_find_uid(uid);
75789+
75790+ if (loc >= 0) {
75791+ uid_set[loc].expires = expires;
75792+ return;
75793+ }
75794+
75795+ uid_set[uid_used].uid = uid;
75796+ uid_set[uid_used].expires = expires;
75797+ uid_used++;
75798+
75799+ gr_insertsort();
75800+
75801+ return;
75802+}
75803+
75804+void
75805+gr_remove_uid(const unsigned short loc)
75806+{
75807+ unsigned short i;
75808+
75809+ for (i = loc + 1; i < uid_used; i++)
75810+ uid_set[i - 1] = uid_set[i];
75811+
75812+ uid_used--;
75813+
75814+ return;
75815+}
75816+
75817+int
75818+gr_check_crash_uid(const kuid_t kuid)
75819+{
75820+ int loc;
75821+ int ret = 0;
75822+ uid_t uid;
75823+
75824+ if (unlikely(!gr_acl_is_enabled()))
75825+ return 0;
75826+
75827+ uid = GR_GLOBAL_UID(kuid);
75828+
75829+ spin_lock(&gr_uid_lock);
75830+ loc = gr_find_uid(uid);
75831+
75832+ if (loc < 0)
75833+ goto out_unlock;
75834+
75835+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
75836+ gr_remove_uid(loc);
75837+ else
75838+ ret = 1;
75839+
75840+out_unlock:
75841+ spin_unlock(&gr_uid_lock);
75842+ return ret;
75843+}
75844+
75845+static __inline__ int
75846+proc_is_setxid(const struct cred *cred)
75847+{
75848+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
75849+ !uid_eq(cred->uid, cred->fsuid))
75850+ return 1;
75851+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
75852+ !gid_eq(cred->gid, cred->fsgid))
75853+ return 1;
75854+
75855+ return 0;
75856+}
75857+
75858+extern int gr_fake_force_sig(int sig, struct task_struct *t);
75859+
75860+void
75861+gr_handle_crash(struct task_struct *task, const int sig)
75862+{
75863+ struct acl_subject_label *curr;
75864+ struct task_struct *tsk, *tsk2;
75865+ const struct cred *cred;
75866+ const struct cred *cred2;
75867+
75868+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
75869+ return;
75870+
75871+ if (unlikely(!gr_acl_is_enabled()))
75872+ return;
75873+
75874+ curr = task->acl;
75875+
75876+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
75877+ return;
75878+
75879+ if (time_before_eq(curr->expires, get_seconds())) {
75880+ curr->expires = 0;
75881+ curr->crashes = 0;
75882+ }
75883+
75884+ curr->crashes++;
75885+
75886+ if (!curr->expires)
75887+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
75888+
75889+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75890+ time_after(curr->expires, get_seconds())) {
75891+ rcu_read_lock();
75892+ cred = __task_cred(task);
75893+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
75894+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75895+ spin_lock(&gr_uid_lock);
75896+ gr_insert_uid(cred->uid, curr->expires);
75897+ spin_unlock(&gr_uid_lock);
75898+ curr->expires = 0;
75899+ curr->crashes = 0;
75900+ read_lock(&tasklist_lock);
75901+ do_each_thread(tsk2, tsk) {
75902+ cred2 = __task_cred(tsk);
75903+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
75904+ gr_fake_force_sig(SIGKILL, tsk);
75905+ } while_each_thread(tsk2, tsk);
75906+ read_unlock(&tasklist_lock);
75907+ } else {
75908+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
75909+ read_lock(&tasklist_lock);
75910+ read_lock(&grsec_exec_file_lock);
75911+ do_each_thread(tsk2, tsk) {
75912+ if (likely(tsk != task)) {
75913+ // if this thread has the same subject as the one that triggered
75914+ // RES_CRASH and it's the same binary, kill it
75915+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
75916+ gr_fake_force_sig(SIGKILL, tsk);
75917+ }
75918+ } while_each_thread(tsk2, tsk);
75919+ read_unlock(&grsec_exec_file_lock);
75920+ read_unlock(&tasklist_lock);
75921+ }
75922+ rcu_read_unlock();
75923+ }
75924+
75925+ return;
75926+}
75927+
75928+int
75929+gr_check_crash_exec(const struct file *filp)
75930+{
75931+ struct acl_subject_label *curr;
75932+
75933+ if (unlikely(!gr_acl_is_enabled()))
75934+ return 0;
75935+
75936+ read_lock(&gr_inode_lock);
75937+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
75938+ __get_dev(filp->f_path.dentry),
75939+ current->role);
75940+ read_unlock(&gr_inode_lock);
75941+
75942+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
75943+ (!curr->crashes && !curr->expires))
75944+ return 0;
75945+
75946+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
75947+ time_after(curr->expires, get_seconds()))
75948+ return 1;
75949+ else if (time_before_eq(curr->expires, get_seconds())) {
75950+ curr->crashes = 0;
75951+ curr->expires = 0;
75952+ }
75953+
75954+ return 0;
75955+}
75956+
75957+void
75958+gr_handle_alertkill(struct task_struct *task)
75959+{
75960+ struct acl_subject_label *curracl;
75961+ __u32 curr_ip;
75962+ struct task_struct *p, *p2;
75963+
75964+ if (unlikely(!gr_acl_is_enabled()))
75965+ return;
75966+
75967+ curracl = task->acl;
75968+ curr_ip = task->signal->curr_ip;
75969+
75970+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
75971+ read_lock(&tasklist_lock);
75972+ do_each_thread(p2, p) {
75973+ if (p->signal->curr_ip == curr_ip)
75974+ gr_fake_force_sig(SIGKILL, p);
75975+ } while_each_thread(p2, p);
75976+ read_unlock(&tasklist_lock);
75977+ } else if (curracl->mode & GR_KILLPROC)
75978+ gr_fake_force_sig(SIGKILL, task);
75979+
75980+ return;
75981+}
75982diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
75983new file mode 100644
75984index 0000000..6b0c9cc
75985--- /dev/null
75986+++ b/grsecurity/gracl_shm.c
75987@@ -0,0 +1,40 @@
75988+#include <linux/kernel.h>
75989+#include <linux/mm.h>
75990+#include <linux/sched.h>
75991+#include <linux/file.h>
75992+#include <linux/ipc.h>
75993+#include <linux/gracl.h>
75994+#include <linux/grsecurity.h>
75995+#include <linux/grinternal.h>
75996+
75997+int
75998+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
75999+ const u64 shm_createtime, const kuid_t cuid, const int shmid)
76000+{
76001+ struct task_struct *task;
76002+
76003+ if (!gr_acl_is_enabled())
76004+ return 1;
76005+
76006+ rcu_read_lock();
76007+ read_lock(&tasklist_lock);
76008+
76009+ task = find_task_by_vpid(shm_cprid);
76010+
76011+ if (unlikely(!task))
76012+ task = find_task_by_vpid(shm_lapid);
76013+
76014+ if (unlikely(task && (time_before_eq64(task->start_time, shm_createtime) ||
76015+ (task_pid_nr(task) == shm_lapid)) &&
76016+ (task->acl->mode & GR_PROTSHM) &&
76017+ (task->acl != current->acl))) {
76018+ read_unlock(&tasklist_lock);
76019+ rcu_read_unlock();
76020+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
76021+ return 0;
76022+ }
76023+ read_unlock(&tasklist_lock);
76024+ rcu_read_unlock();
76025+
76026+ return 1;
76027+}
76028diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
76029new file mode 100644
76030index 0000000..bc0be01
76031--- /dev/null
76032+++ b/grsecurity/grsec_chdir.c
76033@@ -0,0 +1,19 @@
76034+#include <linux/kernel.h>
76035+#include <linux/sched.h>
76036+#include <linux/fs.h>
76037+#include <linux/file.h>
76038+#include <linux/grsecurity.h>
76039+#include <linux/grinternal.h>
76040+
76041+void
76042+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
76043+{
76044+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76045+ if ((grsec_enable_chdir && grsec_enable_group &&
76046+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
76047+ !grsec_enable_group)) {
76048+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
76049+ }
76050+#endif
76051+ return;
76052+}
76053diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
76054new file mode 100644
76055index 0000000..6d99cec
76056--- /dev/null
76057+++ b/grsecurity/grsec_chroot.c
76058@@ -0,0 +1,385 @@
76059+#include <linux/kernel.h>
76060+#include <linux/module.h>
76061+#include <linux/sched.h>
76062+#include <linux/file.h>
76063+#include <linux/fs.h>
76064+#include <linux/mount.h>
76065+#include <linux/types.h>
76066+#include "../fs/mount.h"
76067+#include <linux/grsecurity.h>
76068+#include <linux/grinternal.h>
76069+
76070+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76071+int gr_init_ran;
76072+#endif
76073+
76074+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
76075+{
76076+#ifdef CONFIG_GRKERNSEC
76077+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
76078+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
76079+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76080+ && gr_init_ran
76081+#endif
76082+ )
76083+ task->gr_is_chrooted = 1;
76084+ else {
76085+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
76086+ if (task_pid_nr(task) == 1 && !gr_init_ran)
76087+ gr_init_ran = 1;
76088+#endif
76089+ task->gr_is_chrooted = 0;
76090+ }
76091+
76092+ task->gr_chroot_dentry = path->dentry;
76093+#endif
76094+ return;
76095+}
76096+
76097+void gr_clear_chroot_entries(struct task_struct *task)
76098+{
76099+#ifdef CONFIG_GRKERNSEC
76100+ task->gr_is_chrooted = 0;
76101+ task->gr_chroot_dentry = NULL;
76102+#endif
76103+ return;
76104+}
76105+
76106+int
76107+gr_handle_chroot_unix(const pid_t pid)
76108+{
76109+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76110+ struct task_struct *p;
76111+
76112+ if (unlikely(!grsec_enable_chroot_unix))
76113+ return 1;
76114+
76115+ if (likely(!proc_is_chrooted(current)))
76116+ return 1;
76117+
76118+ rcu_read_lock();
76119+ read_lock(&tasklist_lock);
76120+ p = find_task_by_vpid_unrestricted(pid);
76121+ if (unlikely(p && !have_same_root(current, p))) {
76122+ read_unlock(&tasklist_lock);
76123+ rcu_read_unlock();
76124+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
76125+ return 0;
76126+ }
76127+ read_unlock(&tasklist_lock);
76128+ rcu_read_unlock();
76129+#endif
76130+ return 1;
76131+}
76132+
76133+int
76134+gr_handle_chroot_nice(void)
76135+{
76136+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76137+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
76138+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
76139+ return -EPERM;
76140+ }
76141+#endif
76142+ return 0;
76143+}
76144+
76145+int
76146+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
76147+{
76148+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76149+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
76150+ && proc_is_chrooted(current)) {
76151+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
76152+ return -EACCES;
76153+ }
76154+#endif
76155+ return 0;
76156+}
76157+
76158+int
76159+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
76160+{
76161+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76162+ struct task_struct *p;
76163+ int ret = 0;
76164+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
76165+ return ret;
76166+
76167+ read_lock(&tasklist_lock);
76168+ do_each_pid_task(pid, type, p) {
76169+ if (!have_same_root(current, p)) {
76170+ ret = 1;
76171+ goto out;
76172+ }
76173+ } while_each_pid_task(pid, type, p);
76174+out:
76175+ read_unlock(&tasklist_lock);
76176+ return ret;
76177+#endif
76178+ return 0;
76179+}
76180+
76181+int
76182+gr_pid_is_chrooted(struct task_struct *p)
76183+{
76184+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76185+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
76186+ return 0;
76187+
76188+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
76189+ !have_same_root(current, p)) {
76190+ return 1;
76191+ }
76192+#endif
76193+ return 0;
76194+}
76195+
76196+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
76197+
76198+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
76199+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
76200+{
76201+ struct path path, currentroot;
76202+ int ret = 0;
76203+
76204+ path.dentry = (struct dentry *)u_dentry;
76205+ path.mnt = (struct vfsmount *)u_mnt;
76206+ get_fs_root(current->fs, &currentroot);
76207+ if (path_is_under(&path, &currentroot))
76208+ ret = 1;
76209+ path_put(&currentroot);
76210+
76211+ return ret;
76212+}
76213+#endif
76214+
76215+int
76216+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
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 if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
76225+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
76226+ return 0;
76227+ }
76228+#endif
76229+ return 1;
76230+}
76231+
76232+int
76233+gr_chroot_fhandle(void)
76234+{
76235+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76236+ if (!grsec_enable_chroot_fchdir)
76237+ return 1;
76238+
76239+ if (!proc_is_chrooted(current))
76240+ return 1;
76241+ else {
76242+ gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
76243+ return 0;
76244+ }
76245+#endif
76246+ return 1;
76247+}
76248+
76249+int
76250+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76251+ const u64 shm_createtime)
76252+{
76253+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76254+ struct task_struct *p;
76255+
76256+ if (unlikely(!grsec_enable_chroot_shmat))
76257+ return 1;
76258+
76259+ if (likely(!proc_is_chrooted(current)))
76260+ return 1;
76261+
76262+ rcu_read_lock();
76263+ read_lock(&tasklist_lock);
76264+
76265+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
76266+ if (time_before_eq64(p->start_time, shm_createtime)) {
76267+ if (have_same_root(current, p)) {
76268+ goto allow;
76269+ } else {
76270+ read_unlock(&tasklist_lock);
76271+ rcu_read_unlock();
76272+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76273+ return 0;
76274+ }
76275+ }
76276+ /* creator exited, pid reuse, fall through to next check */
76277+ }
76278+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
76279+ if (unlikely(!have_same_root(current, p))) {
76280+ read_unlock(&tasklist_lock);
76281+ rcu_read_unlock();
76282+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
76283+ return 0;
76284+ }
76285+ }
76286+
76287+allow:
76288+ read_unlock(&tasklist_lock);
76289+ rcu_read_unlock();
76290+#endif
76291+ return 1;
76292+}
76293+
76294+void
76295+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
76296+{
76297+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76298+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
76299+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
76300+#endif
76301+ return;
76302+}
76303+
76304+int
76305+gr_handle_chroot_mknod(const struct dentry *dentry,
76306+ const struct vfsmount *mnt, const int mode)
76307+{
76308+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76309+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
76310+ proc_is_chrooted(current)) {
76311+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
76312+ return -EPERM;
76313+ }
76314+#endif
76315+ return 0;
76316+}
76317+
76318+int
76319+gr_handle_chroot_mount(const struct dentry *dentry,
76320+ const struct vfsmount *mnt, const char *dev_name)
76321+{
76322+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76323+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
76324+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
76325+ return -EPERM;
76326+ }
76327+#endif
76328+ return 0;
76329+}
76330+
76331+int
76332+gr_handle_chroot_pivot(void)
76333+{
76334+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76335+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
76336+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
76337+ return -EPERM;
76338+ }
76339+#endif
76340+ return 0;
76341+}
76342+
76343+int
76344+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
76345+{
76346+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76347+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
76348+ !gr_is_outside_chroot(dentry, mnt)) {
76349+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
76350+ return -EPERM;
76351+ }
76352+#endif
76353+ return 0;
76354+}
76355+
76356+extern const char *captab_log[];
76357+extern int captab_log_entries;
76358+
76359+int
76360+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
76361+{
76362+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76363+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76364+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76365+ if (cap_raised(chroot_caps, cap)) {
76366+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
76367+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
76368+ }
76369+ return 0;
76370+ }
76371+ }
76372+#endif
76373+ return 1;
76374+}
76375+
76376+int
76377+gr_chroot_is_capable(const int cap)
76378+{
76379+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76380+ return gr_task_chroot_is_capable(current, current_cred(), cap);
76381+#endif
76382+ return 1;
76383+}
76384+
76385+int
76386+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
76387+{
76388+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76389+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
76390+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
76391+ if (cap_raised(chroot_caps, cap)) {
76392+ return 0;
76393+ }
76394+ }
76395+#endif
76396+ return 1;
76397+}
76398+
76399+int
76400+gr_chroot_is_capable_nolog(const int cap)
76401+{
76402+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76403+ return gr_task_chroot_is_capable_nolog(current, cap);
76404+#endif
76405+ return 1;
76406+}
76407+
76408+int
76409+gr_handle_chroot_sysctl(const int op)
76410+{
76411+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76412+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
76413+ proc_is_chrooted(current))
76414+ return -EACCES;
76415+#endif
76416+ return 0;
76417+}
76418+
76419+void
76420+gr_handle_chroot_chdir(const struct path *path)
76421+{
76422+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76423+ if (grsec_enable_chroot_chdir)
76424+ set_fs_pwd(current->fs, path);
76425+#endif
76426+ return;
76427+}
76428+
76429+int
76430+gr_handle_chroot_chmod(const struct dentry *dentry,
76431+ const struct vfsmount *mnt, const int mode)
76432+{
76433+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76434+ /* allow chmod +s on directories, but not files */
76435+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
76436+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
76437+ proc_is_chrooted(current)) {
76438+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
76439+ return -EPERM;
76440+ }
76441+#endif
76442+ return 0;
76443+}
76444diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
76445new file mode 100644
76446index 0000000..0f9ac91
76447--- /dev/null
76448+++ b/grsecurity/grsec_disabled.c
76449@@ -0,0 +1,440 @@
76450+#include <linux/kernel.h>
76451+#include <linux/module.h>
76452+#include <linux/sched.h>
76453+#include <linux/file.h>
76454+#include <linux/fs.h>
76455+#include <linux/kdev_t.h>
76456+#include <linux/net.h>
76457+#include <linux/in.h>
76458+#include <linux/ip.h>
76459+#include <linux/skbuff.h>
76460+#include <linux/sysctl.h>
76461+
76462+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
76463+void
76464+pax_set_initial_flags(struct linux_binprm *bprm)
76465+{
76466+ return;
76467+}
76468+#endif
76469+
76470+#ifdef CONFIG_SYSCTL
76471+__u32
76472+gr_handle_sysctl(const struct ctl_table * table, const int op)
76473+{
76474+ return 0;
76475+}
76476+#endif
76477+
76478+#ifdef CONFIG_TASKSTATS
76479+int gr_is_taskstats_denied(int pid)
76480+{
76481+ return 0;
76482+}
76483+#endif
76484+
76485+int
76486+gr_acl_is_enabled(void)
76487+{
76488+ return 0;
76489+}
76490+
76491+int
76492+gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap)
76493+{
76494+ return 0;
76495+}
76496+
76497+void
76498+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
76499+{
76500+ return;
76501+}
76502+
76503+int
76504+gr_handle_rawio(const struct inode *inode)
76505+{
76506+ return 0;
76507+}
76508+
76509+void
76510+gr_acl_handle_psacct(struct task_struct *task, const long code)
76511+{
76512+ return;
76513+}
76514+
76515+int
76516+gr_handle_ptrace(struct task_struct *task, const long request)
76517+{
76518+ return 0;
76519+}
76520+
76521+int
76522+gr_handle_proc_ptrace(struct task_struct *task)
76523+{
76524+ return 0;
76525+}
76526+
76527+int
76528+gr_set_acls(const int type)
76529+{
76530+ return 0;
76531+}
76532+
76533+int
76534+gr_check_hidden_task(const struct task_struct *tsk)
76535+{
76536+ return 0;
76537+}
76538+
76539+int
76540+gr_check_protected_task(const struct task_struct *task)
76541+{
76542+ return 0;
76543+}
76544+
76545+int
76546+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
76547+{
76548+ return 0;
76549+}
76550+
76551+void
76552+gr_copy_label(struct task_struct *tsk)
76553+{
76554+ return;
76555+}
76556+
76557+void
76558+gr_set_pax_flags(struct task_struct *task)
76559+{
76560+ return;
76561+}
76562+
76563+int
76564+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
76565+ const int unsafe_share)
76566+{
76567+ return 0;
76568+}
76569+
76570+void
76571+gr_handle_delete(const ino_t ino, const dev_t dev)
76572+{
76573+ return;
76574+}
76575+
76576+void
76577+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
76578+{
76579+ return;
76580+}
76581+
76582+void
76583+gr_handle_crash(struct task_struct *task, const int sig)
76584+{
76585+ return;
76586+}
76587+
76588+int
76589+gr_check_crash_exec(const struct file *filp)
76590+{
76591+ return 0;
76592+}
76593+
76594+int
76595+gr_check_crash_uid(const kuid_t uid)
76596+{
76597+ return 0;
76598+}
76599+
76600+void
76601+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
76602+ struct dentry *old_dentry,
76603+ struct dentry *new_dentry,
76604+ struct vfsmount *mnt, const __u8 replace, unsigned int flags)
76605+{
76606+ return;
76607+}
76608+
76609+int
76610+gr_search_socket(const int family, const int type, const int protocol)
76611+{
76612+ return 1;
76613+}
76614+
76615+int
76616+gr_search_connectbind(const int mode, const struct socket *sock,
76617+ const struct sockaddr_in *addr)
76618+{
76619+ return 0;
76620+}
76621+
76622+void
76623+gr_handle_alertkill(struct task_struct *task)
76624+{
76625+ return;
76626+}
76627+
76628+__u32
76629+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
76630+{
76631+ return 1;
76632+}
76633+
76634+__u32
76635+gr_acl_handle_hidden_file(const struct dentry * dentry,
76636+ const struct vfsmount * mnt)
76637+{
76638+ return 1;
76639+}
76640+
76641+__u32
76642+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
76643+ int acc_mode)
76644+{
76645+ return 1;
76646+}
76647+
76648+__u32
76649+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
76650+{
76651+ return 1;
76652+}
76653+
76654+__u32
76655+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
76656+{
76657+ return 1;
76658+}
76659+
76660+int
76661+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
76662+ unsigned int *vm_flags)
76663+{
76664+ return 1;
76665+}
76666+
76667+__u32
76668+gr_acl_handle_truncate(const struct dentry * dentry,
76669+ const struct vfsmount * mnt)
76670+{
76671+ return 1;
76672+}
76673+
76674+__u32
76675+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
76676+{
76677+ return 1;
76678+}
76679+
76680+__u32
76681+gr_acl_handle_access(const struct dentry * dentry,
76682+ const struct vfsmount * mnt, const int fmode)
76683+{
76684+ return 1;
76685+}
76686+
76687+__u32
76688+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
76689+ umode_t *mode)
76690+{
76691+ return 1;
76692+}
76693+
76694+__u32
76695+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
76696+{
76697+ return 1;
76698+}
76699+
76700+__u32
76701+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
76702+{
76703+ return 1;
76704+}
76705+
76706+__u32
76707+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
76708+{
76709+ return 1;
76710+}
76711+
76712+void
76713+grsecurity_init(void)
76714+{
76715+ return;
76716+}
76717+
76718+umode_t gr_acl_umask(void)
76719+{
76720+ return 0;
76721+}
76722+
76723+__u32
76724+gr_acl_handle_mknod(const struct dentry * new_dentry,
76725+ const struct dentry * parent_dentry,
76726+ const struct vfsmount * parent_mnt,
76727+ const int mode)
76728+{
76729+ return 1;
76730+}
76731+
76732+__u32
76733+gr_acl_handle_mkdir(const struct dentry * new_dentry,
76734+ const struct dentry * parent_dentry,
76735+ const struct vfsmount * parent_mnt)
76736+{
76737+ return 1;
76738+}
76739+
76740+__u32
76741+gr_acl_handle_symlink(const struct dentry * new_dentry,
76742+ const struct dentry * parent_dentry,
76743+ const struct vfsmount * parent_mnt, const struct filename *from)
76744+{
76745+ return 1;
76746+}
76747+
76748+__u32
76749+gr_acl_handle_link(const struct dentry * new_dentry,
76750+ const struct dentry * parent_dentry,
76751+ const struct vfsmount * parent_mnt,
76752+ const struct dentry * old_dentry,
76753+ const struct vfsmount * old_mnt, const struct filename *to)
76754+{
76755+ return 1;
76756+}
76757+
76758+int
76759+gr_acl_handle_rename(const struct dentry *new_dentry,
76760+ const struct dentry *parent_dentry,
76761+ const struct vfsmount *parent_mnt,
76762+ const struct dentry *old_dentry,
76763+ const struct inode *old_parent_inode,
76764+ const struct vfsmount *old_mnt, const struct filename *newname,
76765+ unsigned int flags)
76766+{
76767+ return 0;
76768+}
76769+
76770+int
76771+gr_acl_handle_filldir(const struct file *file, const char *name,
76772+ const int namelen, const ino_t ino)
76773+{
76774+ return 1;
76775+}
76776+
76777+int
76778+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
76779+ const u64 shm_createtime, const kuid_t cuid, const int shmid)
76780+{
76781+ return 1;
76782+}
76783+
76784+int
76785+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
76786+{
76787+ return 0;
76788+}
76789+
76790+int
76791+gr_search_accept(const struct socket *sock)
76792+{
76793+ return 0;
76794+}
76795+
76796+int
76797+gr_search_listen(const struct socket *sock)
76798+{
76799+ return 0;
76800+}
76801+
76802+int
76803+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
76804+{
76805+ return 0;
76806+}
76807+
76808+__u32
76809+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
76810+{
76811+ return 1;
76812+}
76813+
76814+__u32
76815+gr_acl_handle_creat(const struct dentry * dentry,
76816+ const struct dentry * p_dentry,
76817+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
76818+ const int imode)
76819+{
76820+ return 1;
76821+}
76822+
76823+void
76824+gr_acl_handle_exit(void)
76825+{
76826+ return;
76827+}
76828+
76829+int
76830+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
76831+{
76832+ return 1;
76833+}
76834+
76835+void
76836+gr_set_role_label(const kuid_t uid, const kgid_t gid)
76837+{
76838+ return;
76839+}
76840+
76841+int
76842+gr_acl_handle_procpidmem(const struct task_struct *task)
76843+{
76844+ return 0;
76845+}
76846+
76847+int
76848+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
76849+{
76850+ return 0;
76851+}
76852+
76853+int
76854+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
76855+{
76856+ return 0;
76857+}
76858+
76859+int
76860+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
76861+{
76862+ return 0;
76863+}
76864+
76865+int
76866+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
76867+{
76868+ return 0;
76869+}
76870+
76871+int gr_acl_enable_at_secure(void)
76872+{
76873+ return 0;
76874+}
76875+
76876+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
76877+{
76878+ return dentry->d_sb->s_dev;
76879+}
76880+
76881+void gr_put_exec_file(struct task_struct *task)
76882+{
76883+ return;
76884+}
76885+
76886+#ifdef CONFIG_SECURITY
76887+EXPORT_SYMBOL_GPL(gr_check_user_change);
76888+EXPORT_SYMBOL_GPL(gr_check_group_change);
76889+#endif
76890diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
76891new file mode 100644
76892index 0000000..14638ff
76893--- /dev/null
76894+++ b/grsecurity/grsec_exec.c
76895@@ -0,0 +1,188 @@
76896+#include <linux/kernel.h>
76897+#include <linux/sched.h>
76898+#include <linux/file.h>
76899+#include <linux/binfmts.h>
76900+#include <linux/fs.h>
76901+#include <linux/types.h>
76902+#include <linux/grdefs.h>
76903+#include <linux/grsecurity.h>
76904+#include <linux/grinternal.h>
76905+#include <linux/capability.h>
76906+#include <linux/module.h>
76907+#include <linux/compat.h>
76908+
76909+#include <asm/uaccess.h>
76910+
76911+#ifdef CONFIG_GRKERNSEC_EXECLOG
76912+static char gr_exec_arg_buf[132];
76913+static DEFINE_MUTEX(gr_exec_arg_mutex);
76914+#endif
76915+
76916+struct user_arg_ptr {
76917+#ifdef CONFIG_COMPAT
76918+ bool is_compat;
76919+#endif
76920+ union {
76921+ const char __user *const __user *native;
76922+#ifdef CONFIG_COMPAT
76923+ const compat_uptr_t __user *compat;
76924+#endif
76925+ } ptr;
76926+};
76927+
76928+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
76929+
76930+void
76931+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
76932+{
76933+#ifdef CONFIG_GRKERNSEC_EXECLOG
76934+ char *grarg = gr_exec_arg_buf;
76935+ unsigned int i, x, execlen = 0;
76936+ char c;
76937+
76938+ if (!((grsec_enable_execlog && grsec_enable_group &&
76939+ in_group_p(grsec_audit_gid))
76940+ || (grsec_enable_execlog && !grsec_enable_group)))
76941+ return;
76942+
76943+ mutex_lock(&gr_exec_arg_mutex);
76944+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
76945+
76946+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
76947+ const char __user *p;
76948+ unsigned int len;
76949+
76950+ p = get_user_arg_ptr(argv, i);
76951+ if (IS_ERR(p))
76952+ goto log;
76953+
76954+ len = strnlen_user(p, 128 - execlen);
76955+ if (len > 128 - execlen)
76956+ len = 128 - execlen;
76957+ else if (len > 0)
76958+ len--;
76959+ if (copy_from_user(grarg + execlen, p, len))
76960+ goto log;
76961+
76962+ /* rewrite unprintable characters */
76963+ for (x = 0; x < len; x++) {
76964+ c = *(grarg + execlen + x);
76965+ if (c < 32 || c > 126)
76966+ *(grarg + execlen + x) = ' ';
76967+ }
76968+
76969+ execlen += len;
76970+ *(grarg + execlen) = ' ';
76971+ *(grarg + execlen + 1) = '\0';
76972+ execlen++;
76973+ }
76974+
76975+ log:
76976+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
76977+ bprm->file->f_path.mnt, grarg);
76978+ mutex_unlock(&gr_exec_arg_mutex);
76979+#endif
76980+ return;
76981+}
76982+
76983+#ifdef CONFIG_GRKERNSEC
76984+extern int gr_acl_is_capable(const int cap);
76985+extern int gr_acl_is_capable_nolog(const int cap);
76986+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
76987+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
76988+extern int gr_chroot_is_capable(const int cap);
76989+extern int gr_chroot_is_capable_nolog(const int cap);
76990+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
76991+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
76992+#endif
76993+
76994+const char *captab_log[] = {
76995+ "CAP_CHOWN",
76996+ "CAP_DAC_OVERRIDE",
76997+ "CAP_DAC_READ_SEARCH",
76998+ "CAP_FOWNER",
76999+ "CAP_FSETID",
77000+ "CAP_KILL",
77001+ "CAP_SETGID",
77002+ "CAP_SETUID",
77003+ "CAP_SETPCAP",
77004+ "CAP_LINUX_IMMUTABLE",
77005+ "CAP_NET_BIND_SERVICE",
77006+ "CAP_NET_BROADCAST",
77007+ "CAP_NET_ADMIN",
77008+ "CAP_NET_RAW",
77009+ "CAP_IPC_LOCK",
77010+ "CAP_IPC_OWNER",
77011+ "CAP_SYS_MODULE",
77012+ "CAP_SYS_RAWIO",
77013+ "CAP_SYS_CHROOT",
77014+ "CAP_SYS_PTRACE",
77015+ "CAP_SYS_PACCT",
77016+ "CAP_SYS_ADMIN",
77017+ "CAP_SYS_BOOT",
77018+ "CAP_SYS_NICE",
77019+ "CAP_SYS_RESOURCE",
77020+ "CAP_SYS_TIME",
77021+ "CAP_SYS_TTY_CONFIG",
77022+ "CAP_MKNOD",
77023+ "CAP_LEASE",
77024+ "CAP_AUDIT_WRITE",
77025+ "CAP_AUDIT_CONTROL",
77026+ "CAP_SETFCAP",
77027+ "CAP_MAC_OVERRIDE",
77028+ "CAP_MAC_ADMIN",
77029+ "CAP_SYSLOG",
77030+ "CAP_WAKE_ALARM",
77031+ "CAP_BLOCK_SUSPEND"
77032+};
77033+
77034+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
77035+
77036+int gr_is_capable(const int cap)
77037+{
77038+#ifdef CONFIG_GRKERNSEC
77039+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
77040+ return 1;
77041+ return 0;
77042+#else
77043+ return 1;
77044+#endif
77045+}
77046+
77047+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
77048+{
77049+#ifdef CONFIG_GRKERNSEC
77050+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
77051+ return 1;
77052+ return 0;
77053+#else
77054+ return 1;
77055+#endif
77056+}
77057+
77058+int gr_is_capable_nolog(const int cap)
77059+{
77060+#ifdef CONFIG_GRKERNSEC
77061+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
77062+ return 1;
77063+ return 0;
77064+#else
77065+ return 1;
77066+#endif
77067+}
77068+
77069+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
77070+{
77071+#ifdef CONFIG_GRKERNSEC
77072+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
77073+ return 1;
77074+ return 0;
77075+#else
77076+ return 1;
77077+#endif
77078+}
77079+
77080+EXPORT_SYMBOL_GPL(gr_is_capable);
77081+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
77082+EXPORT_SYMBOL_GPL(gr_task_is_capable);
77083+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
77084diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
77085new file mode 100644
77086index 0000000..06cc6ea
77087--- /dev/null
77088+++ b/grsecurity/grsec_fifo.c
77089@@ -0,0 +1,24 @@
77090+#include <linux/kernel.h>
77091+#include <linux/sched.h>
77092+#include <linux/fs.h>
77093+#include <linux/file.h>
77094+#include <linux/grinternal.h>
77095+
77096+int
77097+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
77098+ const struct dentry *dir, const int flag, const int acc_mode)
77099+{
77100+#ifdef CONFIG_GRKERNSEC_FIFO
77101+ const struct cred *cred = current_cred();
77102+
77103+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
77104+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
77105+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
77106+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
77107+ if (!inode_permission(dentry->d_inode, acc_mode))
77108+ 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));
77109+ return -EACCES;
77110+ }
77111+#endif
77112+ return 0;
77113+}
77114diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
77115new file mode 100644
77116index 0000000..8ca18bf
77117--- /dev/null
77118+++ b/grsecurity/grsec_fork.c
77119@@ -0,0 +1,23 @@
77120+#include <linux/kernel.h>
77121+#include <linux/sched.h>
77122+#include <linux/grsecurity.h>
77123+#include <linux/grinternal.h>
77124+#include <linux/errno.h>
77125+
77126+void
77127+gr_log_forkfail(const int retval)
77128+{
77129+#ifdef CONFIG_GRKERNSEC_FORKFAIL
77130+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
77131+ switch (retval) {
77132+ case -EAGAIN:
77133+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
77134+ break;
77135+ case -ENOMEM:
77136+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
77137+ break;
77138+ }
77139+ }
77140+#endif
77141+ return;
77142+}
77143diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
77144new file mode 100644
77145index 0000000..b7cb191
77146--- /dev/null
77147+++ b/grsecurity/grsec_init.c
77148@@ -0,0 +1,286 @@
77149+#include <linux/kernel.h>
77150+#include <linux/sched.h>
77151+#include <linux/mm.h>
77152+#include <linux/gracl.h>
77153+#include <linux/slab.h>
77154+#include <linux/vmalloc.h>
77155+#include <linux/percpu.h>
77156+#include <linux/module.h>
77157+
77158+int grsec_enable_ptrace_readexec;
77159+int grsec_enable_setxid;
77160+int grsec_enable_symlinkown;
77161+kgid_t grsec_symlinkown_gid;
77162+int grsec_enable_brute;
77163+int grsec_enable_link;
77164+int grsec_enable_dmesg;
77165+int grsec_enable_harden_ptrace;
77166+int grsec_enable_harden_ipc;
77167+int grsec_enable_fifo;
77168+int grsec_enable_execlog;
77169+int grsec_enable_signal;
77170+int grsec_enable_forkfail;
77171+int grsec_enable_audit_ptrace;
77172+int grsec_enable_time;
77173+int grsec_enable_group;
77174+kgid_t grsec_audit_gid;
77175+int grsec_enable_chdir;
77176+int grsec_enable_mount;
77177+int grsec_enable_rofs;
77178+int grsec_deny_new_usb;
77179+int grsec_enable_chroot_findtask;
77180+int grsec_enable_chroot_mount;
77181+int grsec_enable_chroot_shmat;
77182+int grsec_enable_chroot_fchdir;
77183+int grsec_enable_chroot_double;
77184+int grsec_enable_chroot_pivot;
77185+int grsec_enable_chroot_chdir;
77186+int grsec_enable_chroot_chmod;
77187+int grsec_enable_chroot_mknod;
77188+int grsec_enable_chroot_nice;
77189+int grsec_enable_chroot_execlog;
77190+int grsec_enable_chroot_caps;
77191+int grsec_enable_chroot_sysctl;
77192+int grsec_enable_chroot_unix;
77193+int grsec_enable_tpe;
77194+kgid_t grsec_tpe_gid;
77195+int grsec_enable_blackhole;
77196+#ifdef CONFIG_IPV6_MODULE
77197+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
77198+#endif
77199+int grsec_lastack_retries;
77200+int grsec_enable_tpe_all;
77201+int grsec_enable_tpe_invert;
77202+int grsec_enable_socket_all;
77203+kgid_t grsec_socket_all_gid;
77204+int grsec_enable_socket_client;
77205+kgid_t grsec_socket_client_gid;
77206+int grsec_enable_socket_server;
77207+kgid_t grsec_socket_server_gid;
77208+int grsec_resource_logging;
77209+int grsec_disable_privio;
77210+int grsec_enable_log_rwxmaps;
77211+int grsec_lock;
77212+
77213+DEFINE_SPINLOCK(grsec_alert_lock);
77214+unsigned long grsec_alert_wtime = 0;
77215+unsigned long grsec_alert_fyet = 0;
77216+
77217+DEFINE_SPINLOCK(grsec_audit_lock);
77218+
77219+DEFINE_RWLOCK(grsec_exec_file_lock);
77220+
77221+char *gr_shared_page[4];
77222+
77223+char *gr_alert_log_fmt;
77224+char *gr_audit_log_fmt;
77225+char *gr_alert_log_buf;
77226+char *gr_audit_log_buf;
77227+
77228+extern struct gr_arg *gr_usermode;
77229+extern unsigned char *gr_system_salt;
77230+extern unsigned char *gr_system_sum;
77231+
77232+void __init
77233+grsecurity_init(void)
77234+{
77235+ int j;
77236+ /* create the per-cpu shared pages */
77237+
77238+#ifdef CONFIG_X86
77239+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
77240+#endif
77241+
77242+ for (j = 0; j < 4; j++) {
77243+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
77244+ if (gr_shared_page[j] == NULL) {
77245+ panic("Unable to allocate grsecurity shared page");
77246+ return;
77247+ }
77248+ }
77249+
77250+ /* allocate log buffers */
77251+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
77252+ if (!gr_alert_log_fmt) {
77253+ panic("Unable to allocate grsecurity alert log format buffer");
77254+ return;
77255+ }
77256+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
77257+ if (!gr_audit_log_fmt) {
77258+ panic("Unable to allocate grsecurity audit log format buffer");
77259+ return;
77260+ }
77261+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77262+ if (!gr_alert_log_buf) {
77263+ panic("Unable to allocate grsecurity alert log buffer");
77264+ return;
77265+ }
77266+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
77267+ if (!gr_audit_log_buf) {
77268+ panic("Unable to allocate grsecurity audit log buffer");
77269+ return;
77270+ }
77271+
77272+ /* allocate memory for authentication structure */
77273+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
77274+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
77275+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
77276+
77277+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
77278+ panic("Unable to allocate grsecurity authentication structure");
77279+ return;
77280+ }
77281+
77282+#ifdef CONFIG_GRKERNSEC_IO
77283+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
77284+ grsec_disable_privio = 1;
77285+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77286+ grsec_disable_privio = 1;
77287+#else
77288+ grsec_disable_privio = 0;
77289+#endif
77290+#endif
77291+
77292+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
77293+ /* for backward compatibility, tpe_invert always defaults to on if
77294+ enabled in the kernel
77295+ */
77296+ grsec_enable_tpe_invert = 1;
77297+#endif
77298+
77299+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
77300+#ifndef CONFIG_GRKERNSEC_SYSCTL
77301+ grsec_lock = 1;
77302+#endif
77303+
77304+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
77305+ grsec_enable_log_rwxmaps = 1;
77306+#endif
77307+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
77308+ grsec_enable_group = 1;
77309+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
77310+#endif
77311+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
77312+ grsec_enable_ptrace_readexec = 1;
77313+#endif
77314+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
77315+ grsec_enable_chdir = 1;
77316+#endif
77317+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
77318+ grsec_enable_harden_ptrace = 1;
77319+#endif
77320+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77321+ grsec_enable_harden_ipc = 1;
77322+#endif
77323+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77324+ grsec_enable_mount = 1;
77325+#endif
77326+#ifdef CONFIG_GRKERNSEC_LINK
77327+ grsec_enable_link = 1;
77328+#endif
77329+#ifdef CONFIG_GRKERNSEC_BRUTE
77330+ grsec_enable_brute = 1;
77331+#endif
77332+#ifdef CONFIG_GRKERNSEC_DMESG
77333+ grsec_enable_dmesg = 1;
77334+#endif
77335+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77336+ grsec_enable_blackhole = 1;
77337+ grsec_lastack_retries = 4;
77338+#endif
77339+#ifdef CONFIG_GRKERNSEC_FIFO
77340+ grsec_enable_fifo = 1;
77341+#endif
77342+#ifdef CONFIG_GRKERNSEC_EXECLOG
77343+ grsec_enable_execlog = 1;
77344+#endif
77345+#ifdef CONFIG_GRKERNSEC_SETXID
77346+ grsec_enable_setxid = 1;
77347+#endif
77348+#ifdef CONFIG_GRKERNSEC_SIGNAL
77349+ grsec_enable_signal = 1;
77350+#endif
77351+#ifdef CONFIG_GRKERNSEC_FORKFAIL
77352+ grsec_enable_forkfail = 1;
77353+#endif
77354+#ifdef CONFIG_GRKERNSEC_TIME
77355+ grsec_enable_time = 1;
77356+#endif
77357+#ifdef CONFIG_GRKERNSEC_RESLOG
77358+ grsec_resource_logging = 1;
77359+#endif
77360+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
77361+ grsec_enable_chroot_findtask = 1;
77362+#endif
77363+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
77364+ grsec_enable_chroot_unix = 1;
77365+#endif
77366+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
77367+ grsec_enable_chroot_mount = 1;
77368+#endif
77369+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
77370+ grsec_enable_chroot_fchdir = 1;
77371+#endif
77372+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
77373+ grsec_enable_chroot_shmat = 1;
77374+#endif
77375+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
77376+ grsec_enable_audit_ptrace = 1;
77377+#endif
77378+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
77379+ grsec_enable_chroot_double = 1;
77380+#endif
77381+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
77382+ grsec_enable_chroot_pivot = 1;
77383+#endif
77384+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
77385+ grsec_enable_chroot_chdir = 1;
77386+#endif
77387+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
77388+ grsec_enable_chroot_chmod = 1;
77389+#endif
77390+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
77391+ grsec_enable_chroot_mknod = 1;
77392+#endif
77393+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
77394+ grsec_enable_chroot_nice = 1;
77395+#endif
77396+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
77397+ grsec_enable_chroot_execlog = 1;
77398+#endif
77399+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
77400+ grsec_enable_chroot_caps = 1;
77401+#endif
77402+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
77403+ grsec_enable_chroot_sysctl = 1;
77404+#endif
77405+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77406+ grsec_enable_symlinkown = 1;
77407+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
77408+#endif
77409+#ifdef CONFIG_GRKERNSEC_TPE
77410+ grsec_enable_tpe = 1;
77411+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
77412+#ifdef CONFIG_GRKERNSEC_TPE_ALL
77413+ grsec_enable_tpe_all = 1;
77414+#endif
77415+#endif
77416+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
77417+ grsec_enable_socket_all = 1;
77418+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
77419+#endif
77420+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
77421+ grsec_enable_socket_client = 1;
77422+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
77423+#endif
77424+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
77425+ grsec_enable_socket_server = 1;
77426+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
77427+#endif
77428+#endif
77429+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
77430+ grsec_deny_new_usb = 1;
77431+#endif
77432+
77433+ return;
77434+}
77435diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
77436new file mode 100644
77437index 0000000..1773300
77438--- /dev/null
77439+++ b/grsecurity/grsec_ipc.c
77440@@ -0,0 +1,48 @@
77441+#include <linux/kernel.h>
77442+#include <linux/mm.h>
77443+#include <linux/sched.h>
77444+#include <linux/file.h>
77445+#include <linux/ipc.h>
77446+#include <linux/ipc_namespace.h>
77447+#include <linux/grsecurity.h>
77448+#include <linux/grinternal.h>
77449+
77450+int
77451+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
77452+{
77453+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
77454+ int write;
77455+ int orig_granted_mode;
77456+ kuid_t euid;
77457+ kgid_t egid;
77458+
77459+ if (!grsec_enable_harden_ipc)
77460+ return 1;
77461+
77462+ euid = current_euid();
77463+ egid = current_egid();
77464+
77465+ write = requested_mode & 00002;
77466+ orig_granted_mode = ipcp->mode;
77467+
77468+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
77469+ orig_granted_mode >>= 6;
77470+ else {
77471+ /* if likely wrong permissions, lock to user */
77472+ if (orig_granted_mode & 0007)
77473+ orig_granted_mode = 0;
77474+ /* otherwise do a egid-only check */
77475+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
77476+ orig_granted_mode >>= 3;
77477+ /* otherwise, no access */
77478+ else
77479+ orig_granted_mode = 0;
77480+ }
77481+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
77482+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
77483+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
77484+ return 0;
77485+ }
77486+#endif
77487+ return 1;
77488+}
77489diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
77490new file mode 100644
77491index 0000000..5e05e20
77492--- /dev/null
77493+++ b/grsecurity/grsec_link.c
77494@@ -0,0 +1,58 @@
77495+#include <linux/kernel.h>
77496+#include <linux/sched.h>
77497+#include <linux/fs.h>
77498+#include <linux/file.h>
77499+#include <linux/grinternal.h>
77500+
77501+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
77502+{
77503+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
77504+ const struct inode *link_inode = link->dentry->d_inode;
77505+
77506+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
77507+ /* ignore root-owned links, e.g. /proc/self */
77508+ gr_is_global_nonroot(link_inode->i_uid) && target &&
77509+ !uid_eq(link_inode->i_uid, target->i_uid)) {
77510+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
77511+ return 1;
77512+ }
77513+#endif
77514+ return 0;
77515+}
77516+
77517+int
77518+gr_handle_follow_link(const struct inode *parent,
77519+ const struct inode *inode,
77520+ const struct dentry *dentry, const struct vfsmount *mnt)
77521+{
77522+#ifdef CONFIG_GRKERNSEC_LINK
77523+ const struct cred *cred = current_cred();
77524+
77525+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
77526+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
77527+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
77528+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
77529+ return -EACCES;
77530+ }
77531+#endif
77532+ return 0;
77533+}
77534+
77535+int
77536+gr_handle_hardlink(const struct dentry *dentry,
77537+ const struct vfsmount *mnt,
77538+ struct inode *inode, const int mode, const struct filename *to)
77539+{
77540+#ifdef CONFIG_GRKERNSEC_LINK
77541+ const struct cred *cred = current_cred();
77542+
77543+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
77544+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
77545+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
77546+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
77547+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
77548+ return -EPERM;
77549+ }
77550+#endif
77551+ return 0;
77552+}
77553diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
77554new file mode 100644
77555index 0000000..dbe0a6b
77556--- /dev/null
77557+++ b/grsecurity/grsec_log.c
77558@@ -0,0 +1,341 @@
77559+#include <linux/kernel.h>
77560+#include <linux/sched.h>
77561+#include <linux/file.h>
77562+#include <linux/tty.h>
77563+#include <linux/fs.h>
77564+#include <linux/mm.h>
77565+#include <linux/grinternal.h>
77566+
77567+#ifdef CONFIG_TREE_PREEMPT_RCU
77568+#define DISABLE_PREEMPT() preempt_disable()
77569+#define ENABLE_PREEMPT() preempt_enable()
77570+#else
77571+#define DISABLE_PREEMPT()
77572+#define ENABLE_PREEMPT()
77573+#endif
77574+
77575+#define BEGIN_LOCKS(x) \
77576+ DISABLE_PREEMPT(); \
77577+ rcu_read_lock(); \
77578+ read_lock(&tasklist_lock); \
77579+ read_lock(&grsec_exec_file_lock); \
77580+ if (x != GR_DO_AUDIT) \
77581+ spin_lock(&grsec_alert_lock); \
77582+ else \
77583+ spin_lock(&grsec_audit_lock)
77584+
77585+#define END_LOCKS(x) \
77586+ if (x != GR_DO_AUDIT) \
77587+ spin_unlock(&grsec_alert_lock); \
77588+ else \
77589+ spin_unlock(&grsec_audit_lock); \
77590+ read_unlock(&grsec_exec_file_lock); \
77591+ read_unlock(&tasklist_lock); \
77592+ rcu_read_unlock(); \
77593+ ENABLE_PREEMPT(); \
77594+ if (x == GR_DONT_AUDIT) \
77595+ gr_handle_alertkill(current)
77596+
77597+enum {
77598+ FLOODING,
77599+ NO_FLOODING
77600+};
77601+
77602+extern char *gr_alert_log_fmt;
77603+extern char *gr_audit_log_fmt;
77604+extern char *gr_alert_log_buf;
77605+extern char *gr_audit_log_buf;
77606+
77607+static int gr_log_start(int audit)
77608+{
77609+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
77610+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
77611+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77612+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
77613+ unsigned long curr_secs = get_seconds();
77614+
77615+ if (audit == GR_DO_AUDIT)
77616+ goto set_fmt;
77617+
77618+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
77619+ grsec_alert_wtime = curr_secs;
77620+ grsec_alert_fyet = 0;
77621+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
77622+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
77623+ grsec_alert_fyet++;
77624+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
77625+ grsec_alert_wtime = curr_secs;
77626+ grsec_alert_fyet++;
77627+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
77628+ return FLOODING;
77629+ }
77630+ else return FLOODING;
77631+
77632+set_fmt:
77633+#endif
77634+ memset(buf, 0, PAGE_SIZE);
77635+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
77636+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
77637+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77638+ } else if (current->signal->curr_ip) {
77639+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
77640+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
77641+ } else if (gr_acl_is_enabled()) {
77642+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
77643+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
77644+ } else {
77645+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
77646+ strcpy(buf, fmt);
77647+ }
77648+
77649+ return NO_FLOODING;
77650+}
77651+
77652+static void gr_log_middle(int audit, const char *msg, va_list ap)
77653+ __attribute__ ((format (printf, 2, 0)));
77654+
77655+static void gr_log_middle(int audit, const char *msg, va_list ap)
77656+{
77657+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77658+ unsigned int len = strlen(buf);
77659+
77660+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77661+
77662+ return;
77663+}
77664+
77665+static void gr_log_middle_varargs(int audit, const char *msg, ...)
77666+ __attribute__ ((format (printf, 2, 3)));
77667+
77668+static void gr_log_middle_varargs(int audit, const char *msg, ...)
77669+{
77670+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77671+ unsigned int len = strlen(buf);
77672+ va_list ap;
77673+
77674+ va_start(ap, msg);
77675+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
77676+ va_end(ap);
77677+
77678+ return;
77679+}
77680+
77681+static void gr_log_end(int audit, int append_default)
77682+{
77683+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
77684+ if (append_default) {
77685+ struct task_struct *task = current;
77686+ struct task_struct *parent = task->real_parent;
77687+ const struct cred *cred = __task_cred(task);
77688+ const struct cred *pcred = __task_cred(parent);
77689+ unsigned int len = strlen(buf);
77690+
77691+ 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));
77692+ }
77693+
77694+ printk("%s\n", buf);
77695+
77696+ return;
77697+}
77698+
77699+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
77700+{
77701+ int logtype;
77702+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
77703+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
77704+ void *voidptr = NULL;
77705+ int num1 = 0, num2 = 0;
77706+ unsigned long ulong1 = 0, ulong2 = 0;
77707+ struct dentry *dentry = NULL;
77708+ struct vfsmount *mnt = NULL;
77709+ struct file *file = NULL;
77710+ struct task_struct *task = NULL;
77711+ struct vm_area_struct *vma = NULL;
77712+ const struct cred *cred, *pcred;
77713+ va_list ap;
77714+
77715+ BEGIN_LOCKS(audit);
77716+ logtype = gr_log_start(audit);
77717+ if (logtype == FLOODING) {
77718+ END_LOCKS(audit);
77719+ return;
77720+ }
77721+ va_start(ap, argtypes);
77722+ switch (argtypes) {
77723+ case GR_TTYSNIFF:
77724+ task = va_arg(ap, struct task_struct *);
77725+ 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));
77726+ break;
77727+ case GR_SYSCTL_HIDDEN:
77728+ str1 = va_arg(ap, char *);
77729+ gr_log_middle_varargs(audit, msg, result, str1);
77730+ break;
77731+ case GR_RBAC:
77732+ dentry = va_arg(ap, struct dentry *);
77733+ mnt = va_arg(ap, struct vfsmount *);
77734+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
77735+ break;
77736+ case GR_RBAC_STR:
77737+ dentry = va_arg(ap, struct dentry *);
77738+ mnt = va_arg(ap, struct vfsmount *);
77739+ str1 = va_arg(ap, char *);
77740+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
77741+ break;
77742+ case GR_STR_RBAC:
77743+ str1 = va_arg(ap, char *);
77744+ dentry = va_arg(ap, struct dentry *);
77745+ mnt = va_arg(ap, struct vfsmount *);
77746+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
77747+ break;
77748+ case GR_RBAC_MODE2:
77749+ dentry = va_arg(ap, struct dentry *);
77750+ mnt = va_arg(ap, struct vfsmount *);
77751+ str1 = va_arg(ap, char *);
77752+ str2 = va_arg(ap, char *);
77753+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
77754+ break;
77755+ case GR_RBAC_MODE3:
77756+ dentry = va_arg(ap, struct dentry *);
77757+ mnt = va_arg(ap, struct vfsmount *);
77758+ str1 = va_arg(ap, char *);
77759+ str2 = va_arg(ap, char *);
77760+ str3 = va_arg(ap, char *);
77761+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
77762+ break;
77763+ case GR_FILENAME:
77764+ dentry = va_arg(ap, struct dentry *);
77765+ mnt = va_arg(ap, struct vfsmount *);
77766+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
77767+ break;
77768+ case GR_STR_FILENAME:
77769+ str1 = va_arg(ap, char *);
77770+ dentry = va_arg(ap, struct dentry *);
77771+ mnt = va_arg(ap, struct vfsmount *);
77772+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
77773+ break;
77774+ case GR_FILENAME_STR:
77775+ dentry = va_arg(ap, struct dentry *);
77776+ mnt = va_arg(ap, struct vfsmount *);
77777+ str1 = va_arg(ap, char *);
77778+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
77779+ break;
77780+ case GR_FILENAME_TWO_INT:
77781+ dentry = va_arg(ap, struct dentry *);
77782+ mnt = va_arg(ap, struct vfsmount *);
77783+ num1 = va_arg(ap, int);
77784+ num2 = va_arg(ap, int);
77785+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
77786+ break;
77787+ case GR_FILENAME_TWO_INT_STR:
77788+ dentry = va_arg(ap, struct dentry *);
77789+ mnt = va_arg(ap, struct vfsmount *);
77790+ num1 = va_arg(ap, int);
77791+ num2 = va_arg(ap, int);
77792+ str1 = va_arg(ap, char *);
77793+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
77794+ break;
77795+ case GR_TEXTREL:
77796+ file = va_arg(ap, struct file *);
77797+ ulong1 = va_arg(ap, unsigned long);
77798+ ulong2 = va_arg(ap, unsigned long);
77799+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
77800+ break;
77801+ case GR_PTRACE:
77802+ task = va_arg(ap, struct task_struct *);
77803+ 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));
77804+ break;
77805+ case GR_RESOURCE:
77806+ task = va_arg(ap, struct task_struct *);
77807+ cred = __task_cred(task);
77808+ pcred = __task_cred(task->real_parent);
77809+ ulong1 = va_arg(ap, unsigned long);
77810+ str1 = va_arg(ap, char *);
77811+ ulong2 = va_arg(ap, unsigned long);
77812+ 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));
77813+ break;
77814+ case GR_CAP:
77815+ task = va_arg(ap, struct task_struct *);
77816+ cred = __task_cred(task);
77817+ pcred = __task_cred(task->real_parent);
77818+ str1 = va_arg(ap, char *);
77819+ 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));
77820+ break;
77821+ case GR_SIG:
77822+ str1 = va_arg(ap, char *);
77823+ voidptr = va_arg(ap, void *);
77824+ gr_log_middle_varargs(audit, msg, str1, voidptr);
77825+ break;
77826+ case GR_SIG2:
77827+ task = va_arg(ap, struct task_struct *);
77828+ cred = __task_cred(task);
77829+ pcred = __task_cred(task->real_parent);
77830+ num1 = va_arg(ap, int);
77831+ 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));
77832+ break;
77833+ case GR_CRASH1:
77834+ task = va_arg(ap, struct task_struct *);
77835+ cred = __task_cred(task);
77836+ pcred = __task_cred(task->real_parent);
77837+ ulong1 = va_arg(ap, unsigned long);
77838+ 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);
77839+ break;
77840+ case GR_CRASH2:
77841+ task = va_arg(ap, struct task_struct *);
77842+ cred = __task_cred(task);
77843+ pcred = __task_cred(task->real_parent);
77844+ ulong1 = va_arg(ap, unsigned long);
77845+ 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);
77846+ break;
77847+ case GR_RWXMAP:
77848+ file = va_arg(ap, struct file *);
77849+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
77850+ break;
77851+ case GR_RWXMAPVMA:
77852+ vma = va_arg(ap, struct vm_area_struct *);
77853+ if (vma->vm_file)
77854+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
77855+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
77856+ str1 = "<stack>";
77857+ else if (vma->vm_start <= current->mm->brk &&
77858+ vma->vm_end >= current->mm->start_brk)
77859+ str1 = "<heap>";
77860+ else
77861+ str1 = "<anonymous mapping>";
77862+ gr_log_middle_varargs(audit, msg, str1);
77863+ break;
77864+ case GR_PSACCT:
77865+ {
77866+ unsigned int wday, cday;
77867+ __u8 whr, chr;
77868+ __u8 wmin, cmin;
77869+ __u8 wsec, csec;
77870+ char cur_tty[64] = { 0 };
77871+ char parent_tty[64] = { 0 };
77872+
77873+ task = va_arg(ap, struct task_struct *);
77874+ wday = va_arg(ap, unsigned int);
77875+ cday = va_arg(ap, unsigned int);
77876+ whr = va_arg(ap, int);
77877+ chr = va_arg(ap, int);
77878+ wmin = va_arg(ap, int);
77879+ cmin = va_arg(ap, int);
77880+ wsec = va_arg(ap, int);
77881+ csec = va_arg(ap, int);
77882+ ulong1 = va_arg(ap, unsigned long);
77883+ cred = __task_cred(task);
77884+ pcred = __task_cred(task->real_parent);
77885+
77886+ 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));
77887+ }
77888+ break;
77889+ default:
77890+ gr_log_middle(audit, msg, ap);
77891+ }
77892+ va_end(ap);
77893+ // these don't need DEFAULTSECARGS printed on the end
77894+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
77895+ gr_log_end(audit, 0);
77896+ else
77897+ gr_log_end(audit, 1);
77898+ END_LOCKS(audit);
77899+}
77900diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
77901new file mode 100644
77902index 0000000..0e39d8c
77903--- /dev/null
77904+++ b/grsecurity/grsec_mem.c
77905@@ -0,0 +1,48 @@
77906+#include <linux/kernel.h>
77907+#include <linux/sched.h>
77908+#include <linux/mm.h>
77909+#include <linux/mman.h>
77910+#include <linux/module.h>
77911+#include <linux/grinternal.h>
77912+
77913+void gr_handle_msr_write(void)
77914+{
77915+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
77916+ return;
77917+}
77918+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
77919+
77920+void
77921+gr_handle_ioperm(void)
77922+{
77923+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
77924+ return;
77925+}
77926+
77927+void
77928+gr_handle_iopl(void)
77929+{
77930+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
77931+ return;
77932+}
77933+
77934+void
77935+gr_handle_mem_readwrite(u64 from, u64 to)
77936+{
77937+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
77938+ return;
77939+}
77940+
77941+void
77942+gr_handle_vm86(void)
77943+{
77944+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
77945+ return;
77946+}
77947+
77948+void
77949+gr_log_badprocpid(const char *entry)
77950+{
77951+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
77952+ return;
77953+}
77954diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
77955new file mode 100644
77956index 0000000..cd9e124
77957--- /dev/null
77958+++ b/grsecurity/grsec_mount.c
77959@@ -0,0 +1,65 @@
77960+#include <linux/kernel.h>
77961+#include <linux/sched.h>
77962+#include <linux/mount.h>
77963+#include <linux/major.h>
77964+#include <linux/grsecurity.h>
77965+#include <linux/grinternal.h>
77966+
77967+void
77968+gr_log_remount(const char *devname, const int retval)
77969+{
77970+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77971+ if (grsec_enable_mount && (retval >= 0))
77972+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
77973+#endif
77974+ return;
77975+}
77976+
77977+void
77978+gr_log_unmount(const char *devname, const int retval)
77979+{
77980+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77981+ if (grsec_enable_mount && (retval >= 0))
77982+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
77983+#endif
77984+ return;
77985+}
77986+
77987+void
77988+gr_log_mount(const char *from, const char *to, const int retval)
77989+{
77990+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
77991+ if (grsec_enable_mount && (retval >= 0))
77992+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
77993+#endif
77994+ return;
77995+}
77996+
77997+int
77998+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
77999+{
78000+#ifdef CONFIG_GRKERNSEC_ROFS
78001+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
78002+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
78003+ return -EPERM;
78004+ } else
78005+ return 0;
78006+#endif
78007+ return 0;
78008+}
78009+
78010+int
78011+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
78012+{
78013+#ifdef CONFIG_GRKERNSEC_ROFS
78014+ struct inode *inode = dentry->d_inode;
78015+
78016+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
78017+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
78018+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
78019+ return -EPERM;
78020+ } else
78021+ return 0;
78022+#endif
78023+ return 0;
78024+}
78025diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
78026new file mode 100644
78027index 0000000..6ee9d50
78028--- /dev/null
78029+++ b/grsecurity/grsec_pax.c
78030@@ -0,0 +1,45 @@
78031+#include <linux/kernel.h>
78032+#include <linux/sched.h>
78033+#include <linux/mm.h>
78034+#include <linux/file.h>
78035+#include <linux/grinternal.h>
78036+#include <linux/grsecurity.h>
78037+
78038+void
78039+gr_log_textrel(struct vm_area_struct * vma)
78040+{
78041+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78042+ if (grsec_enable_log_rwxmaps)
78043+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
78044+#endif
78045+ return;
78046+}
78047+
78048+void gr_log_ptgnustack(struct file *file)
78049+{
78050+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78051+ if (grsec_enable_log_rwxmaps)
78052+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
78053+#endif
78054+ return;
78055+}
78056+
78057+void
78058+gr_log_rwxmmap(struct file *file)
78059+{
78060+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78061+ if (grsec_enable_log_rwxmaps)
78062+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
78063+#endif
78064+ return;
78065+}
78066+
78067+void
78068+gr_log_rwxmprotect(struct vm_area_struct *vma)
78069+{
78070+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78071+ if (grsec_enable_log_rwxmaps)
78072+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
78073+#endif
78074+ return;
78075+}
78076diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
78077new file mode 100644
78078index 0000000..2005a3a
78079--- /dev/null
78080+++ b/grsecurity/grsec_proc.c
78081@@ -0,0 +1,20 @@
78082+#include <linux/kernel.h>
78083+#include <linux/sched.h>
78084+#include <linux/grsecurity.h>
78085+#include <linux/grinternal.h>
78086+
78087+int gr_proc_is_restricted(void)
78088+{
78089+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78090+ const struct cred *cred = current_cred();
78091+#endif
78092+
78093+#ifdef CONFIG_GRKERNSEC_PROC_USER
78094+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
78095+ return -EACCES;
78096+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78097+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
78098+ return -EACCES;
78099+#endif
78100+ return 0;
78101+}
78102diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
78103new file mode 100644
78104index 0000000..f7f29aa
78105--- /dev/null
78106+++ b/grsecurity/grsec_ptrace.c
78107@@ -0,0 +1,30 @@
78108+#include <linux/kernel.h>
78109+#include <linux/sched.h>
78110+#include <linux/grinternal.h>
78111+#include <linux/security.h>
78112+
78113+void
78114+gr_audit_ptrace(struct task_struct *task)
78115+{
78116+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
78117+ if (grsec_enable_audit_ptrace)
78118+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
78119+#endif
78120+ return;
78121+}
78122+
78123+int
78124+gr_ptrace_readexec(struct file *file, int unsafe_flags)
78125+{
78126+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78127+ const struct dentry *dentry = file->f_path.dentry;
78128+ const struct vfsmount *mnt = file->f_path.mnt;
78129+
78130+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
78131+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
78132+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
78133+ return -EACCES;
78134+ }
78135+#endif
78136+ return 0;
78137+}
78138diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
78139new file mode 100644
78140index 0000000..3860c7e
78141--- /dev/null
78142+++ b/grsecurity/grsec_sig.c
78143@@ -0,0 +1,236 @@
78144+#include <linux/kernel.h>
78145+#include <linux/sched.h>
78146+#include <linux/fs.h>
78147+#include <linux/delay.h>
78148+#include <linux/grsecurity.h>
78149+#include <linux/grinternal.h>
78150+#include <linux/hardirq.h>
78151+
78152+char *signames[] = {
78153+ [SIGSEGV] = "Segmentation fault",
78154+ [SIGILL] = "Illegal instruction",
78155+ [SIGABRT] = "Abort",
78156+ [SIGBUS] = "Invalid alignment/Bus error"
78157+};
78158+
78159+void
78160+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
78161+{
78162+#ifdef CONFIG_GRKERNSEC_SIGNAL
78163+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
78164+ (sig == SIGABRT) || (sig == SIGBUS))) {
78165+ if (task_pid_nr(t) == task_pid_nr(current)) {
78166+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
78167+ } else {
78168+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
78169+ }
78170+ }
78171+#endif
78172+ return;
78173+}
78174+
78175+int
78176+gr_handle_signal(const struct task_struct *p, const int sig)
78177+{
78178+#ifdef CONFIG_GRKERNSEC
78179+ /* ignore the 0 signal for protected task checks */
78180+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
78181+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
78182+ return -EPERM;
78183+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
78184+ return -EPERM;
78185+ }
78186+#endif
78187+ return 0;
78188+}
78189+
78190+#ifdef CONFIG_GRKERNSEC
78191+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
78192+
78193+int gr_fake_force_sig(int sig, struct task_struct *t)
78194+{
78195+ unsigned long int flags;
78196+ int ret, blocked, ignored;
78197+ struct k_sigaction *action;
78198+
78199+ spin_lock_irqsave(&t->sighand->siglock, flags);
78200+ action = &t->sighand->action[sig-1];
78201+ ignored = action->sa.sa_handler == SIG_IGN;
78202+ blocked = sigismember(&t->blocked, sig);
78203+ if (blocked || ignored) {
78204+ action->sa.sa_handler = SIG_DFL;
78205+ if (blocked) {
78206+ sigdelset(&t->blocked, sig);
78207+ recalc_sigpending_and_wake(t);
78208+ }
78209+ }
78210+ if (action->sa.sa_handler == SIG_DFL)
78211+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
78212+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
78213+
78214+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
78215+
78216+ return ret;
78217+}
78218+#endif
78219+
78220+#define GR_USER_BAN_TIME (15 * 60)
78221+#define GR_DAEMON_BRUTE_TIME (30 * 60)
78222+
78223+void gr_handle_brute_attach(int dumpable)
78224+{
78225+#ifdef CONFIG_GRKERNSEC_BRUTE
78226+ struct task_struct *p = current;
78227+ kuid_t uid = GLOBAL_ROOT_UID;
78228+ int daemon = 0;
78229+
78230+ if (!grsec_enable_brute)
78231+ return;
78232+
78233+ rcu_read_lock();
78234+ read_lock(&tasklist_lock);
78235+ read_lock(&grsec_exec_file_lock);
78236+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
78237+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
78238+ p->real_parent->brute = 1;
78239+ daemon = 1;
78240+ } else {
78241+ const struct cred *cred = __task_cred(p), *cred2;
78242+ struct task_struct *tsk, *tsk2;
78243+
78244+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
78245+ struct user_struct *user;
78246+
78247+ uid = cred->uid;
78248+
78249+ /* this is put upon execution past expiration */
78250+ user = find_user(uid);
78251+ if (user == NULL)
78252+ goto unlock;
78253+ user->suid_banned = 1;
78254+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
78255+ if (user->suid_ban_expires == ~0UL)
78256+ user->suid_ban_expires--;
78257+
78258+ /* only kill other threads of the same binary, from the same user */
78259+ do_each_thread(tsk2, tsk) {
78260+ cred2 = __task_cred(tsk);
78261+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
78262+ gr_fake_force_sig(SIGKILL, tsk);
78263+ } while_each_thread(tsk2, tsk);
78264+ }
78265+ }
78266+unlock:
78267+ read_unlock(&grsec_exec_file_lock);
78268+ read_unlock(&tasklist_lock);
78269+ rcu_read_unlock();
78270+
78271+ if (gr_is_global_nonroot(uid))
78272+ 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);
78273+ else if (daemon)
78274+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
78275+
78276+#endif
78277+ return;
78278+}
78279+
78280+void gr_handle_brute_check(void)
78281+{
78282+#ifdef CONFIG_GRKERNSEC_BRUTE
78283+ struct task_struct *p = current;
78284+
78285+ if (unlikely(p->brute)) {
78286+ if (!grsec_enable_brute)
78287+ p->brute = 0;
78288+ else if (time_before(get_seconds(), p->brute_expires))
78289+ msleep(30 * 1000);
78290+ }
78291+#endif
78292+ return;
78293+}
78294+
78295+void gr_handle_kernel_exploit(void)
78296+{
78297+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78298+ const struct cred *cred;
78299+ struct task_struct *tsk, *tsk2;
78300+ struct user_struct *user;
78301+ kuid_t uid;
78302+
78303+ if (in_irq() || in_serving_softirq() || in_nmi())
78304+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
78305+
78306+ uid = current_uid();
78307+
78308+ if (gr_is_global_root(uid))
78309+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
78310+ else {
78311+ /* kill all the processes of this user, hold a reference
78312+ to their creds struct, and prevent them from creating
78313+ another process until system reset
78314+ */
78315+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
78316+ GR_GLOBAL_UID(uid));
78317+ /* we intentionally leak this ref */
78318+ user = get_uid(current->cred->user);
78319+ if (user)
78320+ user->kernel_banned = 1;
78321+
78322+ /* kill all processes of this user */
78323+ read_lock(&tasklist_lock);
78324+ do_each_thread(tsk2, tsk) {
78325+ cred = __task_cred(tsk);
78326+ if (uid_eq(cred->uid, uid))
78327+ gr_fake_force_sig(SIGKILL, tsk);
78328+ } while_each_thread(tsk2, tsk);
78329+ read_unlock(&tasklist_lock);
78330+ }
78331+#endif
78332+}
78333+
78334+#ifdef CONFIG_GRKERNSEC_BRUTE
78335+static bool suid_ban_expired(struct user_struct *user)
78336+{
78337+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
78338+ user->suid_banned = 0;
78339+ user->suid_ban_expires = 0;
78340+ free_uid(user);
78341+ return true;
78342+ }
78343+
78344+ return false;
78345+}
78346+#endif
78347+
78348+int gr_process_kernel_exec_ban(void)
78349+{
78350+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78351+ if (unlikely(current->cred->user->kernel_banned))
78352+ return -EPERM;
78353+#endif
78354+ return 0;
78355+}
78356+
78357+int gr_process_kernel_setuid_ban(struct user_struct *user)
78358+{
78359+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
78360+ if (unlikely(user->kernel_banned))
78361+ gr_fake_force_sig(SIGKILL, current);
78362+#endif
78363+ return 0;
78364+}
78365+
78366+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
78367+{
78368+#ifdef CONFIG_GRKERNSEC_BRUTE
78369+ struct user_struct *user = current->cred->user;
78370+ if (unlikely(user->suid_banned)) {
78371+ if (suid_ban_expired(user))
78372+ return 0;
78373+ /* disallow execution of suid binaries only */
78374+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
78375+ return -EPERM;
78376+ }
78377+#endif
78378+ return 0;
78379+}
78380diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
78381new file mode 100644
78382index 0000000..e3650b6
78383--- /dev/null
78384+++ b/grsecurity/grsec_sock.c
78385@@ -0,0 +1,244 @@
78386+#include <linux/kernel.h>
78387+#include <linux/module.h>
78388+#include <linux/sched.h>
78389+#include <linux/file.h>
78390+#include <linux/net.h>
78391+#include <linux/in.h>
78392+#include <linux/ip.h>
78393+#include <net/sock.h>
78394+#include <net/inet_sock.h>
78395+#include <linux/grsecurity.h>
78396+#include <linux/grinternal.h>
78397+#include <linux/gracl.h>
78398+
78399+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
78400+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
78401+
78402+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
78403+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
78404+
78405+#ifdef CONFIG_UNIX_MODULE
78406+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
78407+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
78408+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
78409+EXPORT_SYMBOL_GPL(gr_handle_create);
78410+#endif
78411+
78412+#ifdef CONFIG_GRKERNSEC
78413+#define gr_conn_table_size 32749
78414+struct conn_table_entry {
78415+ struct conn_table_entry *next;
78416+ struct signal_struct *sig;
78417+};
78418+
78419+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
78420+DEFINE_SPINLOCK(gr_conn_table_lock);
78421+
78422+extern const char * gr_socktype_to_name(unsigned char type);
78423+extern const char * gr_proto_to_name(unsigned char proto);
78424+extern const char * gr_sockfamily_to_name(unsigned char family);
78425+
78426+static __inline__ int
78427+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
78428+{
78429+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
78430+}
78431+
78432+static __inline__ int
78433+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
78434+ __u16 sport, __u16 dport)
78435+{
78436+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
78437+ sig->gr_sport == sport && sig->gr_dport == dport))
78438+ return 1;
78439+ else
78440+ return 0;
78441+}
78442+
78443+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
78444+{
78445+ struct conn_table_entry **match;
78446+ unsigned int index;
78447+
78448+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78449+ sig->gr_sport, sig->gr_dport,
78450+ gr_conn_table_size);
78451+
78452+ newent->sig = sig;
78453+
78454+ match = &gr_conn_table[index];
78455+ newent->next = *match;
78456+ *match = newent;
78457+
78458+ return;
78459+}
78460+
78461+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
78462+{
78463+ struct conn_table_entry *match, *last = NULL;
78464+ unsigned int index;
78465+
78466+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
78467+ sig->gr_sport, sig->gr_dport,
78468+ gr_conn_table_size);
78469+
78470+ match = gr_conn_table[index];
78471+ while (match && !conn_match(match->sig,
78472+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
78473+ sig->gr_dport)) {
78474+ last = match;
78475+ match = match->next;
78476+ }
78477+
78478+ if (match) {
78479+ if (last)
78480+ last->next = match->next;
78481+ else
78482+ gr_conn_table[index] = NULL;
78483+ kfree(match);
78484+ }
78485+
78486+ return;
78487+}
78488+
78489+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
78490+ __u16 sport, __u16 dport)
78491+{
78492+ struct conn_table_entry *match;
78493+ unsigned int index;
78494+
78495+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
78496+
78497+ match = gr_conn_table[index];
78498+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
78499+ match = match->next;
78500+
78501+ if (match)
78502+ return match->sig;
78503+ else
78504+ return NULL;
78505+}
78506+
78507+#endif
78508+
78509+void gr_update_task_in_ip_table(const struct inet_sock *inet)
78510+{
78511+#ifdef CONFIG_GRKERNSEC
78512+ struct signal_struct *sig = current->signal;
78513+ struct conn_table_entry *newent;
78514+
78515+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
78516+ if (newent == NULL)
78517+ return;
78518+ /* no bh lock needed since we are called with bh disabled */
78519+ spin_lock(&gr_conn_table_lock);
78520+ gr_del_task_from_ip_table_nolock(sig);
78521+ sig->gr_saddr = inet->inet_rcv_saddr;
78522+ sig->gr_daddr = inet->inet_daddr;
78523+ sig->gr_sport = inet->inet_sport;
78524+ sig->gr_dport = inet->inet_dport;
78525+ gr_add_to_task_ip_table_nolock(sig, newent);
78526+ spin_unlock(&gr_conn_table_lock);
78527+#endif
78528+ return;
78529+}
78530+
78531+void gr_del_task_from_ip_table(struct task_struct *task)
78532+{
78533+#ifdef CONFIG_GRKERNSEC
78534+ spin_lock_bh(&gr_conn_table_lock);
78535+ gr_del_task_from_ip_table_nolock(task->signal);
78536+ spin_unlock_bh(&gr_conn_table_lock);
78537+#endif
78538+ return;
78539+}
78540+
78541+void
78542+gr_attach_curr_ip(const struct sock *sk)
78543+{
78544+#ifdef CONFIG_GRKERNSEC
78545+ struct signal_struct *p, *set;
78546+ const struct inet_sock *inet = inet_sk(sk);
78547+
78548+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
78549+ return;
78550+
78551+ set = current->signal;
78552+
78553+ spin_lock_bh(&gr_conn_table_lock);
78554+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
78555+ inet->inet_dport, inet->inet_sport);
78556+ if (unlikely(p != NULL)) {
78557+ set->curr_ip = p->curr_ip;
78558+ set->used_accept = 1;
78559+ gr_del_task_from_ip_table_nolock(p);
78560+ spin_unlock_bh(&gr_conn_table_lock);
78561+ return;
78562+ }
78563+ spin_unlock_bh(&gr_conn_table_lock);
78564+
78565+ set->curr_ip = inet->inet_daddr;
78566+ set->used_accept = 1;
78567+#endif
78568+ return;
78569+}
78570+
78571+int
78572+gr_handle_sock_all(const int family, const int type, const int protocol)
78573+{
78574+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78575+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
78576+ (family != AF_UNIX)) {
78577+ if (family == AF_INET)
78578+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
78579+ else
78580+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
78581+ return -EACCES;
78582+ }
78583+#endif
78584+ return 0;
78585+}
78586+
78587+int
78588+gr_handle_sock_server(const struct sockaddr *sck)
78589+{
78590+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78591+ if (grsec_enable_socket_server &&
78592+ in_group_p(grsec_socket_server_gid) &&
78593+ sck && (sck->sa_family != AF_UNIX) &&
78594+ (sck->sa_family != AF_LOCAL)) {
78595+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78596+ return -EACCES;
78597+ }
78598+#endif
78599+ return 0;
78600+}
78601+
78602+int
78603+gr_handle_sock_server_other(const struct sock *sck)
78604+{
78605+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78606+ if (grsec_enable_socket_server &&
78607+ in_group_p(grsec_socket_server_gid) &&
78608+ sck && (sck->sk_family != AF_UNIX) &&
78609+ (sck->sk_family != AF_LOCAL)) {
78610+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
78611+ return -EACCES;
78612+ }
78613+#endif
78614+ return 0;
78615+}
78616+
78617+int
78618+gr_handle_sock_client(const struct sockaddr *sck)
78619+{
78620+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78621+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
78622+ sck && (sck->sa_family != AF_UNIX) &&
78623+ (sck->sa_family != AF_LOCAL)) {
78624+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
78625+ return -EACCES;
78626+ }
78627+#endif
78628+ return 0;
78629+}
78630diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
78631new file mode 100644
78632index 0000000..8159888
78633--- /dev/null
78634+++ b/grsecurity/grsec_sysctl.c
78635@@ -0,0 +1,479 @@
78636+#include <linux/kernel.h>
78637+#include <linux/sched.h>
78638+#include <linux/sysctl.h>
78639+#include <linux/grsecurity.h>
78640+#include <linux/grinternal.h>
78641+
78642+int
78643+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
78644+{
78645+#ifdef CONFIG_GRKERNSEC_SYSCTL
78646+ if (dirname == NULL || name == NULL)
78647+ return 0;
78648+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
78649+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
78650+ return -EACCES;
78651+ }
78652+#endif
78653+ return 0;
78654+}
78655+
78656+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
78657+static int __maybe_unused __read_only one = 1;
78658+#endif
78659+
78660+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
78661+ defined(CONFIG_GRKERNSEC_DENYUSB)
78662+struct ctl_table grsecurity_table[] = {
78663+#ifdef CONFIG_GRKERNSEC_SYSCTL
78664+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
78665+#ifdef CONFIG_GRKERNSEC_IO
78666+ {
78667+ .procname = "disable_priv_io",
78668+ .data = &grsec_disable_privio,
78669+ .maxlen = sizeof(int),
78670+ .mode = 0600,
78671+ .proc_handler = &proc_dointvec,
78672+ },
78673+#endif
78674+#endif
78675+#ifdef CONFIG_GRKERNSEC_LINK
78676+ {
78677+ .procname = "linking_restrictions",
78678+ .data = &grsec_enable_link,
78679+ .maxlen = sizeof(int),
78680+ .mode = 0600,
78681+ .proc_handler = &proc_dointvec,
78682+ },
78683+#endif
78684+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
78685+ {
78686+ .procname = "enforce_symlinksifowner",
78687+ .data = &grsec_enable_symlinkown,
78688+ .maxlen = sizeof(int),
78689+ .mode = 0600,
78690+ .proc_handler = &proc_dointvec,
78691+ },
78692+ {
78693+ .procname = "symlinkown_gid",
78694+ .data = &grsec_symlinkown_gid,
78695+ .maxlen = sizeof(int),
78696+ .mode = 0600,
78697+ .proc_handler = &proc_dointvec,
78698+ },
78699+#endif
78700+#ifdef CONFIG_GRKERNSEC_BRUTE
78701+ {
78702+ .procname = "deter_bruteforce",
78703+ .data = &grsec_enable_brute,
78704+ .maxlen = sizeof(int),
78705+ .mode = 0600,
78706+ .proc_handler = &proc_dointvec,
78707+ },
78708+#endif
78709+#ifdef CONFIG_GRKERNSEC_FIFO
78710+ {
78711+ .procname = "fifo_restrictions",
78712+ .data = &grsec_enable_fifo,
78713+ .maxlen = sizeof(int),
78714+ .mode = 0600,
78715+ .proc_handler = &proc_dointvec,
78716+ },
78717+#endif
78718+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
78719+ {
78720+ .procname = "ptrace_readexec",
78721+ .data = &grsec_enable_ptrace_readexec,
78722+ .maxlen = sizeof(int),
78723+ .mode = 0600,
78724+ .proc_handler = &proc_dointvec,
78725+ },
78726+#endif
78727+#ifdef CONFIG_GRKERNSEC_SETXID
78728+ {
78729+ .procname = "consistent_setxid",
78730+ .data = &grsec_enable_setxid,
78731+ .maxlen = sizeof(int),
78732+ .mode = 0600,
78733+ .proc_handler = &proc_dointvec,
78734+ },
78735+#endif
78736+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
78737+ {
78738+ .procname = "ip_blackhole",
78739+ .data = &grsec_enable_blackhole,
78740+ .maxlen = sizeof(int),
78741+ .mode = 0600,
78742+ .proc_handler = &proc_dointvec,
78743+ },
78744+ {
78745+ .procname = "lastack_retries",
78746+ .data = &grsec_lastack_retries,
78747+ .maxlen = sizeof(int),
78748+ .mode = 0600,
78749+ .proc_handler = &proc_dointvec,
78750+ },
78751+#endif
78752+#ifdef CONFIG_GRKERNSEC_EXECLOG
78753+ {
78754+ .procname = "exec_logging",
78755+ .data = &grsec_enable_execlog,
78756+ .maxlen = sizeof(int),
78757+ .mode = 0600,
78758+ .proc_handler = &proc_dointvec,
78759+ },
78760+#endif
78761+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
78762+ {
78763+ .procname = "rwxmap_logging",
78764+ .data = &grsec_enable_log_rwxmaps,
78765+ .maxlen = sizeof(int),
78766+ .mode = 0600,
78767+ .proc_handler = &proc_dointvec,
78768+ },
78769+#endif
78770+#ifdef CONFIG_GRKERNSEC_SIGNAL
78771+ {
78772+ .procname = "signal_logging",
78773+ .data = &grsec_enable_signal,
78774+ .maxlen = sizeof(int),
78775+ .mode = 0600,
78776+ .proc_handler = &proc_dointvec,
78777+ },
78778+#endif
78779+#ifdef CONFIG_GRKERNSEC_FORKFAIL
78780+ {
78781+ .procname = "forkfail_logging",
78782+ .data = &grsec_enable_forkfail,
78783+ .maxlen = sizeof(int),
78784+ .mode = 0600,
78785+ .proc_handler = &proc_dointvec,
78786+ },
78787+#endif
78788+#ifdef CONFIG_GRKERNSEC_TIME
78789+ {
78790+ .procname = "timechange_logging",
78791+ .data = &grsec_enable_time,
78792+ .maxlen = sizeof(int),
78793+ .mode = 0600,
78794+ .proc_handler = &proc_dointvec,
78795+ },
78796+#endif
78797+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
78798+ {
78799+ .procname = "chroot_deny_shmat",
78800+ .data = &grsec_enable_chroot_shmat,
78801+ .maxlen = sizeof(int),
78802+ .mode = 0600,
78803+ .proc_handler = &proc_dointvec,
78804+ },
78805+#endif
78806+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
78807+ {
78808+ .procname = "chroot_deny_unix",
78809+ .data = &grsec_enable_chroot_unix,
78810+ .maxlen = sizeof(int),
78811+ .mode = 0600,
78812+ .proc_handler = &proc_dointvec,
78813+ },
78814+#endif
78815+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
78816+ {
78817+ .procname = "chroot_deny_mount",
78818+ .data = &grsec_enable_chroot_mount,
78819+ .maxlen = sizeof(int),
78820+ .mode = 0600,
78821+ .proc_handler = &proc_dointvec,
78822+ },
78823+#endif
78824+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
78825+ {
78826+ .procname = "chroot_deny_fchdir",
78827+ .data = &grsec_enable_chroot_fchdir,
78828+ .maxlen = sizeof(int),
78829+ .mode = 0600,
78830+ .proc_handler = &proc_dointvec,
78831+ },
78832+#endif
78833+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
78834+ {
78835+ .procname = "chroot_deny_chroot",
78836+ .data = &grsec_enable_chroot_double,
78837+ .maxlen = sizeof(int),
78838+ .mode = 0600,
78839+ .proc_handler = &proc_dointvec,
78840+ },
78841+#endif
78842+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
78843+ {
78844+ .procname = "chroot_deny_pivot",
78845+ .data = &grsec_enable_chroot_pivot,
78846+ .maxlen = sizeof(int),
78847+ .mode = 0600,
78848+ .proc_handler = &proc_dointvec,
78849+ },
78850+#endif
78851+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
78852+ {
78853+ .procname = "chroot_enforce_chdir",
78854+ .data = &grsec_enable_chroot_chdir,
78855+ .maxlen = sizeof(int),
78856+ .mode = 0600,
78857+ .proc_handler = &proc_dointvec,
78858+ },
78859+#endif
78860+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
78861+ {
78862+ .procname = "chroot_deny_chmod",
78863+ .data = &grsec_enable_chroot_chmod,
78864+ .maxlen = sizeof(int),
78865+ .mode = 0600,
78866+ .proc_handler = &proc_dointvec,
78867+ },
78868+#endif
78869+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
78870+ {
78871+ .procname = "chroot_deny_mknod",
78872+ .data = &grsec_enable_chroot_mknod,
78873+ .maxlen = sizeof(int),
78874+ .mode = 0600,
78875+ .proc_handler = &proc_dointvec,
78876+ },
78877+#endif
78878+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
78879+ {
78880+ .procname = "chroot_restrict_nice",
78881+ .data = &grsec_enable_chroot_nice,
78882+ .maxlen = sizeof(int),
78883+ .mode = 0600,
78884+ .proc_handler = &proc_dointvec,
78885+ },
78886+#endif
78887+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
78888+ {
78889+ .procname = "chroot_execlog",
78890+ .data = &grsec_enable_chroot_execlog,
78891+ .maxlen = sizeof(int),
78892+ .mode = 0600,
78893+ .proc_handler = &proc_dointvec,
78894+ },
78895+#endif
78896+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
78897+ {
78898+ .procname = "chroot_caps",
78899+ .data = &grsec_enable_chroot_caps,
78900+ .maxlen = sizeof(int),
78901+ .mode = 0600,
78902+ .proc_handler = &proc_dointvec,
78903+ },
78904+#endif
78905+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
78906+ {
78907+ .procname = "chroot_deny_sysctl",
78908+ .data = &grsec_enable_chroot_sysctl,
78909+ .maxlen = sizeof(int),
78910+ .mode = 0600,
78911+ .proc_handler = &proc_dointvec,
78912+ },
78913+#endif
78914+#ifdef CONFIG_GRKERNSEC_TPE
78915+ {
78916+ .procname = "tpe",
78917+ .data = &grsec_enable_tpe,
78918+ .maxlen = sizeof(int),
78919+ .mode = 0600,
78920+ .proc_handler = &proc_dointvec,
78921+ },
78922+ {
78923+ .procname = "tpe_gid",
78924+ .data = &grsec_tpe_gid,
78925+ .maxlen = sizeof(int),
78926+ .mode = 0600,
78927+ .proc_handler = &proc_dointvec,
78928+ },
78929+#endif
78930+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
78931+ {
78932+ .procname = "tpe_invert",
78933+ .data = &grsec_enable_tpe_invert,
78934+ .maxlen = sizeof(int),
78935+ .mode = 0600,
78936+ .proc_handler = &proc_dointvec,
78937+ },
78938+#endif
78939+#ifdef CONFIG_GRKERNSEC_TPE_ALL
78940+ {
78941+ .procname = "tpe_restrict_all",
78942+ .data = &grsec_enable_tpe_all,
78943+ .maxlen = sizeof(int),
78944+ .mode = 0600,
78945+ .proc_handler = &proc_dointvec,
78946+ },
78947+#endif
78948+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
78949+ {
78950+ .procname = "socket_all",
78951+ .data = &grsec_enable_socket_all,
78952+ .maxlen = sizeof(int),
78953+ .mode = 0600,
78954+ .proc_handler = &proc_dointvec,
78955+ },
78956+ {
78957+ .procname = "socket_all_gid",
78958+ .data = &grsec_socket_all_gid,
78959+ .maxlen = sizeof(int),
78960+ .mode = 0600,
78961+ .proc_handler = &proc_dointvec,
78962+ },
78963+#endif
78964+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
78965+ {
78966+ .procname = "socket_client",
78967+ .data = &grsec_enable_socket_client,
78968+ .maxlen = sizeof(int),
78969+ .mode = 0600,
78970+ .proc_handler = &proc_dointvec,
78971+ },
78972+ {
78973+ .procname = "socket_client_gid",
78974+ .data = &grsec_socket_client_gid,
78975+ .maxlen = sizeof(int),
78976+ .mode = 0600,
78977+ .proc_handler = &proc_dointvec,
78978+ },
78979+#endif
78980+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
78981+ {
78982+ .procname = "socket_server",
78983+ .data = &grsec_enable_socket_server,
78984+ .maxlen = sizeof(int),
78985+ .mode = 0600,
78986+ .proc_handler = &proc_dointvec,
78987+ },
78988+ {
78989+ .procname = "socket_server_gid",
78990+ .data = &grsec_socket_server_gid,
78991+ .maxlen = sizeof(int),
78992+ .mode = 0600,
78993+ .proc_handler = &proc_dointvec,
78994+ },
78995+#endif
78996+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
78997+ {
78998+ .procname = "audit_group",
78999+ .data = &grsec_enable_group,
79000+ .maxlen = sizeof(int),
79001+ .mode = 0600,
79002+ .proc_handler = &proc_dointvec,
79003+ },
79004+ {
79005+ .procname = "audit_gid",
79006+ .data = &grsec_audit_gid,
79007+ .maxlen = sizeof(int),
79008+ .mode = 0600,
79009+ .proc_handler = &proc_dointvec,
79010+ },
79011+#endif
79012+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
79013+ {
79014+ .procname = "audit_chdir",
79015+ .data = &grsec_enable_chdir,
79016+ .maxlen = sizeof(int),
79017+ .mode = 0600,
79018+ .proc_handler = &proc_dointvec,
79019+ },
79020+#endif
79021+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
79022+ {
79023+ .procname = "audit_mount",
79024+ .data = &grsec_enable_mount,
79025+ .maxlen = sizeof(int),
79026+ .mode = 0600,
79027+ .proc_handler = &proc_dointvec,
79028+ },
79029+#endif
79030+#ifdef CONFIG_GRKERNSEC_DMESG
79031+ {
79032+ .procname = "dmesg",
79033+ .data = &grsec_enable_dmesg,
79034+ .maxlen = sizeof(int),
79035+ .mode = 0600,
79036+ .proc_handler = &proc_dointvec,
79037+ },
79038+#endif
79039+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79040+ {
79041+ .procname = "chroot_findtask",
79042+ .data = &grsec_enable_chroot_findtask,
79043+ .maxlen = sizeof(int),
79044+ .mode = 0600,
79045+ .proc_handler = &proc_dointvec,
79046+ },
79047+#endif
79048+#ifdef CONFIG_GRKERNSEC_RESLOG
79049+ {
79050+ .procname = "resource_logging",
79051+ .data = &grsec_resource_logging,
79052+ .maxlen = sizeof(int),
79053+ .mode = 0600,
79054+ .proc_handler = &proc_dointvec,
79055+ },
79056+#endif
79057+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
79058+ {
79059+ .procname = "audit_ptrace",
79060+ .data = &grsec_enable_audit_ptrace,
79061+ .maxlen = sizeof(int),
79062+ .mode = 0600,
79063+ .proc_handler = &proc_dointvec,
79064+ },
79065+#endif
79066+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
79067+ {
79068+ .procname = "harden_ptrace",
79069+ .data = &grsec_enable_harden_ptrace,
79070+ .maxlen = sizeof(int),
79071+ .mode = 0600,
79072+ .proc_handler = &proc_dointvec,
79073+ },
79074+#endif
79075+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
79076+ {
79077+ .procname = "harden_ipc",
79078+ .data = &grsec_enable_harden_ipc,
79079+ .maxlen = sizeof(int),
79080+ .mode = 0600,
79081+ .proc_handler = &proc_dointvec,
79082+ },
79083+#endif
79084+ {
79085+ .procname = "grsec_lock",
79086+ .data = &grsec_lock,
79087+ .maxlen = sizeof(int),
79088+ .mode = 0600,
79089+ .proc_handler = &proc_dointvec,
79090+ },
79091+#endif
79092+#ifdef CONFIG_GRKERNSEC_ROFS
79093+ {
79094+ .procname = "romount_protect",
79095+ .data = &grsec_enable_rofs,
79096+ .maxlen = sizeof(int),
79097+ .mode = 0600,
79098+ .proc_handler = &proc_dointvec_minmax,
79099+ .extra1 = &one,
79100+ .extra2 = &one,
79101+ },
79102+#endif
79103+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
79104+ {
79105+ .procname = "deny_new_usb",
79106+ .data = &grsec_deny_new_usb,
79107+ .maxlen = sizeof(int),
79108+ .mode = 0600,
79109+ .proc_handler = &proc_dointvec,
79110+ },
79111+#endif
79112+ { }
79113+};
79114+#endif
79115diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
79116new file mode 100644
79117index 0000000..61b514e
79118--- /dev/null
79119+++ b/grsecurity/grsec_time.c
79120@@ -0,0 +1,16 @@
79121+#include <linux/kernel.h>
79122+#include <linux/sched.h>
79123+#include <linux/grinternal.h>
79124+#include <linux/module.h>
79125+
79126+void
79127+gr_log_timechange(void)
79128+{
79129+#ifdef CONFIG_GRKERNSEC_TIME
79130+ if (grsec_enable_time)
79131+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
79132+#endif
79133+ return;
79134+}
79135+
79136+EXPORT_SYMBOL_GPL(gr_log_timechange);
79137diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
79138new file mode 100644
79139index 0000000..d1953de
79140--- /dev/null
79141+++ b/grsecurity/grsec_tpe.c
79142@@ -0,0 +1,78 @@
79143+#include <linux/kernel.h>
79144+#include <linux/sched.h>
79145+#include <linux/file.h>
79146+#include <linux/fs.h>
79147+#include <linux/grinternal.h>
79148+
79149+extern int gr_acl_tpe_check(void);
79150+
79151+int
79152+gr_tpe_allow(const struct file *file)
79153+{
79154+#ifdef CONFIG_GRKERNSEC
79155+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
79156+ struct inode *file_inode = file->f_path.dentry->d_inode;
79157+ const struct cred *cred = current_cred();
79158+ char *msg = NULL;
79159+ char *msg2 = NULL;
79160+
79161+ // never restrict root
79162+ if (gr_is_global_root(cred->uid))
79163+ return 1;
79164+
79165+ if (grsec_enable_tpe) {
79166+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
79167+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
79168+ msg = "not being in trusted group";
79169+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
79170+ msg = "being in untrusted group";
79171+#else
79172+ if (in_group_p(grsec_tpe_gid))
79173+ msg = "being in untrusted group";
79174+#endif
79175+ }
79176+ if (!msg && gr_acl_tpe_check())
79177+ msg = "being in untrusted role";
79178+
79179+ // not in any affected group/role
79180+ if (!msg)
79181+ goto next_check;
79182+
79183+ if (gr_is_global_nonroot(inode->i_uid))
79184+ msg2 = "file in non-root-owned directory";
79185+ else if (inode->i_mode & S_IWOTH)
79186+ msg2 = "file in world-writable directory";
79187+ else if (inode->i_mode & S_IWGRP)
79188+ msg2 = "file in group-writable directory";
79189+ else if (file_inode->i_mode & S_IWOTH)
79190+ msg2 = "file is world-writable";
79191+
79192+ if (msg && msg2) {
79193+ char fullmsg[70] = {0};
79194+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
79195+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
79196+ return 0;
79197+ }
79198+ msg = NULL;
79199+next_check:
79200+#ifdef CONFIG_GRKERNSEC_TPE_ALL
79201+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
79202+ return 1;
79203+
79204+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
79205+ msg = "directory not owned by user";
79206+ else if (inode->i_mode & S_IWOTH)
79207+ msg = "file in world-writable directory";
79208+ else if (inode->i_mode & S_IWGRP)
79209+ msg = "file in group-writable directory";
79210+ else if (file_inode->i_mode & S_IWOTH)
79211+ msg = "file is world-writable";
79212+
79213+ if (msg) {
79214+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
79215+ return 0;
79216+ }
79217+#endif
79218+#endif
79219+ return 1;
79220+}
79221diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
79222new file mode 100644
79223index 0000000..ae02d8e
79224--- /dev/null
79225+++ b/grsecurity/grsec_usb.c
79226@@ -0,0 +1,15 @@
79227+#include <linux/kernel.h>
79228+#include <linux/grinternal.h>
79229+#include <linux/module.h>
79230+
79231+int gr_handle_new_usb(void)
79232+{
79233+#ifdef CONFIG_GRKERNSEC_DENYUSB
79234+ if (grsec_deny_new_usb) {
79235+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
79236+ return 1;
79237+ }
79238+#endif
79239+ return 0;
79240+}
79241+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
79242diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
79243new file mode 100644
79244index 0000000..158b330
79245--- /dev/null
79246+++ b/grsecurity/grsum.c
79247@@ -0,0 +1,64 @@
79248+#include <linux/err.h>
79249+#include <linux/kernel.h>
79250+#include <linux/sched.h>
79251+#include <linux/mm.h>
79252+#include <linux/scatterlist.h>
79253+#include <linux/crypto.h>
79254+#include <linux/gracl.h>
79255+
79256+
79257+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
79258+#error "crypto and sha256 must be built into the kernel"
79259+#endif
79260+
79261+int
79262+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
79263+{
79264+ struct crypto_hash *tfm;
79265+ struct hash_desc desc;
79266+ struct scatterlist sg[2];
79267+ unsigned char temp_sum[GR_SHA_LEN] __attribute__((aligned(__alignof__(unsigned long))));
79268+ unsigned long *tmpsumptr = (unsigned long *)temp_sum;
79269+ unsigned long *sumptr = (unsigned long *)sum;
79270+ int cryptres;
79271+ int retval = 1;
79272+ volatile int mismatched = 0;
79273+ volatile int dummy = 0;
79274+ unsigned int i;
79275+
79276+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
79277+ if (IS_ERR(tfm)) {
79278+ /* should never happen, since sha256 should be built in */
79279+ memset(entry->pw, 0, GR_PW_LEN);
79280+ return 1;
79281+ }
79282+
79283+ sg_init_table(sg, 2);
79284+ sg_set_buf(&sg[0], salt, GR_SALT_LEN);
79285+ sg_set_buf(&sg[1], entry->pw, strlen(entry->pw));
79286+
79287+ desc.tfm = tfm;
79288+ desc.flags = 0;
79289+
79290+ cryptres = crypto_hash_digest(&desc, sg, GR_SALT_LEN + strlen(entry->pw),
79291+ temp_sum);
79292+
79293+ memset(entry->pw, 0, GR_PW_LEN);
79294+
79295+ if (cryptres)
79296+ goto out;
79297+
79298+ for (i = 0; i < GR_SHA_LEN/sizeof(tmpsumptr[0]); i++)
79299+ if (sumptr[i] != tmpsumptr[i])
79300+ mismatched = 1;
79301+ else
79302+ dummy = 1; // waste a cycle
79303+
79304+ if (!mismatched)
79305+ retval = dummy - 1;
79306+
79307+out:
79308+ crypto_free_hash(tfm);
79309+
79310+ return retval;
79311+}
79312diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
79313index 77ff547..181834f 100644
79314--- a/include/asm-generic/4level-fixup.h
79315+++ b/include/asm-generic/4level-fixup.h
79316@@ -13,8 +13,10 @@
79317 #define pmd_alloc(mm, pud, address) \
79318 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
79319 NULL: pmd_offset(pud, address))
79320+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
79321
79322 #define pud_alloc(mm, pgd, address) (pgd)
79323+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
79324 #define pud_offset(pgd, start) (pgd)
79325 #define pud_none(pud) 0
79326 #define pud_bad(pud) 0
79327diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
79328index b7babf0..97f4c4f 100644
79329--- a/include/asm-generic/atomic-long.h
79330+++ b/include/asm-generic/atomic-long.h
79331@@ -22,6 +22,12 @@
79332
79333 typedef atomic64_t atomic_long_t;
79334
79335+#ifdef CONFIG_PAX_REFCOUNT
79336+typedef atomic64_unchecked_t atomic_long_unchecked_t;
79337+#else
79338+typedef atomic64_t atomic_long_unchecked_t;
79339+#endif
79340+
79341 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
79342
79343 static inline long atomic_long_read(atomic_long_t *l)
79344@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79345 return (long)atomic64_read(v);
79346 }
79347
79348+#ifdef CONFIG_PAX_REFCOUNT
79349+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79350+{
79351+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79352+
79353+ return (long)atomic64_read_unchecked(v);
79354+}
79355+#endif
79356+
79357 static inline void atomic_long_set(atomic_long_t *l, long i)
79358 {
79359 atomic64_t *v = (atomic64_t *)l;
79360@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79361 atomic64_set(v, i);
79362 }
79363
79364+#ifdef CONFIG_PAX_REFCOUNT
79365+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79366+{
79367+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79368+
79369+ atomic64_set_unchecked(v, i);
79370+}
79371+#endif
79372+
79373 static inline void atomic_long_inc(atomic_long_t *l)
79374 {
79375 atomic64_t *v = (atomic64_t *)l;
79376@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79377 atomic64_inc(v);
79378 }
79379
79380+#ifdef CONFIG_PAX_REFCOUNT
79381+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79382+{
79383+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79384+
79385+ atomic64_inc_unchecked(v);
79386+}
79387+#endif
79388+
79389 static inline void atomic_long_dec(atomic_long_t *l)
79390 {
79391 atomic64_t *v = (atomic64_t *)l;
79392@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79393 atomic64_dec(v);
79394 }
79395
79396+#ifdef CONFIG_PAX_REFCOUNT
79397+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79398+{
79399+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79400+
79401+ atomic64_dec_unchecked(v);
79402+}
79403+#endif
79404+
79405 static inline void atomic_long_add(long i, atomic_long_t *l)
79406 {
79407 atomic64_t *v = (atomic64_t *)l;
79408@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79409 atomic64_add(i, v);
79410 }
79411
79412+#ifdef CONFIG_PAX_REFCOUNT
79413+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79414+{
79415+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79416+
79417+ atomic64_add_unchecked(i, v);
79418+}
79419+#endif
79420+
79421 static inline void atomic_long_sub(long i, atomic_long_t *l)
79422 {
79423 atomic64_t *v = (atomic64_t *)l;
79424@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79425 atomic64_sub(i, v);
79426 }
79427
79428+#ifdef CONFIG_PAX_REFCOUNT
79429+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79430+{
79431+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79432+
79433+ atomic64_sub_unchecked(i, v);
79434+}
79435+#endif
79436+
79437 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79438 {
79439 atomic64_t *v = (atomic64_t *)l;
79440@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
79441 return atomic64_add_negative(i, v);
79442 }
79443
79444-static inline long atomic_long_add_return(long i, atomic_long_t *l)
79445+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
79446 {
79447 atomic64_t *v = (atomic64_t *)l;
79448
79449 return (long)atomic64_add_return(i, v);
79450 }
79451
79452+#ifdef CONFIG_PAX_REFCOUNT
79453+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79454+{
79455+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79456+
79457+ return (long)atomic64_add_return_unchecked(i, v);
79458+}
79459+#endif
79460+
79461 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79462 {
79463 atomic64_t *v = (atomic64_t *)l;
79464@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79465 return (long)atomic64_inc_return(v);
79466 }
79467
79468+#ifdef CONFIG_PAX_REFCOUNT
79469+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79470+{
79471+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
79472+
79473+ return (long)atomic64_inc_return_unchecked(v);
79474+}
79475+#endif
79476+
79477 static inline long atomic_long_dec_return(atomic_long_t *l)
79478 {
79479 atomic64_t *v = (atomic64_t *)l;
79480@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79481
79482 typedef atomic_t atomic_long_t;
79483
79484+#ifdef CONFIG_PAX_REFCOUNT
79485+typedef atomic_unchecked_t atomic_long_unchecked_t;
79486+#else
79487+typedef atomic_t atomic_long_unchecked_t;
79488+#endif
79489+
79490 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
79491 static inline long atomic_long_read(atomic_long_t *l)
79492 {
79493@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
79494 return (long)atomic_read(v);
79495 }
79496
79497+#ifdef CONFIG_PAX_REFCOUNT
79498+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
79499+{
79500+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79501+
79502+ return (long)atomic_read_unchecked(v);
79503+}
79504+#endif
79505+
79506 static inline void atomic_long_set(atomic_long_t *l, long i)
79507 {
79508 atomic_t *v = (atomic_t *)l;
79509@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
79510 atomic_set(v, i);
79511 }
79512
79513+#ifdef CONFIG_PAX_REFCOUNT
79514+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
79515+{
79516+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79517+
79518+ atomic_set_unchecked(v, i);
79519+}
79520+#endif
79521+
79522 static inline void atomic_long_inc(atomic_long_t *l)
79523 {
79524 atomic_t *v = (atomic_t *)l;
79525@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
79526 atomic_inc(v);
79527 }
79528
79529+#ifdef CONFIG_PAX_REFCOUNT
79530+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
79531+{
79532+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79533+
79534+ atomic_inc_unchecked(v);
79535+}
79536+#endif
79537+
79538 static inline void atomic_long_dec(atomic_long_t *l)
79539 {
79540 atomic_t *v = (atomic_t *)l;
79541@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
79542 atomic_dec(v);
79543 }
79544
79545+#ifdef CONFIG_PAX_REFCOUNT
79546+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
79547+{
79548+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79549+
79550+ atomic_dec_unchecked(v);
79551+}
79552+#endif
79553+
79554 static inline void atomic_long_add(long i, atomic_long_t *l)
79555 {
79556 atomic_t *v = (atomic_t *)l;
79557@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
79558 atomic_add(i, v);
79559 }
79560
79561+#ifdef CONFIG_PAX_REFCOUNT
79562+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
79563+{
79564+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79565+
79566+ atomic_add_unchecked(i, v);
79567+}
79568+#endif
79569+
79570 static inline void atomic_long_sub(long i, atomic_long_t *l)
79571 {
79572 atomic_t *v = (atomic_t *)l;
79573@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
79574 atomic_sub(i, v);
79575 }
79576
79577+#ifdef CONFIG_PAX_REFCOUNT
79578+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
79579+{
79580+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79581+
79582+ atomic_sub_unchecked(i, v);
79583+}
79584+#endif
79585+
79586 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
79587 {
79588 atomic_t *v = (atomic_t *)l;
79589@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
79590 return (long)atomic_add_return(i, v);
79591 }
79592
79593+#ifdef CONFIG_PAX_REFCOUNT
79594+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
79595+{
79596+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79597+
79598+ return (long)atomic_add_return_unchecked(i, v);
79599+}
79600+
79601+#endif
79602+
79603 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
79604 {
79605 atomic_t *v = (atomic_t *)l;
79606@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
79607 return (long)atomic_inc_return(v);
79608 }
79609
79610+#ifdef CONFIG_PAX_REFCOUNT
79611+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
79612+{
79613+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
79614+
79615+ return (long)atomic_inc_return_unchecked(v);
79616+}
79617+#endif
79618+
79619 static inline long atomic_long_dec_return(atomic_long_t *l)
79620 {
79621 atomic_t *v = (atomic_t *)l;
79622@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
79623
79624 #endif /* BITS_PER_LONG == 64 */
79625
79626+#ifdef CONFIG_PAX_REFCOUNT
79627+static inline void pax_refcount_needs_these_functions(void)
79628+{
79629+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
79630+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
79631+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
79632+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
79633+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
79634+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
79635+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
79636+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
79637+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
79638+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
79639+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
79640+#ifdef CONFIG_X86
79641+ atomic_clear_mask_unchecked(0, NULL);
79642+ atomic_set_mask_unchecked(0, NULL);
79643+#endif
79644+
79645+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
79646+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
79647+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
79648+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
79649+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
79650+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
79651+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
79652+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
79653+}
79654+#else
79655+#define atomic_read_unchecked(v) atomic_read(v)
79656+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
79657+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
79658+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
79659+#define atomic_inc_unchecked(v) atomic_inc(v)
79660+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
79661+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
79662+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
79663+#define atomic_dec_unchecked(v) atomic_dec(v)
79664+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
79665+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
79666+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
79667+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
79668+
79669+#define atomic_long_read_unchecked(v) atomic_long_read(v)
79670+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
79671+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
79672+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
79673+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
79674+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
79675+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
79676+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
79677+#endif
79678+
79679 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
79680diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
79681index 9c79e76..9f7827d 100644
79682--- a/include/asm-generic/atomic.h
79683+++ b/include/asm-generic/atomic.h
79684@@ -154,7 +154,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
79685 * Atomically clears the bits set in @mask from @v
79686 */
79687 #ifndef atomic_clear_mask
79688-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
79689+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
79690 {
79691 unsigned long flags;
79692
79693diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
79694index b18ce4f..2ee2843 100644
79695--- a/include/asm-generic/atomic64.h
79696+++ b/include/asm-generic/atomic64.h
79697@@ -16,6 +16,8 @@ typedef struct {
79698 long long counter;
79699 } atomic64_t;
79700
79701+typedef atomic64_t atomic64_unchecked_t;
79702+
79703 #define ATOMIC64_INIT(i) { (i) }
79704
79705 extern long long atomic64_read(const atomic64_t *v);
79706@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
79707 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
79708 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
79709
79710+#define atomic64_read_unchecked(v) atomic64_read(v)
79711+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
79712+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
79713+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
79714+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
79715+#define atomic64_inc_unchecked(v) atomic64_inc(v)
79716+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
79717+#define atomic64_dec_unchecked(v) atomic64_dec(v)
79718+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
79719+
79720 #endif /* _ASM_GENERIC_ATOMIC64_H */
79721diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
79722index 1402fa8..025a736 100644
79723--- a/include/asm-generic/barrier.h
79724+++ b/include/asm-generic/barrier.h
79725@@ -74,7 +74,7 @@
79726 do { \
79727 compiletime_assert_atomic_type(*p); \
79728 smp_mb(); \
79729- ACCESS_ONCE(*p) = (v); \
79730+ ACCESS_ONCE_RW(*p) = (v); \
79731 } while (0)
79732
79733 #define smp_load_acquire(p) \
79734diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
79735index a60a7cc..0fe12f2 100644
79736--- a/include/asm-generic/bitops/__fls.h
79737+++ b/include/asm-generic/bitops/__fls.h
79738@@ -9,7 +9,7 @@
79739 *
79740 * Undefined if no set bit exists, so code should check against 0 first.
79741 */
79742-static __always_inline unsigned long __fls(unsigned long word)
79743+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
79744 {
79745 int num = BITS_PER_LONG - 1;
79746
79747diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
79748index 0576d1f..dad6c71 100644
79749--- a/include/asm-generic/bitops/fls.h
79750+++ b/include/asm-generic/bitops/fls.h
79751@@ -9,7 +9,7 @@
79752 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
79753 */
79754
79755-static __always_inline int fls(int x)
79756+static __always_inline int __intentional_overflow(-1) fls(int x)
79757 {
79758 int r = 32;
79759
79760diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
79761index b097cf8..3d40e14 100644
79762--- a/include/asm-generic/bitops/fls64.h
79763+++ b/include/asm-generic/bitops/fls64.h
79764@@ -15,7 +15,7 @@
79765 * at position 64.
79766 */
79767 #if BITS_PER_LONG == 32
79768-static __always_inline int fls64(__u64 x)
79769+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79770 {
79771 __u32 h = x >> 32;
79772 if (h)
79773@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
79774 return fls(x);
79775 }
79776 #elif BITS_PER_LONG == 64
79777-static __always_inline int fls64(__u64 x)
79778+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
79779 {
79780 if (x == 0)
79781 return 0;
79782diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
79783index 1bfcfe5..e04c5c9 100644
79784--- a/include/asm-generic/cache.h
79785+++ b/include/asm-generic/cache.h
79786@@ -6,7 +6,7 @@
79787 * cache lines need to provide their own cache.h.
79788 */
79789
79790-#define L1_CACHE_SHIFT 5
79791-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
79792+#define L1_CACHE_SHIFT 5UL
79793+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
79794
79795 #endif /* __ASM_GENERIC_CACHE_H */
79796diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
79797index 0d68a1e..b74a761 100644
79798--- a/include/asm-generic/emergency-restart.h
79799+++ b/include/asm-generic/emergency-restart.h
79800@@ -1,7 +1,7 @@
79801 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
79802 #define _ASM_GENERIC_EMERGENCY_RESTART_H
79803
79804-static inline void machine_emergency_restart(void)
79805+static inline __noreturn void machine_emergency_restart(void)
79806 {
79807 machine_restart(NULL);
79808 }
79809diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
79810index 975e1cc..0b8a083 100644
79811--- a/include/asm-generic/io.h
79812+++ b/include/asm-generic/io.h
79813@@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
79814 * These are pretty trivial
79815 */
79816 #ifndef virt_to_phys
79817-static inline unsigned long virt_to_phys(volatile void *address)
79818+static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
79819 {
79820 return __pa((unsigned long)address);
79821 }
79822diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
79823index 90f99c7..00ce236 100644
79824--- a/include/asm-generic/kmap_types.h
79825+++ b/include/asm-generic/kmap_types.h
79826@@ -2,9 +2,9 @@
79827 #define _ASM_GENERIC_KMAP_TYPES_H
79828
79829 #ifdef __WITH_KM_FENCE
79830-# define KM_TYPE_NR 41
79831+# define KM_TYPE_NR 42
79832 #else
79833-# define KM_TYPE_NR 20
79834+# define KM_TYPE_NR 21
79835 #endif
79836
79837 #endif
79838diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
79839index 9ceb03b..62b0b8f 100644
79840--- a/include/asm-generic/local.h
79841+++ b/include/asm-generic/local.h
79842@@ -23,24 +23,37 @@ typedef struct
79843 atomic_long_t a;
79844 } local_t;
79845
79846+typedef struct {
79847+ atomic_long_unchecked_t a;
79848+} local_unchecked_t;
79849+
79850 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
79851
79852 #define local_read(l) atomic_long_read(&(l)->a)
79853+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
79854 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
79855+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
79856 #define local_inc(l) atomic_long_inc(&(l)->a)
79857+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
79858 #define local_dec(l) atomic_long_dec(&(l)->a)
79859+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
79860 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
79861+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
79862 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
79863+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
79864
79865 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
79866 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
79867 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
79868 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
79869 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
79870+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
79871 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
79872 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
79873+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
79874
79875 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
79876+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
79877 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
79878 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
79879 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
79880diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
79881index 725612b..9cc513a 100644
79882--- a/include/asm-generic/pgtable-nopmd.h
79883+++ b/include/asm-generic/pgtable-nopmd.h
79884@@ -1,14 +1,19 @@
79885 #ifndef _PGTABLE_NOPMD_H
79886 #define _PGTABLE_NOPMD_H
79887
79888-#ifndef __ASSEMBLY__
79889-
79890 #include <asm-generic/pgtable-nopud.h>
79891
79892-struct mm_struct;
79893-
79894 #define __PAGETABLE_PMD_FOLDED
79895
79896+#define PMD_SHIFT PUD_SHIFT
79897+#define PTRS_PER_PMD 1
79898+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
79899+#define PMD_MASK (~(PMD_SIZE-1))
79900+
79901+#ifndef __ASSEMBLY__
79902+
79903+struct mm_struct;
79904+
79905 /*
79906 * Having the pmd type consist of a pud gets the size right, and allows
79907 * us to conceptually access the pud entry that this pmd is folded into
79908@@ -16,11 +21,6 @@ struct mm_struct;
79909 */
79910 typedef struct { pud_t pud; } pmd_t;
79911
79912-#define PMD_SHIFT PUD_SHIFT
79913-#define PTRS_PER_PMD 1
79914-#define PMD_SIZE (1UL << PMD_SHIFT)
79915-#define PMD_MASK (~(PMD_SIZE-1))
79916-
79917 /*
79918 * The "pud_xxx()" functions here are trivial for a folded two-level
79919 * setup: the pmd is never bad, and a pmd always exists (as it's folded
79920diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
79921index 810431d..0ec4804f 100644
79922--- a/include/asm-generic/pgtable-nopud.h
79923+++ b/include/asm-generic/pgtable-nopud.h
79924@@ -1,10 +1,15 @@
79925 #ifndef _PGTABLE_NOPUD_H
79926 #define _PGTABLE_NOPUD_H
79927
79928-#ifndef __ASSEMBLY__
79929-
79930 #define __PAGETABLE_PUD_FOLDED
79931
79932+#define PUD_SHIFT PGDIR_SHIFT
79933+#define PTRS_PER_PUD 1
79934+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
79935+#define PUD_MASK (~(PUD_SIZE-1))
79936+
79937+#ifndef __ASSEMBLY__
79938+
79939 /*
79940 * Having the pud type consist of a pgd gets the size right, and allows
79941 * us to conceptually access the pgd entry that this pud is folded into
79942@@ -12,11 +17,6 @@
79943 */
79944 typedef struct { pgd_t pgd; } pud_t;
79945
79946-#define PUD_SHIFT PGDIR_SHIFT
79947-#define PTRS_PER_PUD 1
79948-#define PUD_SIZE (1UL << PUD_SHIFT)
79949-#define PUD_MASK (~(PUD_SIZE-1))
79950-
79951 /*
79952 * The "pgd_xxx()" functions here are trivial for a folded two-level
79953 * setup: the pud is never bad, and a pud always exists (as it's folded
79954@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
79955 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
79956
79957 #define pgd_populate(mm, pgd, pud) do { } while (0)
79958+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
79959 /*
79960 * (puds are folded into pgds so this doesn't get actually called,
79961 * but the define is needed for a generic inline function.)
79962diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
79963index 53b2acc..f4568e7 100644
79964--- a/include/asm-generic/pgtable.h
79965+++ b/include/asm-generic/pgtable.h
79966@@ -819,6 +819,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
79967 }
79968 #endif /* CONFIG_NUMA_BALANCING */
79969
79970+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
79971+#ifdef CONFIG_PAX_KERNEXEC
79972+#error KERNEXEC requires pax_open_kernel
79973+#else
79974+static inline unsigned long pax_open_kernel(void) { return 0; }
79975+#endif
79976+#endif
79977+
79978+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
79979+#ifdef CONFIG_PAX_KERNEXEC
79980+#error KERNEXEC requires pax_close_kernel
79981+#else
79982+static inline unsigned long pax_close_kernel(void) { return 0; }
79983+#endif
79984+#endif
79985+
79986 #endif /* CONFIG_MMU */
79987
79988 #endif /* !__ASSEMBLY__ */
79989diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
79990index 72d8803..cb9749c 100644
79991--- a/include/asm-generic/uaccess.h
79992+++ b/include/asm-generic/uaccess.h
79993@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
79994 return __clear_user(to, n);
79995 }
79996
79997+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
79998+#ifdef CONFIG_PAX_MEMORY_UDEREF
79999+#error UDEREF requires pax_open_userland
80000+#else
80001+static inline unsigned long pax_open_userland(void) { return 0; }
80002+#endif
80003+#endif
80004+
80005+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
80006+#ifdef CONFIG_PAX_MEMORY_UDEREF
80007+#error UDEREF requires pax_close_userland
80008+#else
80009+static inline unsigned long pax_close_userland(void) { return 0; }
80010+#endif
80011+#endif
80012+
80013 #endif /* __ASM_GENERIC_UACCESS_H */
80014diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
80015index 5ba0360..e85c934 100644
80016--- a/include/asm-generic/vmlinux.lds.h
80017+++ b/include/asm-generic/vmlinux.lds.h
80018@@ -231,6 +231,7 @@
80019 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
80020 VMLINUX_SYMBOL(__start_rodata) = .; \
80021 *(.rodata) *(.rodata.*) \
80022+ *(.data..read_only) \
80023 *(__vermagic) /* Kernel version magic */ \
80024 . = ALIGN(8); \
80025 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
80026@@ -722,17 +723,18 @@
80027 * section in the linker script will go there too. @phdr should have
80028 * a leading colon.
80029 *
80030- * Note that this macros defines __per_cpu_load as an absolute symbol.
80031+ * Note that this macros defines per_cpu_load as an absolute symbol.
80032 * If there is no need to put the percpu section at a predetermined
80033 * address, use PERCPU_SECTION.
80034 */
80035 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
80036- VMLINUX_SYMBOL(__per_cpu_load) = .; \
80037- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
80038+ per_cpu_load = .; \
80039+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
80040 - LOAD_OFFSET) { \
80041+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
80042 PERCPU_INPUT(cacheline) \
80043 } phdr \
80044- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
80045+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
80046
80047 /**
80048 * PERCPU_SECTION - define output section for percpu area, simple version
80049diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
80050index 623a59c..1e79ab9 100644
80051--- a/include/crypto/algapi.h
80052+++ b/include/crypto/algapi.h
80053@@ -34,7 +34,7 @@ struct crypto_type {
80054 unsigned int maskclear;
80055 unsigned int maskset;
80056 unsigned int tfmsize;
80057-};
80058+} __do_const;
80059
80060 struct crypto_instance {
80061 struct crypto_alg alg;
80062diff --git a/include/drm/drmP.h b/include/drm/drmP.h
80063index 1968907..7d9ed9f 100644
80064--- a/include/drm/drmP.h
80065+++ b/include/drm/drmP.h
80066@@ -68,6 +68,7 @@
80067 #include <linux/workqueue.h>
80068 #include <linux/poll.h>
80069 #include <asm/pgalloc.h>
80070+#include <asm/local.h>
80071 #include <drm/drm.h>
80072 #include <drm/drm_sarea.h>
80073 #include <drm/drm_vma_manager.h>
80074@@ -260,10 +261,12 @@ do { \
80075 * \param cmd command.
80076 * \param arg argument.
80077 */
80078-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
80079+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
80080+ struct drm_file *file_priv);
80081+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
80082 struct drm_file *file_priv);
80083
80084-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80085+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
80086 unsigned long arg);
80087
80088 #define DRM_IOCTL_NR(n) _IOC_NR(n)
80089@@ -279,10 +282,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
80090 struct drm_ioctl_desc {
80091 unsigned int cmd;
80092 int flags;
80093- drm_ioctl_t *func;
80094+ drm_ioctl_t func;
80095 unsigned int cmd_drv;
80096 const char *name;
80097-};
80098+} __do_const;
80099
80100 /**
80101 * Creates a driver or general drm_ioctl_desc array entry for the given
80102@@ -946,7 +949,8 @@ struct drm_info_list {
80103 int (*show)(struct seq_file*, void*); /** show callback */
80104 u32 driver_features; /**< Required driver features for this entry */
80105 void *data;
80106-};
80107+} __do_const;
80108+typedef struct drm_info_list __no_const drm_info_list_no_const;
80109
80110 /**
80111 * debugfs node structure. This structure represents a debugfs file.
80112@@ -1030,7 +1034,7 @@ struct drm_device {
80113
80114 /** \name Usage Counters */
80115 /*@{ */
80116- int open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80117+ local_t open_count; /**< Outstanding files open, protected by drm_global_mutex. */
80118 spinlock_t buf_lock; /**< For drm_device::buf_use and a few other things. */
80119 int buf_use; /**< Buffers in use -- cannot alloc */
80120 atomic_t buf_alloc; /**< Buffer allocation in progress */
80121diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
80122index a3d75fe..6802f9c 100644
80123--- a/include/drm/drm_crtc_helper.h
80124+++ b/include/drm/drm_crtc_helper.h
80125@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
80126 struct drm_connector *connector);
80127 /* disable encoder when not in use - more explicit than dpms off */
80128 void (*disable)(struct drm_encoder *encoder);
80129-};
80130+} __no_const;
80131
80132 /**
80133 * drm_connector_helper_funcs - helper operations for connectors
80134diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
80135index a70d456..6ea07cd 100644
80136--- a/include/drm/i915_pciids.h
80137+++ b/include/drm/i915_pciids.h
80138@@ -37,7 +37,7 @@
80139 */
80140 #define INTEL_VGA_DEVICE(id, info) { \
80141 0x8086, id, \
80142- ~0, ~0, \
80143+ PCI_ANY_ID, PCI_ANY_ID, \
80144 0x030000, 0xff0000, \
80145 (unsigned long) info }
80146
80147diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
80148index 72dcbe8..8db58d7 100644
80149--- a/include/drm/ttm/ttm_memory.h
80150+++ b/include/drm/ttm/ttm_memory.h
80151@@ -48,7 +48,7 @@
80152
80153 struct ttm_mem_shrink {
80154 int (*do_shrink) (struct ttm_mem_shrink *);
80155-};
80156+} __no_const;
80157
80158 /**
80159 * struct ttm_mem_global - Global memory accounting structure.
80160diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
80161index 49a8284..9643967 100644
80162--- a/include/drm/ttm/ttm_page_alloc.h
80163+++ b/include/drm/ttm/ttm_page_alloc.h
80164@@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
80165 */
80166 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
80167
80168+struct device;
80169 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80170 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
80171
80172diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
80173index 4b840e8..155d235 100644
80174--- a/include/keys/asymmetric-subtype.h
80175+++ b/include/keys/asymmetric-subtype.h
80176@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
80177 /* Verify the signature on a key of this subtype (optional) */
80178 int (*verify_signature)(const struct key *key,
80179 const struct public_key_signature *sig);
80180-};
80181+} __do_const;
80182
80183 /**
80184 * asymmetric_key_subtype - Get the subtype from an asymmetric key
80185diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
80186index c1da539..1dcec55 100644
80187--- a/include/linux/atmdev.h
80188+++ b/include/linux/atmdev.h
80189@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
80190 #endif
80191
80192 struct k_atm_aal_stats {
80193-#define __HANDLE_ITEM(i) atomic_t i
80194+#define __HANDLE_ITEM(i) atomic_unchecked_t i
80195 __AAL_STAT_ITEMS
80196 #undef __HANDLE_ITEM
80197 };
80198@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
80199 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
80200 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
80201 struct module *owner;
80202-};
80203+} __do_const ;
80204
80205 struct atmphy_ops {
80206 int (*start)(struct atm_dev *dev);
80207diff --git a/include/linux/audit.h b/include/linux/audit.h
80208index 22cfddb..1514eef 100644
80209--- a/include/linux/audit.h
80210+++ b/include/linux/audit.h
80211@@ -86,7 +86,7 @@ extern unsigned compat_dir_class[];
80212 extern unsigned compat_chattr_class[];
80213 extern unsigned compat_signal_class[];
80214
80215-extern int __weak audit_classify_compat_syscall(int abi, unsigned syscall);
80216+extern int audit_classify_compat_syscall(int abi, unsigned syscall);
80217
80218 /* audit_names->type values */
80219 #define AUDIT_TYPE_UNKNOWN 0 /* we don't know yet */
80220@@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
80221 extern unsigned int audit_serial(void);
80222 extern int auditsc_get_stamp(struct audit_context *ctx,
80223 struct timespec *t, unsigned int *serial);
80224-extern int audit_set_loginuid(kuid_t loginuid);
80225+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
80226
80227 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
80228 {
80229diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
80230index 61f29e5..e67c658 100644
80231--- a/include/linux/binfmts.h
80232+++ b/include/linux/binfmts.h
80233@@ -44,7 +44,7 @@ struct linux_binprm {
80234 unsigned interp_flags;
80235 unsigned interp_data;
80236 unsigned long loader, exec;
80237-};
80238+} __randomize_layout;
80239
80240 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
80241 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
80242@@ -73,8 +73,10 @@ struct linux_binfmt {
80243 int (*load_binary)(struct linux_binprm *);
80244 int (*load_shlib)(struct file *);
80245 int (*core_dump)(struct coredump_params *cprm);
80246+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
80247+ void (*handle_mmap)(struct file *);
80248 unsigned long min_coredump; /* minimal dump size */
80249-};
80250+} __do_const __randomize_layout;
80251
80252 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
80253
80254diff --git a/include/linux/bitops.h b/include/linux/bitops.h
80255index cbc5833..8123ebc 100644
80256--- a/include/linux/bitops.h
80257+++ b/include/linux/bitops.h
80258@@ -122,7 +122,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
80259 * @word: value to rotate
80260 * @shift: bits to roll
80261 */
80262-static inline __u32 rol32(__u32 word, unsigned int shift)
80263+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
80264 {
80265 return (word << shift) | (word >> (32 - shift));
80266 }
80267@@ -132,7 +132,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
80268 * @word: value to rotate
80269 * @shift: bits to roll
80270 */
80271-static inline __u32 ror32(__u32 word, unsigned int shift)
80272+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
80273 {
80274 return (word >> shift) | (word << (32 - shift));
80275 }
80276@@ -188,7 +188,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
80277 return (__s32)(value << shift) >> shift;
80278 }
80279
80280-static inline unsigned fls_long(unsigned long l)
80281+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
80282 {
80283 if (sizeof(l) == 4)
80284 return fls(l);
80285diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
80286index f2057ff8..59dfa2d 100644
80287--- a/include/linux/blkdev.h
80288+++ b/include/linux/blkdev.h
80289@@ -1625,7 +1625,7 @@ struct block_device_operations {
80290 /* this callback is with swap_lock and sometimes page table lock held */
80291 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
80292 struct module *owner;
80293-};
80294+} __do_const;
80295
80296 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
80297 unsigned long);
80298diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
80299index afc1343..9735539 100644
80300--- a/include/linux/blktrace_api.h
80301+++ b/include/linux/blktrace_api.h
80302@@ -25,7 +25,7 @@ struct blk_trace {
80303 struct dentry *dropped_file;
80304 struct dentry *msg_file;
80305 struct list_head running_list;
80306- atomic_t dropped;
80307+ atomic_unchecked_t dropped;
80308 };
80309
80310 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
80311diff --git a/include/linux/cache.h b/include/linux/cache.h
80312index 17e7e82..1d7da26 100644
80313--- a/include/linux/cache.h
80314+++ b/include/linux/cache.h
80315@@ -16,6 +16,14 @@
80316 #define __read_mostly
80317 #endif
80318
80319+#ifndef __read_only
80320+#ifdef CONFIG_PAX_KERNEXEC
80321+#error KERNEXEC requires __read_only
80322+#else
80323+#define __read_only __read_mostly
80324+#endif
80325+#endif
80326+
80327 #ifndef ____cacheline_aligned
80328 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
80329 #endif
80330diff --git a/include/linux/capability.h b/include/linux/capability.h
80331index aa93e5e..985a1b0 100644
80332--- a/include/linux/capability.h
80333+++ b/include/linux/capability.h
80334@@ -214,9 +214,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
80335 extern bool capable(int cap);
80336 extern bool ns_capable(struct user_namespace *ns, int cap);
80337 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
80338+extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
80339 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
80340+extern bool capable_nolog(int cap);
80341+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
80342
80343 /* audit system wants to get cap info from files as well */
80344 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
80345
80346+extern int is_privileged_binary(const struct dentry *dentry);
80347+
80348 #endif /* !_LINUX_CAPABILITY_H */
80349diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
80350index 8609d57..86e4d79 100644
80351--- a/include/linux/cdrom.h
80352+++ b/include/linux/cdrom.h
80353@@ -87,7 +87,6 @@ struct cdrom_device_ops {
80354
80355 /* driver specifications */
80356 const int capability; /* capability flags */
80357- int n_minors; /* number of active minor devices */
80358 /* handle uniform packets for scsi type devices (scsi,atapi) */
80359 int (*generic_packet) (struct cdrom_device_info *,
80360 struct packet_command *);
80361diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
80362index 4ce9056..86caac6 100644
80363--- a/include/linux/cleancache.h
80364+++ b/include/linux/cleancache.h
80365@@ -31,7 +31,7 @@ struct cleancache_ops {
80366 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
80367 void (*invalidate_inode)(int, struct cleancache_filekey);
80368 void (*invalidate_fs)(int);
80369-};
80370+} __no_const;
80371
80372 extern struct cleancache_ops *
80373 cleancache_register_ops(struct cleancache_ops *ops);
80374diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
80375index 411dd7e..ee38878 100644
80376--- a/include/linux/clk-provider.h
80377+++ b/include/linux/clk-provider.h
80378@@ -180,6 +180,7 @@ struct clk_ops {
80379 void (*init)(struct clk_hw *hw);
80380 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
80381 };
80382+typedef struct clk_ops __no_const clk_ops_no_const;
80383
80384 /**
80385 * struct clk_init_data - holds init data that's common to all clocks and is
80386diff --git a/include/linux/clocksource.h b/include/linux/clocksource.h
80387index 653f0e2..abcafaa 100644
80388--- a/include/linux/clocksource.h
80389+++ b/include/linux/clocksource.h
80390@@ -287,7 +287,7 @@ extern struct clocksource* clocksource_get_next(void);
80391 extern void clocksource_change_rating(struct clocksource *cs, int rating);
80392 extern void clocksource_suspend(void);
80393 extern void clocksource_resume(void);
80394-extern struct clocksource * __init __weak clocksource_default_clock(void);
80395+extern struct clocksource * __init clocksource_default_clock(void);
80396 extern void clocksource_mark_unstable(struct clocksource *cs);
80397
80398 extern u64
80399diff --git a/include/linux/compat.h b/include/linux/compat.h
80400index e649426..a74047b 100644
80401--- a/include/linux/compat.h
80402+++ b/include/linux/compat.h
80403@@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
80404 compat_size_t __user *len_ptr);
80405
80406 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
80407-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
80408+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
80409 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
80410 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
80411 compat_ssize_t msgsz, int msgflg);
80412@@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
80413 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
80414 compat_ulong_t addr, compat_ulong_t data);
80415 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
80416- compat_long_t addr, compat_long_t data);
80417+ compat_ulong_t addr, compat_ulong_t data);
80418
80419 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
80420 /*
80421diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
80422index 2507fd2..55203f8 100644
80423--- a/include/linux/compiler-gcc4.h
80424+++ b/include/linux/compiler-gcc4.h
80425@@ -39,9 +39,34 @@
80426 # define __compiletime_warning(message) __attribute__((warning(message)))
80427 # define __compiletime_error(message) __attribute__((error(message)))
80428 #endif /* __CHECKER__ */
80429+
80430+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
80431+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
80432+#define __bos0(ptr) __bos((ptr), 0)
80433+#define __bos1(ptr) __bos((ptr), 1)
80434 #endif /* GCC_VERSION >= 40300 */
80435
80436 #if GCC_VERSION >= 40500
80437+
80438+#ifdef RANDSTRUCT_PLUGIN
80439+#define __randomize_layout __attribute__((randomize_layout))
80440+#define __no_randomize_layout __attribute__((no_randomize_layout))
80441+#endif
80442+
80443+#ifdef CONSTIFY_PLUGIN
80444+#define __no_const __attribute__((no_const))
80445+#define __do_const __attribute__((do_const))
80446+#endif
80447+
80448+#ifdef SIZE_OVERFLOW_PLUGIN
80449+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
80450+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
80451+#endif
80452+
80453+#ifdef LATENT_ENTROPY_PLUGIN
80454+#define __latent_entropy __attribute__((latent_entropy))
80455+#endif
80456+
80457 /*
80458 * Mark a position in code as unreachable. This can be used to
80459 * suppress control flow warnings after asm blocks that transfer
80460diff --git a/include/linux/compiler.h b/include/linux/compiler.h
80461index d5ad7b1..3b74638 100644
80462--- a/include/linux/compiler.h
80463+++ b/include/linux/compiler.h
80464@@ -5,11 +5,14 @@
80465
80466 #ifdef __CHECKER__
80467 # define __user __attribute__((noderef, address_space(1)))
80468+# define __force_user __force __user
80469 # define __kernel __attribute__((address_space(0)))
80470+# define __force_kernel __force __kernel
80471 # define __safe __attribute__((safe))
80472 # define __force __attribute__((force))
80473 # define __nocast __attribute__((nocast))
80474 # define __iomem __attribute__((noderef, address_space(2)))
80475+# define __force_iomem __force __iomem
80476 # define __must_hold(x) __attribute__((context(x,1,1)))
80477 # define __acquires(x) __attribute__((context(x,0,1)))
80478 # define __releases(x) __attribute__((context(x,1,0)))
80479@@ -17,20 +20,37 @@
80480 # define __release(x) __context__(x,-1)
80481 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
80482 # define __percpu __attribute__((noderef, address_space(3)))
80483+# define __force_percpu __force __percpu
80484 #ifdef CONFIG_SPARSE_RCU_POINTER
80485 # define __rcu __attribute__((noderef, address_space(4)))
80486+# define __force_rcu __force __rcu
80487 #else
80488 # define __rcu
80489+# define __force_rcu
80490 #endif
80491 extern void __chk_user_ptr(const volatile void __user *);
80492 extern void __chk_io_ptr(const volatile void __iomem *);
80493 #else
80494-# define __user
80495-# define __kernel
80496+# ifdef CHECKER_PLUGIN
80497+//# define __user
80498+//# define __force_user
80499+//# define __kernel
80500+//# define __force_kernel
80501+# else
80502+# ifdef STRUCTLEAK_PLUGIN
80503+# define __user __attribute__((user))
80504+# else
80505+# define __user
80506+# endif
80507+# define __force_user
80508+# define __kernel
80509+# define __force_kernel
80510+# endif
80511 # define __safe
80512 # define __force
80513 # define __nocast
80514 # define __iomem
80515+# define __force_iomem
80516 # define __chk_user_ptr(x) (void)0
80517 # define __chk_io_ptr(x) (void)0
80518 # define __builtin_warning(x, y...) (1)
80519@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
80520 # define __release(x) (void)0
80521 # define __cond_lock(x,c) (c)
80522 # define __percpu
80523+# define __force_percpu
80524 # define __rcu
80525+# define __force_rcu
80526 #endif
80527
80528 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
80529@@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80530 # define __attribute_const__ /* unimplemented */
80531 #endif
80532
80533+#ifndef __randomize_layout
80534+# define __randomize_layout
80535+#endif
80536+
80537+#ifndef __no_randomize_layout
80538+# define __no_randomize_layout
80539+#endif
80540+
80541+#ifndef __no_const
80542+# define __no_const
80543+#endif
80544+
80545+#ifndef __do_const
80546+# define __do_const
80547+#endif
80548+
80549+#ifndef __size_overflow
80550+# define __size_overflow(...)
80551+#endif
80552+
80553+#ifndef __intentional_overflow
80554+# define __intentional_overflow(...)
80555+#endif
80556+
80557+#ifndef __latent_entropy
80558+# define __latent_entropy
80559+#endif
80560+
80561 /*
80562 * Tell gcc if a function is cold. The compiler will assume any path
80563 * directly leading to the call is unlikely.
80564@@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80565 #define __cold
80566 #endif
80567
80568+#ifndef __alloc_size
80569+#define __alloc_size(...)
80570+#endif
80571+
80572+#ifndef __bos
80573+#define __bos(ptr, arg)
80574+#endif
80575+
80576+#ifndef __bos0
80577+#define __bos0(ptr)
80578+#endif
80579+
80580+#ifndef __bos1
80581+#define __bos1(ptr)
80582+#endif
80583+
80584 /* Simple shorthand for a section definition */
80585 #ifndef __section
80586 # define __section(S) __attribute__ ((__section__(#S)))
80587@@ -378,7 +444,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
80588 * use is to mediate communication between process-level code and irq/NMI
80589 * handlers, all running on the same CPU.
80590 */
80591-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
80592+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
80593+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
80594
80595 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
80596 #ifdef CONFIG_KPROBES
80597diff --git a/include/linux/completion.h b/include/linux/completion.h
80598index 5d5aaae..0ea9b84 100644
80599--- a/include/linux/completion.h
80600+++ b/include/linux/completion.h
80601@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
80602
80603 extern void wait_for_completion(struct completion *);
80604 extern void wait_for_completion_io(struct completion *);
80605-extern int wait_for_completion_interruptible(struct completion *x);
80606-extern int wait_for_completion_killable(struct completion *x);
80607+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
80608+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
80609 extern unsigned long wait_for_completion_timeout(struct completion *x,
80610- unsigned long timeout);
80611+ unsigned long timeout) __intentional_overflow(-1);
80612 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
80613- unsigned long timeout);
80614+ unsigned long timeout) __intentional_overflow(-1);
80615 extern long wait_for_completion_interruptible_timeout(
80616- struct completion *x, unsigned long timeout);
80617+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80618 extern long wait_for_completion_killable_timeout(
80619- struct completion *x, unsigned long timeout);
80620+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
80621 extern bool try_wait_for_completion(struct completion *x);
80622 extern bool completion_done(struct completion *x);
80623
80624diff --git a/include/linux/configfs.h b/include/linux/configfs.h
80625index 34025df..d94bbbc 100644
80626--- a/include/linux/configfs.h
80627+++ b/include/linux/configfs.h
80628@@ -125,7 +125,7 @@ struct configfs_attribute {
80629 const char *ca_name;
80630 struct module *ca_owner;
80631 umode_t ca_mode;
80632-};
80633+} __do_const;
80634
80635 /*
80636 * Users often need to create attribute structures for their configurable
80637diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
80638index 7d1955a..d86a3ca 100644
80639--- a/include/linux/cpufreq.h
80640+++ b/include/linux/cpufreq.h
80641@@ -203,6 +203,7 @@ struct global_attr {
80642 ssize_t (*store)(struct kobject *a, struct attribute *b,
80643 const char *c, size_t count);
80644 };
80645+typedef struct global_attr __no_const global_attr_no_const;
80646
80647 #define define_one_global_ro(_name) \
80648 static struct global_attr _name = \
80649@@ -269,7 +270,7 @@ struct cpufreq_driver {
80650 bool boost_supported;
80651 bool boost_enabled;
80652 int (*set_boost) (int state);
80653-};
80654+} __do_const;
80655
80656 /* flags */
80657 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
80658diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
80659index 25e0df6..952dffd 100644
80660--- a/include/linux/cpuidle.h
80661+++ b/include/linux/cpuidle.h
80662@@ -50,7 +50,8 @@ struct cpuidle_state {
80663 int index);
80664
80665 int (*enter_dead) (struct cpuidle_device *dev, int index);
80666-};
80667+} __do_const;
80668+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
80669
80670 /* Idle State Flags */
80671 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
80672@@ -209,7 +210,7 @@ struct cpuidle_governor {
80673 void (*reflect) (struct cpuidle_device *dev, int index);
80674
80675 struct module *owner;
80676-};
80677+} __do_const;
80678
80679 #ifdef CONFIG_CPU_IDLE
80680 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
80681diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
80682index 2997af6..424ddc1 100644
80683--- a/include/linux/cpumask.h
80684+++ b/include/linux/cpumask.h
80685@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80686 }
80687
80688 /* Valid inputs for n are -1 and 0. */
80689-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80690+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80691 {
80692 return n+1;
80693 }
80694
80695-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80696+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80697 {
80698 return n+1;
80699 }
80700
80701-static inline unsigned int cpumask_next_and(int n,
80702+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
80703 const struct cpumask *srcp,
80704 const struct cpumask *andp)
80705 {
80706@@ -174,7 +174,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
80707 *
80708 * Returns >= nr_cpu_ids if no further cpus set.
80709 */
80710-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80711+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
80712 {
80713 /* -1 is a legal arg here. */
80714 if (n != -1)
80715@@ -189,7 +189,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
80716 *
80717 * Returns >= nr_cpu_ids if no further cpus unset.
80718 */
80719-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80720+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
80721 {
80722 /* -1 is a legal arg here. */
80723 if (n != -1)
80724@@ -197,7 +197,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
80725 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
80726 }
80727
80728-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
80729+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
80730 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
80731 int cpumask_set_cpu_local_first(int i, int numa_node, cpumask_t *dstp);
80732
80733diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h
80734index 72ab536..3849fce 100644
80735--- a/include/linux/crash_dump.h
80736+++ b/include/linux/crash_dump.h
80737@@ -14,14 +14,13 @@
80738 extern unsigned long long elfcorehdr_addr;
80739 extern unsigned long long elfcorehdr_size;
80740
80741-extern int __weak elfcorehdr_alloc(unsigned long long *addr,
80742- unsigned long long *size);
80743-extern void __weak elfcorehdr_free(unsigned long long addr);
80744-extern ssize_t __weak elfcorehdr_read(char *buf, size_t count, u64 *ppos);
80745-extern ssize_t __weak elfcorehdr_read_notes(char *buf, size_t count, u64 *ppos);
80746-extern int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
80747- unsigned long from, unsigned long pfn,
80748- unsigned long size, pgprot_t prot);
80749+extern int elfcorehdr_alloc(unsigned long long *addr, unsigned long long *size);
80750+extern void elfcorehdr_free(unsigned long long addr);
80751+extern ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos);
80752+extern ssize_t elfcorehdr_read_notes(char *buf, size_t count, u64 *ppos);
80753+extern int remap_oldmem_pfn_range(struct vm_area_struct *vma,
80754+ unsigned long from, unsigned long pfn,
80755+ unsigned long size, pgprot_t prot);
80756
80757 extern ssize_t copy_oldmem_page(unsigned long, char *, size_t,
80758 unsigned long, int);
80759diff --git a/include/linux/cred.h b/include/linux/cred.h
80760index b2d0820..2ecafd3 100644
80761--- a/include/linux/cred.h
80762+++ b/include/linux/cred.h
80763@@ -35,7 +35,7 @@ struct group_info {
80764 int nblocks;
80765 kgid_t small_block[NGROUPS_SMALL];
80766 kgid_t *blocks[0];
80767-};
80768+} __randomize_layout;
80769
80770 /**
80771 * get_group_info - Get a reference to a group info structure
80772@@ -136,7 +136,7 @@ struct cred {
80773 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
80774 struct group_info *group_info; /* supplementary groups for euid/fsgid */
80775 struct rcu_head rcu; /* RCU deletion hook */
80776-};
80777+} __randomize_layout;
80778
80779 extern void __put_cred(struct cred *);
80780 extern void exit_creds(struct task_struct *);
80781@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
80782 static inline void validate_process_creds(void)
80783 {
80784 }
80785+static inline void validate_task_creds(struct task_struct *task)
80786+{
80787+}
80788 #endif
80789
80790 /**
80791@@ -331,6 +334,7 @@ static inline void put_cred(const struct cred *_cred)
80792
80793 #define task_uid(task) (task_cred_xxx((task), uid))
80794 #define task_euid(task) (task_cred_xxx((task), euid))
80795+#define task_securebits(task) (task_cred_xxx((task), securebits))
80796
80797 #define current_cred_xxx(xxx) \
80798 ({ \
80799diff --git a/include/linux/crypto.h b/include/linux/crypto.h
80800index d45e949..51cf5ea 100644
80801--- a/include/linux/crypto.h
80802+++ b/include/linux/crypto.h
80803@@ -373,7 +373,7 @@ struct cipher_tfm {
80804 const u8 *key, unsigned int keylen);
80805 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80806 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
80807-};
80808+} __no_const;
80809
80810 struct hash_tfm {
80811 int (*init)(struct hash_desc *desc);
80812@@ -394,13 +394,13 @@ struct compress_tfm {
80813 int (*cot_decompress)(struct crypto_tfm *tfm,
80814 const u8 *src, unsigned int slen,
80815 u8 *dst, unsigned int *dlen);
80816-};
80817+} __no_const;
80818
80819 struct rng_tfm {
80820 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
80821 unsigned int dlen);
80822 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
80823-};
80824+} __no_const;
80825
80826 #define crt_ablkcipher crt_u.ablkcipher
80827 #define crt_aead crt_u.aead
80828diff --git a/include/linux/ctype.h b/include/linux/ctype.h
80829index 653589e..4ef254a 100644
80830--- a/include/linux/ctype.h
80831+++ b/include/linux/ctype.h
80832@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
80833 * Fast implementation of tolower() for internal usage. Do not use in your
80834 * code.
80835 */
80836-static inline char _tolower(const char c)
80837+static inline unsigned char _tolower(const unsigned char c)
80838 {
80839 return c | 0x20;
80840 }
80841diff --git a/include/linux/dcache.h b/include/linux/dcache.h
80842index 75a227c..1456987 100644
80843--- a/include/linux/dcache.h
80844+++ b/include/linux/dcache.h
80845@@ -134,7 +134,7 @@ struct dentry {
80846 } d_u;
80847 struct list_head d_subdirs; /* our children */
80848 struct hlist_node d_alias; /* inode alias list */
80849-};
80850+} __randomize_layout;
80851
80852 /*
80853 * dentry->d_lock spinlock nesting subclasses:
80854diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
80855index 7925bf0..d5143d2 100644
80856--- a/include/linux/decompress/mm.h
80857+++ b/include/linux/decompress/mm.h
80858@@ -77,7 +77,7 @@ static void free(void *where)
80859 * warnings when not needed (indeed large_malloc / large_free are not
80860 * needed by inflate */
80861
80862-#define malloc(a) kmalloc(a, GFP_KERNEL)
80863+#define malloc(a) kmalloc((a), GFP_KERNEL)
80864 #define free(a) kfree(a)
80865
80866 #define large_malloc(a) vmalloc(a)
80867diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
80868index f1863dc..5c26074 100644
80869--- a/include/linux/devfreq.h
80870+++ b/include/linux/devfreq.h
80871@@ -114,7 +114,7 @@ struct devfreq_governor {
80872 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
80873 int (*event_handler)(struct devfreq *devfreq,
80874 unsigned int event, void *data);
80875-};
80876+} __do_const;
80877
80878 /**
80879 * struct devfreq - Device devfreq structure
80880diff --git a/include/linux/device.h b/include/linux/device.h
80881index 43d183a..03b6ba2 100644
80882--- a/include/linux/device.h
80883+++ b/include/linux/device.h
80884@@ -310,7 +310,7 @@ struct subsys_interface {
80885 struct list_head node;
80886 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
80887 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
80888-};
80889+} __do_const;
80890
80891 int subsys_interface_register(struct subsys_interface *sif);
80892 void subsys_interface_unregister(struct subsys_interface *sif);
80893@@ -506,7 +506,7 @@ struct device_type {
80894 void (*release)(struct device *dev);
80895
80896 const struct dev_pm_ops *pm;
80897-};
80898+} __do_const;
80899
80900 /* interface for exporting device attributes */
80901 struct device_attribute {
80902@@ -516,11 +516,12 @@ struct device_attribute {
80903 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
80904 const char *buf, size_t count);
80905 };
80906+typedef struct device_attribute __no_const device_attribute_no_const;
80907
80908 struct dev_ext_attribute {
80909 struct device_attribute attr;
80910 void *var;
80911-};
80912+} __do_const;
80913
80914 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
80915 char *buf);
80916diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
80917index 931b709..89b2d89 100644
80918--- a/include/linux/dma-mapping.h
80919+++ b/include/linux/dma-mapping.h
80920@@ -60,7 +60,7 @@ struct dma_map_ops {
80921 u64 (*get_required_mask)(struct device *dev);
80922 #endif
80923 int is_phys;
80924-};
80925+} __do_const;
80926
80927 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
80928
80929diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
80930index 1f9e642..39e4263 100644
80931--- a/include/linux/dmaengine.h
80932+++ b/include/linux/dmaengine.h
80933@@ -1147,9 +1147,9 @@ struct dma_pinned_list {
80934 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
80935 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
80936
80937-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
80938+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
80939 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
80940-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
80941+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
80942 struct dma_pinned_list *pinned_list, struct page *page,
80943 unsigned int offset, size_t len);
80944
80945diff --git a/include/linux/efi.h b/include/linux/efi.h
80946index 45cb4ff..c9b4912 100644
80947--- a/include/linux/efi.h
80948+++ b/include/linux/efi.h
80949@@ -1036,6 +1036,7 @@ struct efivar_operations {
80950 efi_set_variable_t *set_variable;
80951 efi_query_variable_store_t *query_variable_store;
80952 };
80953+typedef struct efivar_operations __no_const efivar_operations_no_const;
80954
80955 struct efivars {
80956 /*
80957diff --git a/include/linux/elf.h b/include/linux/elf.h
80958index 67a5fa7..b817372 100644
80959--- a/include/linux/elf.h
80960+++ b/include/linux/elf.h
80961@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
80962 #define elf_note elf32_note
80963 #define elf_addr_t Elf32_Off
80964 #define Elf_Half Elf32_Half
80965+#define elf_dyn Elf32_Dyn
80966
80967 #else
80968
80969@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
80970 #define elf_note elf64_note
80971 #define elf_addr_t Elf64_Off
80972 #define Elf_Half Elf64_Half
80973+#define elf_dyn Elf64_Dyn
80974
80975 #endif
80976
80977diff --git a/include/linux/err.h b/include/linux/err.h
80978index a729120..6ede2c9 100644
80979--- a/include/linux/err.h
80980+++ b/include/linux/err.h
80981@@ -20,12 +20,12 @@
80982
80983 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
80984
80985-static inline void * __must_check ERR_PTR(long error)
80986+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
80987 {
80988 return (void *) error;
80989 }
80990
80991-static inline long __must_check PTR_ERR(__force const void *ptr)
80992+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
80993 {
80994 return (long) ptr;
80995 }
80996diff --git a/include/linux/extcon.h b/include/linux/extcon.h
80997index 36f49c4..a2a1f4c 100644
80998--- a/include/linux/extcon.h
80999+++ b/include/linux/extcon.h
81000@@ -135,7 +135,7 @@ struct extcon_dev {
81001 /* /sys/class/extcon/.../mutually_exclusive/... */
81002 struct attribute_group attr_g_muex;
81003 struct attribute **attrs_muex;
81004- struct device_attribute *d_attrs_muex;
81005+ device_attribute_no_const *d_attrs_muex;
81006 };
81007
81008 /**
81009diff --git a/include/linux/fb.h b/include/linux/fb.h
81010index 09bb7a1..d98870a 100644
81011--- a/include/linux/fb.h
81012+++ b/include/linux/fb.h
81013@@ -305,7 +305,7 @@ struct fb_ops {
81014 /* called at KDB enter and leave time to prepare the console */
81015 int (*fb_debug_enter)(struct fb_info *info);
81016 int (*fb_debug_leave)(struct fb_info *info);
81017-};
81018+} __do_const;
81019
81020 #ifdef CONFIG_FB_TILEBLITTING
81021 #define FB_TILE_CURSOR_NONE 0
81022diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
81023index 230f87b..1fd0485 100644
81024--- a/include/linux/fdtable.h
81025+++ b/include/linux/fdtable.h
81026@@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
81027 void put_files_struct(struct files_struct *fs);
81028 void reset_files_struct(struct files_struct *);
81029 int unshare_files(struct files_struct **);
81030-struct files_struct *dup_fd(struct files_struct *, int *);
81031+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
81032 void do_close_on_exec(struct files_struct *);
81033 int iterate_fd(struct files_struct *, unsigned,
81034 int (*)(const void *, struct file *, unsigned),
81035diff --git a/include/linux/filter.h b/include/linux/filter.h
81036index a5227ab..c789945 100644
81037--- a/include/linux/filter.h
81038+++ b/include/linux/filter.h
81039@@ -9,6 +9,11 @@
81040 #include <linux/skbuff.h>
81041 #include <linux/workqueue.h>
81042 #include <uapi/linux/filter.h>
81043+#include <asm/cacheflush.h>
81044+
81045+struct sk_buff;
81046+struct sock;
81047+struct seccomp_data;
81048
81049 /* Internally used and optimized filter representation with extended
81050 * instruction set based on top of classic BPF.
81051@@ -320,20 +325,23 @@ struct sock_fprog_kern {
81052 struct sock_filter *filter;
81053 };
81054
81055-struct sk_buff;
81056-struct sock;
81057-struct seccomp_data;
81058+struct bpf_work_struct {
81059+ struct bpf_prog *prog;
81060+ struct work_struct work;
81061+};
81062
81063 struct bpf_prog {
81064+ u32 pages; /* Number of allocated pages */
81065 u32 jited:1, /* Is our filter JIT'ed? */
81066 len:31; /* Number of filter blocks */
81067 struct sock_fprog_kern *orig_prog; /* Original BPF program */
81068+ struct bpf_work_struct *work; /* Deferred free work struct */
81069 unsigned int (*bpf_func)(const struct sk_buff *skb,
81070 const struct bpf_insn *filter);
81071+ /* Instructions for interpreter */
81072 union {
81073 struct sock_filter insns[0];
81074 struct bpf_insn insnsi[0];
81075- struct work_struct work;
81076 };
81077 };
81078
81079@@ -353,6 +361,26 @@ static inline unsigned int bpf_prog_size(unsigned int proglen)
81080
81081 #define bpf_classic_proglen(fprog) (fprog->len * sizeof(fprog->filter[0]))
81082
81083+#ifdef CONFIG_DEBUG_SET_MODULE_RONX
81084+static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
81085+{
81086+ set_memory_ro((unsigned long)fp, fp->pages);
81087+}
81088+
81089+static inline void bpf_prog_unlock_ro(struct bpf_prog *fp)
81090+{
81091+ set_memory_rw((unsigned long)fp, fp->pages);
81092+}
81093+#else
81094+static inline void bpf_prog_lock_ro(struct bpf_prog *fp)
81095+{
81096+}
81097+
81098+static inline void bpf_prog_unlock_ro(struct bpf_prog *fp)
81099+{
81100+}
81101+#endif /* CONFIG_DEBUG_SET_MODULE_RONX */
81102+
81103 int sk_filter(struct sock *sk, struct sk_buff *skb);
81104
81105 void bpf_prog_select_runtime(struct bpf_prog *fp);
81106@@ -361,6 +389,17 @@ void bpf_prog_free(struct bpf_prog *fp);
81107 int bpf_convert_filter(struct sock_filter *prog, int len,
81108 struct bpf_insn *new_prog, int *new_len);
81109
81110+struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags);
81111+struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
81112+ gfp_t gfp_extra_flags);
81113+void __bpf_prog_free(struct bpf_prog *fp);
81114+
81115+static inline void bpf_prog_unlock_free(struct bpf_prog *fp)
81116+{
81117+ bpf_prog_unlock_ro(fp);
81118+ __bpf_prog_free(fp);
81119+}
81120+
81121 int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog);
81122 void bpf_prog_destroy(struct bpf_prog *fp);
81123
81124@@ -450,7 +489,7 @@ static inline void bpf_jit_compile(struct bpf_prog *fp)
81125
81126 static inline void bpf_jit_free(struct bpf_prog *fp)
81127 {
81128- kfree(fp);
81129+ bpf_prog_unlock_free(fp);
81130 }
81131 #endif /* CONFIG_BPF_JIT */
81132
81133diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
81134index 8293262..2b3b8bd 100644
81135--- a/include/linux/frontswap.h
81136+++ b/include/linux/frontswap.h
81137@@ -11,7 +11,7 @@ struct frontswap_ops {
81138 int (*load)(unsigned, pgoff_t, struct page *);
81139 void (*invalidate_page)(unsigned, pgoff_t);
81140 void (*invalidate_area)(unsigned);
81141-};
81142+} __no_const;
81143
81144 extern bool frontswap_enabled;
81145 extern struct frontswap_ops *
81146diff --git a/include/linux/fs.h b/include/linux/fs.h
81147index 9418772..0155807 100644
81148--- a/include/linux/fs.h
81149+++ b/include/linux/fs.h
81150@@ -401,7 +401,7 @@ struct address_space {
81151 spinlock_t private_lock; /* for use by the address_space */
81152 struct list_head private_list; /* ditto */
81153 void *private_data; /* ditto */
81154-} __attribute__((aligned(sizeof(long))));
81155+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
81156 /*
81157 * On most architectures that alignment is already the case; but
81158 * must be enforced here for CRIS, to let the least significant bit
81159@@ -444,7 +444,7 @@ struct block_device {
81160 int bd_fsfreeze_count;
81161 /* Mutex for freeze */
81162 struct mutex bd_fsfreeze_mutex;
81163-};
81164+} __randomize_layout;
81165
81166 /*
81167 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
81168@@ -613,7 +613,7 @@ struct inode {
81169 #endif
81170
81171 void *i_private; /* fs or device private pointer */
81172-};
81173+} __randomize_layout;
81174
81175 static inline int inode_unhashed(struct inode *inode)
81176 {
81177@@ -806,7 +806,7 @@ struct file {
81178 struct list_head f_tfile_llink;
81179 #endif /* #ifdef CONFIG_EPOLL */
81180 struct address_space *f_mapping;
81181-} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
81182+} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
81183
81184 struct file_handle {
81185 __u32 handle_bytes;
81186@@ -934,7 +934,7 @@ struct file_lock {
81187 int state; /* state of grant or error if -ve */
81188 } afs;
81189 } fl_u;
81190-};
81191+} __randomize_layout;
81192
81193 /* The following constant reflects the upper bound of the file/locking space */
81194 #ifndef OFFSET_MAX
81195@@ -1284,7 +1284,7 @@ struct super_block {
81196 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
81197 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
81198 struct rcu_head rcu;
81199-};
81200+} __randomize_layout;
81201
81202 extern struct timespec current_fs_time(struct super_block *sb);
81203
81204@@ -1510,7 +1510,8 @@ struct file_operations {
81205 long (*fallocate)(struct file *file, int mode, loff_t offset,
81206 loff_t len);
81207 int (*show_fdinfo)(struct seq_file *m, struct file *f);
81208-};
81209+} __do_const __randomize_layout;
81210+typedef struct file_operations __no_const file_operations_no_const;
81211
81212 struct inode_operations {
81213 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
81214@@ -2796,4 +2797,14 @@ static inline bool dir_relax(struct inode *inode)
81215 return !IS_DEADDIR(inode);
81216 }
81217
81218+static inline bool is_sidechannel_device(const struct inode *inode)
81219+{
81220+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
81221+ umode_t mode = inode->i_mode;
81222+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
81223+#else
81224+ return false;
81225+#endif
81226+}
81227+
81228 #endif /* _LINUX_FS_H */
81229diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
81230index 0efc3e6..fd23610 100644
81231--- a/include/linux/fs_struct.h
81232+++ b/include/linux/fs_struct.h
81233@@ -6,13 +6,13 @@
81234 #include <linux/seqlock.h>
81235
81236 struct fs_struct {
81237- int users;
81238+ atomic_t users;
81239 spinlock_t lock;
81240 seqcount_t seq;
81241 int umask;
81242 int in_exec;
81243 struct path root, pwd;
81244-};
81245+} __randomize_layout;
81246
81247 extern struct kmem_cache *fs_cachep;
81248
81249diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
81250index 7714849..a4a5c7a 100644
81251--- a/include/linux/fscache-cache.h
81252+++ b/include/linux/fscache-cache.h
81253@@ -113,7 +113,7 @@ struct fscache_operation {
81254 fscache_operation_release_t release;
81255 };
81256
81257-extern atomic_t fscache_op_debug_id;
81258+extern atomic_unchecked_t fscache_op_debug_id;
81259 extern void fscache_op_work_func(struct work_struct *work);
81260
81261 extern void fscache_enqueue_operation(struct fscache_operation *);
81262@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
81263 INIT_WORK(&op->work, fscache_op_work_func);
81264 atomic_set(&op->usage, 1);
81265 op->state = FSCACHE_OP_ST_INITIALISED;
81266- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
81267+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
81268 op->processor = processor;
81269 op->release = release;
81270 INIT_LIST_HEAD(&op->pend_link);
81271diff --git a/include/linux/fscache.h b/include/linux/fscache.h
81272index 115bb81..e7b812b 100644
81273--- a/include/linux/fscache.h
81274+++ b/include/linux/fscache.h
81275@@ -152,7 +152,7 @@ struct fscache_cookie_def {
81276 * - this is mandatory for any object that may have data
81277 */
81278 void (*now_uncached)(void *cookie_netfs_data);
81279-};
81280+} __do_const;
81281
81282 /*
81283 * fscache cached network filesystem type
81284diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
81285index 1c804b0..1432c2b 100644
81286--- a/include/linux/fsnotify.h
81287+++ b/include/linux/fsnotify.h
81288@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
81289 struct inode *inode = file_inode(file);
81290 __u32 mask = FS_ACCESS;
81291
81292+ if (is_sidechannel_device(inode))
81293+ return;
81294+
81295 if (S_ISDIR(inode->i_mode))
81296 mask |= FS_ISDIR;
81297
81298@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
81299 struct inode *inode = file_inode(file);
81300 __u32 mask = FS_MODIFY;
81301
81302+ if (is_sidechannel_device(inode))
81303+ return;
81304+
81305 if (S_ISDIR(inode->i_mode))
81306 mask |= FS_ISDIR;
81307
81308@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
81309 */
81310 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
81311 {
81312- return kstrdup(name, GFP_KERNEL);
81313+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
81314 }
81315
81316 /*
81317diff --git a/include/linux/genhd.h b/include/linux/genhd.h
81318index ec274e0..e678159 100644
81319--- a/include/linux/genhd.h
81320+++ b/include/linux/genhd.h
81321@@ -194,7 +194,7 @@ struct gendisk {
81322 struct kobject *slave_dir;
81323
81324 struct timer_rand_state *random;
81325- atomic_t sync_io; /* RAID */
81326+ atomic_unchecked_t sync_io; /* RAID */
81327 struct disk_events *ev;
81328 #ifdef CONFIG_BLK_DEV_INTEGRITY
81329 struct blk_integrity *integrity;
81330@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
81331 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
81332
81333 /* drivers/char/random.c */
81334-extern void add_disk_randomness(struct gendisk *disk);
81335+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
81336 extern void rand_initialize_disk(struct gendisk *disk);
81337
81338 static inline sector_t get_start_sect(struct block_device *bdev)
81339diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
81340index c0894dd..2fbf10c 100644
81341--- a/include/linux/genl_magic_func.h
81342+++ b/include/linux/genl_magic_func.h
81343@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
81344 },
81345
81346 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
81347-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
81348+static struct genl_ops ZZZ_genl_ops[] = {
81349 #include GENL_MAGIC_INCLUDE_FILE
81350 };
81351
81352diff --git a/include/linux/gfp.h b/include/linux/gfp.h
81353index 5e7219d..b1ed627 100644
81354--- a/include/linux/gfp.h
81355+++ b/include/linux/gfp.h
81356@@ -34,6 +34,13 @@ struct vm_area_struct;
81357 #define ___GFP_NO_KSWAPD 0x400000u
81358 #define ___GFP_OTHER_NODE 0x800000u
81359 #define ___GFP_WRITE 0x1000000u
81360+
81361+#ifdef CONFIG_PAX_USERCOPY_SLABS
81362+#define ___GFP_USERCOPY 0x2000000u
81363+#else
81364+#define ___GFP_USERCOPY 0
81365+#endif
81366+
81367 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
81368
81369 /*
81370@@ -90,6 +97,7 @@ struct vm_area_struct;
81371 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
81372 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
81373 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
81374+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
81375
81376 /*
81377 * This may seem redundant, but it's a way of annotating false positives vs.
81378@@ -97,7 +105,7 @@ struct vm_area_struct;
81379 */
81380 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
81381
81382-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
81383+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
81384 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
81385
81386 /* This equals 0, but use constants in case they ever change */
81387@@ -155,6 +163,8 @@ struct vm_area_struct;
81388 /* 4GB DMA on some platforms */
81389 #define GFP_DMA32 __GFP_DMA32
81390
81391+#define GFP_USERCOPY __GFP_USERCOPY
81392+
81393 /* Convert GFP flags to their corresponding migrate type */
81394 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
81395 {
81396diff --git a/include/linux/gracl.h b/include/linux/gracl.h
81397new file mode 100644
81398index 0000000..edb2cb6
81399--- /dev/null
81400+++ b/include/linux/gracl.h
81401@@ -0,0 +1,340 @@
81402+#ifndef GR_ACL_H
81403+#define GR_ACL_H
81404+
81405+#include <linux/grdefs.h>
81406+#include <linux/resource.h>
81407+#include <linux/capability.h>
81408+#include <linux/dcache.h>
81409+#include <asm/resource.h>
81410+
81411+/* Major status information */
81412+
81413+#define GR_VERSION "grsecurity 3.0"
81414+#define GRSECURITY_VERSION 0x3000
81415+
81416+enum {
81417+ GR_SHUTDOWN = 0,
81418+ GR_ENABLE = 1,
81419+ GR_SPROLE = 2,
81420+ GR_OLDRELOAD = 3,
81421+ GR_SEGVMOD = 4,
81422+ GR_STATUS = 5,
81423+ GR_UNSPROLE = 6,
81424+ GR_PASSSET = 7,
81425+ GR_SPROLEPAM = 8,
81426+ GR_RELOAD = 9,
81427+};
81428+
81429+/* Password setup definitions
81430+ * kernel/grhash.c */
81431+enum {
81432+ GR_PW_LEN = 128,
81433+ GR_SALT_LEN = 16,
81434+ GR_SHA_LEN = 32,
81435+};
81436+
81437+enum {
81438+ GR_SPROLE_LEN = 64,
81439+};
81440+
81441+enum {
81442+ GR_NO_GLOB = 0,
81443+ GR_REG_GLOB,
81444+ GR_CREATE_GLOB
81445+};
81446+
81447+#define GR_NLIMITS 32
81448+
81449+/* Begin Data Structures */
81450+
81451+struct sprole_pw {
81452+ unsigned char *rolename;
81453+ unsigned char salt[GR_SALT_LEN];
81454+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
81455+};
81456+
81457+struct name_entry {
81458+ __u32 key;
81459+ ino_t inode;
81460+ dev_t device;
81461+ char *name;
81462+ __u16 len;
81463+ __u8 deleted;
81464+ struct name_entry *prev;
81465+ struct name_entry *next;
81466+};
81467+
81468+struct inodev_entry {
81469+ struct name_entry *nentry;
81470+ struct inodev_entry *prev;
81471+ struct inodev_entry *next;
81472+};
81473+
81474+struct acl_role_db {
81475+ struct acl_role_label **r_hash;
81476+ __u32 r_size;
81477+};
81478+
81479+struct inodev_db {
81480+ struct inodev_entry **i_hash;
81481+ __u32 i_size;
81482+};
81483+
81484+struct name_db {
81485+ struct name_entry **n_hash;
81486+ __u32 n_size;
81487+};
81488+
81489+struct crash_uid {
81490+ uid_t uid;
81491+ unsigned long expires;
81492+};
81493+
81494+struct gr_hash_struct {
81495+ void **table;
81496+ void **nametable;
81497+ void *first;
81498+ __u32 table_size;
81499+ __u32 used_size;
81500+ int type;
81501+};
81502+
81503+/* Userspace Grsecurity ACL data structures */
81504+
81505+struct acl_subject_label {
81506+ char *filename;
81507+ ino_t inode;
81508+ dev_t device;
81509+ __u32 mode;
81510+ kernel_cap_t cap_mask;
81511+ kernel_cap_t cap_lower;
81512+ kernel_cap_t cap_invert_audit;
81513+
81514+ struct rlimit res[GR_NLIMITS];
81515+ __u32 resmask;
81516+
81517+ __u8 user_trans_type;
81518+ __u8 group_trans_type;
81519+ uid_t *user_transitions;
81520+ gid_t *group_transitions;
81521+ __u16 user_trans_num;
81522+ __u16 group_trans_num;
81523+
81524+ __u32 sock_families[2];
81525+ __u32 ip_proto[8];
81526+ __u32 ip_type;
81527+ struct acl_ip_label **ips;
81528+ __u32 ip_num;
81529+ __u32 inaddr_any_override;
81530+
81531+ __u32 crashes;
81532+ unsigned long expires;
81533+
81534+ struct acl_subject_label *parent_subject;
81535+ struct gr_hash_struct *hash;
81536+ struct acl_subject_label *prev;
81537+ struct acl_subject_label *next;
81538+
81539+ struct acl_object_label **obj_hash;
81540+ __u32 obj_hash_size;
81541+ __u16 pax_flags;
81542+};
81543+
81544+struct role_allowed_ip {
81545+ __u32 addr;
81546+ __u32 netmask;
81547+
81548+ struct role_allowed_ip *prev;
81549+ struct role_allowed_ip *next;
81550+};
81551+
81552+struct role_transition {
81553+ char *rolename;
81554+
81555+ struct role_transition *prev;
81556+ struct role_transition *next;
81557+};
81558+
81559+struct acl_role_label {
81560+ char *rolename;
81561+ uid_t uidgid;
81562+ __u16 roletype;
81563+
81564+ __u16 auth_attempts;
81565+ unsigned long expires;
81566+
81567+ struct acl_subject_label *root_label;
81568+ struct gr_hash_struct *hash;
81569+
81570+ struct acl_role_label *prev;
81571+ struct acl_role_label *next;
81572+
81573+ struct role_transition *transitions;
81574+ struct role_allowed_ip *allowed_ips;
81575+ uid_t *domain_children;
81576+ __u16 domain_child_num;
81577+
81578+ umode_t umask;
81579+
81580+ struct acl_subject_label **subj_hash;
81581+ __u32 subj_hash_size;
81582+};
81583+
81584+struct user_acl_role_db {
81585+ struct acl_role_label **r_table;
81586+ __u32 num_pointers; /* Number of allocations to track */
81587+ __u32 num_roles; /* Number of roles */
81588+ __u32 num_domain_children; /* Number of domain children */
81589+ __u32 num_subjects; /* Number of subjects */
81590+ __u32 num_objects; /* Number of objects */
81591+};
81592+
81593+struct acl_object_label {
81594+ char *filename;
81595+ ino_t inode;
81596+ dev_t device;
81597+ __u32 mode;
81598+
81599+ struct acl_subject_label *nested;
81600+ struct acl_object_label *globbed;
81601+
81602+ /* next two structures not used */
81603+
81604+ struct acl_object_label *prev;
81605+ struct acl_object_label *next;
81606+};
81607+
81608+struct acl_ip_label {
81609+ char *iface;
81610+ __u32 addr;
81611+ __u32 netmask;
81612+ __u16 low, high;
81613+ __u8 mode;
81614+ __u32 type;
81615+ __u32 proto[8];
81616+
81617+ /* next two structures not used */
81618+
81619+ struct acl_ip_label *prev;
81620+ struct acl_ip_label *next;
81621+};
81622+
81623+struct gr_arg {
81624+ struct user_acl_role_db role_db;
81625+ unsigned char pw[GR_PW_LEN];
81626+ unsigned char salt[GR_SALT_LEN];
81627+ unsigned char sum[GR_SHA_LEN];
81628+ unsigned char sp_role[GR_SPROLE_LEN];
81629+ struct sprole_pw *sprole_pws;
81630+ dev_t segv_device;
81631+ ino_t segv_inode;
81632+ uid_t segv_uid;
81633+ __u16 num_sprole_pws;
81634+ __u16 mode;
81635+};
81636+
81637+struct gr_arg_wrapper {
81638+ struct gr_arg *arg;
81639+ __u32 version;
81640+ __u32 size;
81641+};
81642+
81643+struct subject_map {
81644+ struct acl_subject_label *user;
81645+ struct acl_subject_label *kernel;
81646+ struct subject_map *prev;
81647+ struct subject_map *next;
81648+};
81649+
81650+struct acl_subj_map_db {
81651+ struct subject_map **s_hash;
81652+ __u32 s_size;
81653+};
81654+
81655+struct gr_policy_state {
81656+ struct sprole_pw **acl_special_roles;
81657+ __u16 num_sprole_pws;
81658+ struct acl_role_label *kernel_role;
81659+ struct acl_role_label *role_list;
81660+ struct acl_role_label *default_role;
81661+ struct acl_role_db acl_role_set;
81662+ struct acl_subj_map_db subj_map_set;
81663+ struct name_db name_set;
81664+ struct inodev_db inodev_set;
81665+};
81666+
81667+struct gr_alloc_state {
81668+ unsigned long alloc_stack_next;
81669+ unsigned long alloc_stack_size;
81670+ void **alloc_stack;
81671+};
81672+
81673+struct gr_reload_state {
81674+ struct gr_policy_state oldpolicy;
81675+ struct gr_alloc_state oldalloc;
81676+ struct gr_policy_state newpolicy;
81677+ struct gr_alloc_state newalloc;
81678+ struct gr_policy_state *oldpolicy_ptr;
81679+ struct gr_alloc_state *oldalloc_ptr;
81680+ unsigned char oldmode;
81681+};
81682+
81683+/* End Data Structures Section */
81684+
81685+/* Hash functions generated by empirical testing by Brad Spengler
81686+ Makes good use of the low bits of the inode. Generally 0-1 times
81687+ in loop for successful match. 0-3 for unsuccessful match.
81688+ Shift/add algorithm with modulus of table size and an XOR*/
81689+
81690+static __inline__ unsigned int
81691+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
81692+{
81693+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
81694+}
81695+
81696+ static __inline__ unsigned int
81697+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
81698+{
81699+ return ((const unsigned long)userp % sz);
81700+}
81701+
81702+static __inline__ unsigned int
81703+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
81704+{
81705+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
81706+}
81707+
81708+static __inline__ unsigned int
81709+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
81710+{
81711+ return full_name_hash((const unsigned char *)name, len) % sz;
81712+}
81713+
81714+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
81715+ subj = NULL; \
81716+ iter = 0; \
81717+ while (iter < role->subj_hash_size) { \
81718+ if (subj == NULL) \
81719+ subj = role->subj_hash[iter]; \
81720+ if (subj == NULL) { \
81721+ iter++; \
81722+ continue; \
81723+ }
81724+
81725+#define FOR_EACH_SUBJECT_END(subj,iter) \
81726+ subj = subj->next; \
81727+ if (subj == NULL) \
81728+ iter++; \
81729+ }
81730+
81731+
81732+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
81733+ subj = role->hash->first; \
81734+ while (subj != NULL) {
81735+
81736+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
81737+ subj = subj->next; \
81738+ }
81739+
81740+#endif
81741+
81742diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
81743new file mode 100644
81744index 0000000..33ebd1f
81745--- /dev/null
81746+++ b/include/linux/gracl_compat.h
81747@@ -0,0 +1,156 @@
81748+#ifndef GR_ACL_COMPAT_H
81749+#define GR_ACL_COMPAT_H
81750+
81751+#include <linux/resource.h>
81752+#include <asm/resource.h>
81753+
81754+struct sprole_pw_compat {
81755+ compat_uptr_t rolename;
81756+ unsigned char salt[GR_SALT_LEN];
81757+ unsigned char sum[GR_SHA_LEN];
81758+};
81759+
81760+struct gr_hash_struct_compat {
81761+ compat_uptr_t table;
81762+ compat_uptr_t nametable;
81763+ compat_uptr_t first;
81764+ __u32 table_size;
81765+ __u32 used_size;
81766+ int type;
81767+};
81768+
81769+struct acl_subject_label_compat {
81770+ compat_uptr_t filename;
81771+ compat_ino_t inode;
81772+ __u32 device;
81773+ __u32 mode;
81774+ kernel_cap_t cap_mask;
81775+ kernel_cap_t cap_lower;
81776+ kernel_cap_t cap_invert_audit;
81777+
81778+ struct compat_rlimit res[GR_NLIMITS];
81779+ __u32 resmask;
81780+
81781+ __u8 user_trans_type;
81782+ __u8 group_trans_type;
81783+ compat_uptr_t user_transitions;
81784+ compat_uptr_t group_transitions;
81785+ __u16 user_trans_num;
81786+ __u16 group_trans_num;
81787+
81788+ __u32 sock_families[2];
81789+ __u32 ip_proto[8];
81790+ __u32 ip_type;
81791+ compat_uptr_t ips;
81792+ __u32 ip_num;
81793+ __u32 inaddr_any_override;
81794+
81795+ __u32 crashes;
81796+ compat_ulong_t expires;
81797+
81798+ compat_uptr_t parent_subject;
81799+ compat_uptr_t hash;
81800+ compat_uptr_t prev;
81801+ compat_uptr_t next;
81802+
81803+ compat_uptr_t obj_hash;
81804+ __u32 obj_hash_size;
81805+ __u16 pax_flags;
81806+};
81807+
81808+struct role_allowed_ip_compat {
81809+ __u32 addr;
81810+ __u32 netmask;
81811+
81812+ compat_uptr_t prev;
81813+ compat_uptr_t next;
81814+};
81815+
81816+struct role_transition_compat {
81817+ compat_uptr_t rolename;
81818+
81819+ compat_uptr_t prev;
81820+ compat_uptr_t next;
81821+};
81822+
81823+struct acl_role_label_compat {
81824+ compat_uptr_t rolename;
81825+ uid_t uidgid;
81826+ __u16 roletype;
81827+
81828+ __u16 auth_attempts;
81829+ compat_ulong_t expires;
81830+
81831+ compat_uptr_t root_label;
81832+ compat_uptr_t hash;
81833+
81834+ compat_uptr_t prev;
81835+ compat_uptr_t next;
81836+
81837+ compat_uptr_t transitions;
81838+ compat_uptr_t allowed_ips;
81839+ compat_uptr_t domain_children;
81840+ __u16 domain_child_num;
81841+
81842+ umode_t umask;
81843+
81844+ compat_uptr_t subj_hash;
81845+ __u32 subj_hash_size;
81846+};
81847+
81848+struct user_acl_role_db_compat {
81849+ compat_uptr_t r_table;
81850+ __u32 num_pointers;
81851+ __u32 num_roles;
81852+ __u32 num_domain_children;
81853+ __u32 num_subjects;
81854+ __u32 num_objects;
81855+};
81856+
81857+struct acl_object_label_compat {
81858+ compat_uptr_t filename;
81859+ compat_ino_t inode;
81860+ __u32 device;
81861+ __u32 mode;
81862+
81863+ compat_uptr_t nested;
81864+ compat_uptr_t globbed;
81865+
81866+ compat_uptr_t prev;
81867+ compat_uptr_t next;
81868+};
81869+
81870+struct acl_ip_label_compat {
81871+ compat_uptr_t iface;
81872+ __u32 addr;
81873+ __u32 netmask;
81874+ __u16 low, high;
81875+ __u8 mode;
81876+ __u32 type;
81877+ __u32 proto[8];
81878+
81879+ compat_uptr_t prev;
81880+ compat_uptr_t next;
81881+};
81882+
81883+struct gr_arg_compat {
81884+ struct user_acl_role_db_compat role_db;
81885+ unsigned char pw[GR_PW_LEN];
81886+ unsigned char salt[GR_SALT_LEN];
81887+ unsigned char sum[GR_SHA_LEN];
81888+ unsigned char sp_role[GR_SPROLE_LEN];
81889+ compat_uptr_t sprole_pws;
81890+ __u32 segv_device;
81891+ compat_ino_t segv_inode;
81892+ uid_t segv_uid;
81893+ __u16 num_sprole_pws;
81894+ __u16 mode;
81895+};
81896+
81897+struct gr_arg_wrapper_compat {
81898+ compat_uptr_t arg;
81899+ __u32 version;
81900+ __u32 size;
81901+};
81902+
81903+#endif
81904diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
81905new file mode 100644
81906index 0000000..323ecf2
81907--- /dev/null
81908+++ b/include/linux/gralloc.h
81909@@ -0,0 +1,9 @@
81910+#ifndef __GRALLOC_H
81911+#define __GRALLOC_H
81912+
81913+void acl_free_all(void);
81914+int acl_alloc_stack_init(unsigned long size);
81915+void *acl_alloc(unsigned long len);
81916+void *acl_alloc_num(unsigned long num, unsigned long len);
81917+
81918+#endif
81919diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
81920new file mode 100644
81921index 0000000..be66033
81922--- /dev/null
81923+++ b/include/linux/grdefs.h
81924@@ -0,0 +1,140 @@
81925+#ifndef GRDEFS_H
81926+#define GRDEFS_H
81927+
81928+/* Begin grsecurity status declarations */
81929+
81930+enum {
81931+ GR_READY = 0x01,
81932+ GR_STATUS_INIT = 0x00 // disabled state
81933+};
81934+
81935+/* Begin ACL declarations */
81936+
81937+/* Role flags */
81938+
81939+enum {
81940+ GR_ROLE_USER = 0x0001,
81941+ GR_ROLE_GROUP = 0x0002,
81942+ GR_ROLE_DEFAULT = 0x0004,
81943+ GR_ROLE_SPECIAL = 0x0008,
81944+ GR_ROLE_AUTH = 0x0010,
81945+ GR_ROLE_NOPW = 0x0020,
81946+ GR_ROLE_GOD = 0x0040,
81947+ GR_ROLE_LEARN = 0x0080,
81948+ GR_ROLE_TPE = 0x0100,
81949+ GR_ROLE_DOMAIN = 0x0200,
81950+ GR_ROLE_PAM = 0x0400,
81951+ GR_ROLE_PERSIST = 0x0800
81952+};
81953+
81954+/* ACL Subject and Object mode flags */
81955+enum {
81956+ GR_DELETED = 0x80000000
81957+};
81958+
81959+/* ACL Object-only mode flags */
81960+enum {
81961+ GR_READ = 0x00000001,
81962+ GR_APPEND = 0x00000002,
81963+ GR_WRITE = 0x00000004,
81964+ GR_EXEC = 0x00000008,
81965+ GR_FIND = 0x00000010,
81966+ GR_INHERIT = 0x00000020,
81967+ GR_SETID = 0x00000040,
81968+ GR_CREATE = 0x00000080,
81969+ GR_DELETE = 0x00000100,
81970+ GR_LINK = 0x00000200,
81971+ GR_AUDIT_READ = 0x00000400,
81972+ GR_AUDIT_APPEND = 0x00000800,
81973+ GR_AUDIT_WRITE = 0x00001000,
81974+ GR_AUDIT_EXEC = 0x00002000,
81975+ GR_AUDIT_FIND = 0x00004000,
81976+ GR_AUDIT_INHERIT= 0x00008000,
81977+ GR_AUDIT_SETID = 0x00010000,
81978+ GR_AUDIT_CREATE = 0x00020000,
81979+ GR_AUDIT_DELETE = 0x00040000,
81980+ GR_AUDIT_LINK = 0x00080000,
81981+ GR_PTRACERD = 0x00100000,
81982+ GR_NOPTRACE = 0x00200000,
81983+ GR_SUPPRESS = 0x00400000,
81984+ GR_NOLEARN = 0x00800000,
81985+ GR_INIT_TRANSFER= 0x01000000
81986+};
81987+
81988+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
81989+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
81990+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
81991+
81992+/* ACL subject-only mode flags */
81993+enum {
81994+ GR_KILL = 0x00000001,
81995+ GR_VIEW = 0x00000002,
81996+ GR_PROTECTED = 0x00000004,
81997+ GR_LEARN = 0x00000008,
81998+ GR_OVERRIDE = 0x00000010,
81999+ /* just a placeholder, this mode is only used in userspace */
82000+ GR_DUMMY = 0x00000020,
82001+ GR_PROTSHM = 0x00000040,
82002+ GR_KILLPROC = 0x00000080,
82003+ GR_KILLIPPROC = 0x00000100,
82004+ /* just a placeholder, this mode is only used in userspace */
82005+ GR_NOTROJAN = 0x00000200,
82006+ GR_PROTPROCFD = 0x00000400,
82007+ GR_PROCACCT = 0x00000800,
82008+ GR_RELAXPTRACE = 0x00001000,
82009+ //GR_NESTED = 0x00002000,
82010+ GR_INHERITLEARN = 0x00004000,
82011+ GR_PROCFIND = 0x00008000,
82012+ GR_POVERRIDE = 0x00010000,
82013+ GR_KERNELAUTH = 0x00020000,
82014+ GR_ATSECURE = 0x00040000,
82015+ GR_SHMEXEC = 0x00080000
82016+};
82017+
82018+enum {
82019+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
82020+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
82021+ GR_PAX_ENABLE_MPROTECT = 0x0004,
82022+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
82023+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
82024+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
82025+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
82026+ GR_PAX_DISABLE_MPROTECT = 0x0400,
82027+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
82028+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
82029+};
82030+
82031+enum {
82032+ GR_ID_USER = 0x01,
82033+ GR_ID_GROUP = 0x02,
82034+};
82035+
82036+enum {
82037+ GR_ID_ALLOW = 0x01,
82038+ GR_ID_DENY = 0x02,
82039+};
82040+
82041+#define GR_CRASH_RES 31
82042+#define GR_UIDTABLE_MAX 500
82043+
82044+/* begin resource learning section */
82045+enum {
82046+ GR_RLIM_CPU_BUMP = 60,
82047+ GR_RLIM_FSIZE_BUMP = 50000,
82048+ GR_RLIM_DATA_BUMP = 10000,
82049+ GR_RLIM_STACK_BUMP = 1000,
82050+ GR_RLIM_CORE_BUMP = 10000,
82051+ GR_RLIM_RSS_BUMP = 500000,
82052+ GR_RLIM_NPROC_BUMP = 1,
82053+ GR_RLIM_NOFILE_BUMP = 5,
82054+ GR_RLIM_MEMLOCK_BUMP = 50000,
82055+ GR_RLIM_AS_BUMP = 500000,
82056+ GR_RLIM_LOCKS_BUMP = 2,
82057+ GR_RLIM_SIGPENDING_BUMP = 5,
82058+ GR_RLIM_MSGQUEUE_BUMP = 10000,
82059+ GR_RLIM_NICE_BUMP = 1,
82060+ GR_RLIM_RTPRIO_BUMP = 1,
82061+ GR_RLIM_RTTIME_BUMP = 1000000
82062+};
82063+
82064+#endif
82065diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
82066new file mode 100644
82067index 0000000..d25522e
82068--- /dev/null
82069+++ b/include/linux/grinternal.h
82070@@ -0,0 +1,229 @@
82071+#ifndef __GRINTERNAL_H
82072+#define __GRINTERNAL_H
82073+
82074+#ifdef CONFIG_GRKERNSEC
82075+
82076+#include <linux/fs.h>
82077+#include <linux/mnt_namespace.h>
82078+#include <linux/nsproxy.h>
82079+#include <linux/gracl.h>
82080+#include <linux/grdefs.h>
82081+#include <linux/grmsg.h>
82082+
82083+void gr_add_learn_entry(const char *fmt, ...)
82084+ __attribute__ ((format (printf, 1, 2)));
82085+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
82086+ const struct vfsmount *mnt);
82087+__u32 gr_check_create(const struct dentry *new_dentry,
82088+ const struct dentry *parent,
82089+ const struct vfsmount *mnt, const __u32 mode);
82090+int gr_check_protected_task(const struct task_struct *task);
82091+__u32 to_gr_audit(const __u32 reqmode);
82092+int gr_set_acls(const int type);
82093+int gr_acl_is_enabled(void);
82094+char gr_roletype_to_char(void);
82095+
82096+void gr_handle_alertkill(struct task_struct *task);
82097+char *gr_to_filename(const struct dentry *dentry,
82098+ const struct vfsmount *mnt);
82099+char *gr_to_filename1(const struct dentry *dentry,
82100+ const struct vfsmount *mnt);
82101+char *gr_to_filename2(const struct dentry *dentry,
82102+ const struct vfsmount *mnt);
82103+char *gr_to_filename3(const struct dentry *dentry,
82104+ const struct vfsmount *mnt);
82105+
82106+extern int grsec_enable_ptrace_readexec;
82107+extern int grsec_enable_harden_ptrace;
82108+extern int grsec_enable_link;
82109+extern int grsec_enable_fifo;
82110+extern int grsec_enable_execve;
82111+extern int grsec_enable_shm;
82112+extern int grsec_enable_execlog;
82113+extern int grsec_enable_signal;
82114+extern int grsec_enable_audit_ptrace;
82115+extern int grsec_enable_forkfail;
82116+extern int grsec_enable_time;
82117+extern int grsec_enable_rofs;
82118+extern int grsec_deny_new_usb;
82119+extern int grsec_enable_chroot_shmat;
82120+extern int grsec_enable_chroot_mount;
82121+extern int grsec_enable_chroot_double;
82122+extern int grsec_enable_chroot_pivot;
82123+extern int grsec_enable_chroot_chdir;
82124+extern int grsec_enable_chroot_chmod;
82125+extern int grsec_enable_chroot_mknod;
82126+extern int grsec_enable_chroot_fchdir;
82127+extern int grsec_enable_chroot_nice;
82128+extern int grsec_enable_chroot_execlog;
82129+extern int grsec_enable_chroot_caps;
82130+extern int grsec_enable_chroot_sysctl;
82131+extern int grsec_enable_chroot_unix;
82132+extern int grsec_enable_symlinkown;
82133+extern kgid_t grsec_symlinkown_gid;
82134+extern int grsec_enable_tpe;
82135+extern kgid_t grsec_tpe_gid;
82136+extern int grsec_enable_tpe_all;
82137+extern int grsec_enable_tpe_invert;
82138+extern int grsec_enable_socket_all;
82139+extern kgid_t grsec_socket_all_gid;
82140+extern int grsec_enable_socket_client;
82141+extern kgid_t grsec_socket_client_gid;
82142+extern int grsec_enable_socket_server;
82143+extern kgid_t grsec_socket_server_gid;
82144+extern kgid_t grsec_audit_gid;
82145+extern int grsec_enable_group;
82146+extern int grsec_enable_log_rwxmaps;
82147+extern int grsec_enable_mount;
82148+extern int grsec_enable_chdir;
82149+extern int grsec_resource_logging;
82150+extern int grsec_enable_blackhole;
82151+extern int grsec_lastack_retries;
82152+extern int grsec_enable_brute;
82153+extern int grsec_enable_harden_ipc;
82154+extern int grsec_lock;
82155+
82156+extern spinlock_t grsec_alert_lock;
82157+extern unsigned long grsec_alert_wtime;
82158+extern unsigned long grsec_alert_fyet;
82159+
82160+extern spinlock_t grsec_audit_lock;
82161+
82162+extern rwlock_t grsec_exec_file_lock;
82163+
82164+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
82165+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
82166+ (tsk)->exec_file->f_path.mnt) : "/")
82167+
82168+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
82169+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
82170+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82171+
82172+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
82173+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
82174+ (tsk)->exec_file->f_path.mnt) : "/")
82175+
82176+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
82177+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
82178+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
82179+
82180+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
82181+
82182+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
82183+
82184+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
82185+{
82186+ if (file1 && file2) {
82187+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
82188+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
82189+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
82190+ return true;
82191+ }
82192+
82193+ return false;
82194+}
82195+
82196+#define GR_CHROOT_CAPS {{ \
82197+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
82198+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
82199+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
82200+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
82201+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
82202+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
82203+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
82204+
82205+#define security_learn(normal_msg,args...) \
82206+({ \
82207+ read_lock(&grsec_exec_file_lock); \
82208+ gr_add_learn_entry(normal_msg "\n", ## args); \
82209+ read_unlock(&grsec_exec_file_lock); \
82210+})
82211+
82212+enum {
82213+ GR_DO_AUDIT,
82214+ GR_DONT_AUDIT,
82215+ /* used for non-audit messages that we shouldn't kill the task on */
82216+ GR_DONT_AUDIT_GOOD
82217+};
82218+
82219+enum {
82220+ GR_TTYSNIFF,
82221+ GR_RBAC,
82222+ GR_RBAC_STR,
82223+ GR_STR_RBAC,
82224+ GR_RBAC_MODE2,
82225+ GR_RBAC_MODE3,
82226+ GR_FILENAME,
82227+ GR_SYSCTL_HIDDEN,
82228+ GR_NOARGS,
82229+ GR_ONE_INT,
82230+ GR_ONE_INT_TWO_STR,
82231+ GR_ONE_STR,
82232+ GR_STR_INT,
82233+ GR_TWO_STR_INT,
82234+ GR_TWO_INT,
82235+ GR_TWO_U64,
82236+ GR_THREE_INT,
82237+ GR_FIVE_INT_TWO_STR,
82238+ GR_TWO_STR,
82239+ GR_THREE_STR,
82240+ GR_FOUR_STR,
82241+ GR_STR_FILENAME,
82242+ GR_FILENAME_STR,
82243+ GR_FILENAME_TWO_INT,
82244+ GR_FILENAME_TWO_INT_STR,
82245+ GR_TEXTREL,
82246+ GR_PTRACE,
82247+ GR_RESOURCE,
82248+ GR_CAP,
82249+ GR_SIG,
82250+ GR_SIG2,
82251+ GR_CRASH1,
82252+ GR_CRASH2,
82253+ GR_PSACCT,
82254+ GR_RWXMAP,
82255+ GR_RWXMAPVMA
82256+};
82257+
82258+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
82259+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
82260+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
82261+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
82262+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
82263+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
82264+#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)
82265+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
82266+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
82267+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
82268+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
82269+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
82270+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
82271+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
82272+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
82273+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
82274+#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)
82275+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
82276+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
82277+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
82278+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
82279+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
82280+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
82281+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
82282+#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)
82283+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
82284+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
82285+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
82286+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
82287+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
82288+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
82289+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
82290+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
82291+#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)
82292+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
82293+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
82294+
82295+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
82296+
82297+#endif
82298+
82299+#endif
82300diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
82301new file mode 100644
82302index 0000000..b02ba9d
82303--- /dev/null
82304+++ b/include/linux/grmsg.h
82305@@ -0,0 +1,117 @@
82306+#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"
82307+#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"
82308+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
82309+#define GR_STOPMOD_MSG "denied modification of module state by "
82310+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
82311+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
82312+#define GR_IOPERM_MSG "denied use of ioperm() by "
82313+#define GR_IOPL_MSG "denied use of iopl() by "
82314+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
82315+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
82316+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
82317+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
82318+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
82319+#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"
82320+#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"
82321+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
82322+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
82323+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
82324+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
82325+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
82326+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
82327+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
82328+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
82329+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
82330+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
82331+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
82332+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
82333+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
82334+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
82335+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
82336+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
82337+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
82338+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
82339+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
82340+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
82341+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
82342+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
82343+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
82344+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
82345+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
82346+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
82347+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
82348+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
82349+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
82350+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
82351+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
82352+#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
82353+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
82354+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
82355+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
82356+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
82357+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
82358+#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"
82359+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
82360+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
82361+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
82362+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
82363+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
82364+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
82365+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
82366+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
82367+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
82368+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
82369+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
82370+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
82371+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
82372+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
82373+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
82374+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
82375+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
82376+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
82377+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
82378+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
82379+#define GR_FAILFORK_MSG "failed fork with errno %s by "
82380+#define GR_NICE_CHROOT_MSG "denied priority change by "
82381+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
82382+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
82383+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
82384+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
82385+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
82386+#define GR_TIME_MSG "time set by "
82387+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
82388+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
82389+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
82390+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
82391+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
82392+#define GR_BIND_MSG "denied bind() by "
82393+#define GR_CONNECT_MSG "denied connect() by "
82394+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
82395+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
82396+#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"
82397+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
82398+#define GR_CAP_ACL_MSG "use of %s denied for "
82399+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
82400+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
82401+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
82402+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
82403+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
82404+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
82405+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
82406+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
82407+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
82408+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
82409+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
82410+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
82411+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
82412+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
82413+#define GR_VM86_MSG "denied use of vm86 by "
82414+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
82415+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
82416+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
82417+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
82418+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
82419+#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 "
82420+#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 "
82421+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
82422+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
82423diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
82424new file mode 100644
82425index 0000000..10b9635
82426--- /dev/null
82427+++ b/include/linux/grsecurity.h
82428@@ -0,0 +1,254 @@
82429+#ifndef GR_SECURITY_H
82430+#define GR_SECURITY_H
82431+#include <linux/fs.h>
82432+#include <linux/fs_struct.h>
82433+#include <linux/binfmts.h>
82434+#include <linux/gracl.h>
82435+
82436+/* notify of brain-dead configs */
82437+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82438+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
82439+#endif
82440+#if defined(CONFIG_GRKERNSEC_PROC) && !defined(CONFIG_GRKERNSEC_PROC_USER) && !defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
82441+#error "CONFIG_GRKERNSEC_PROC enabled, but neither CONFIG_GRKERNSEC_PROC_USER nor CONFIG_GRKERNSEC_PROC_USERGROUP enabled"
82442+#endif
82443+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
82444+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
82445+#endif
82446+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
82447+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
82448+#endif
82449+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
82450+#error "CONFIG_PAX enabled, but no PaX options are enabled."
82451+#endif
82452+
82453+int gr_handle_new_usb(void);
82454+
82455+void gr_handle_brute_attach(int dumpable);
82456+void gr_handle_brute_check(void);
82457+void gr_handle_kernel_exploit(void);
82458+
82459+char gr_roletype_to_char(void);
82460+
82461+int gr_proc_is_restricted(void);
82462+
82463+int gr_acl_enable_at_secure(void);
82464+
82465+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
82466+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
82467+
82468+int gr_learn_cap(const struct task_struct *task, const struct cred *cred, const int cap);
82469+
82470+void gr_del_task_from_ip_table(struct task_struct *p);
82471+
82472+int gr_pid_is_chrooted(struct task_struct *p);
82473+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
82474+int gr_handle_chroot_nice(void);
82475+int gr_handle_chroot_sysctl(const int op);
82476+int gr_handle_chroot_setpriority(struct task_struct *p,
82477+ const int niceval);
82478+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
82479+int gr_chroot_fhandle(void);
82480+int gr_handle_chroot_chroot(const struct dentry *dentry,
82481+ const struct vfsmount *mnt);
82482+void gr_handle_chroot_chdir(const struct path *path);
82483+int gr_handle_chroot_chmod(const struct dentry *dentry,
82484+ const struct vfsmount *mnt, const int mode);
82485+int gr_handle_chroot_mknod(const struct dentry *dentry,
82486+ const struct vfsmount *mnt, const int mode);
82487+int gr_handle_chroot_mount(const struct dentry *dentry,
82488+ const struct vfsmount *mnt,
82489+ const char *dev_name);
82490+int gr_handle_chroot_pivot(void);
82491+int gr_handle_chroot_unix(const pid_t pid);
82492+
82493+int gr_handle_rawio(const struct inode *inode);
82494+
82495+void gr_handle_ioperm(void);
82496+void gr_handle_iopl(void);
82497+void gr_handle_msr_write(void);
82498+
82499+umode_t gr_acl_umask(void);
82500+
82501+int gr_tpe_allow(const struct file *file);
82502+
82503+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
82504+void gr_clear_chroot_entries(struct task_struct *task);
82505+
82506+void gr_log_forkfail(const int retval);
82507+void gr_log_timechange(void);
82508+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
82509+void gr_log_chdir(const struct dentry *dentry,
82510+ const struct vfsmount *mnt);
82511+void gr_log_chroot_exec(const struct dentry *dentry,
82512+ const struct vfsmount *mnt);
82513+void gr_log_remount(const char *devname, const int retval);
82514+void gr_log_unmount(const char *devname, const int retval);
82515+void gr_log_mount(const char *from, const char *to, const int retval);
82516+void gr_log_textrel(struct vm_area_struct *vma);
82517+void gr_log_ptgnustack(struct file *file);
82518+void gr_log_rwxmmap(struct file *file);
82519+void gr_log_rwxmprotect(struct vm_area_struct *vma);
82520+
82521+int gr_handle_follow_link(const struct inode *parent,
82522+ const struct inode *inode,
82523+ const struct dentry *dentry,
82524+ const struct vfsmount *mnt);
82525+int gr_handle_fifo(const struct dentry *dentry,
82526+ const struct vfsmount *mnt,
82527+ const struct dentry *dir, const int flag,
82528+ const int acc_mode);
82529+int gr_handle_hardlink(const struct dentry *dentry,
82530+ const struct vfsmount *mnt,
82531+ struct inode *inode,
82532+ const int mode, const struct filename *to);
82533+
82534+int gr_is_capable(const int cap);
82535+int gr_is_capable_nolog(const int cap);
82536+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
82537+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
82538+
82539+void gr_copy_label(struct task_struct *tsk);
82540+void gr_handle_crash(struct task_struct *task, const int sig);
82541+int gr_handle_signal(const struct task_struct *p, const int sig);
82542+int gr_check_crash_uid(const kuid_t uid);
82543+int gr_check_protected_task(const struct task_struct *task);
82544+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
82545+int gr_acl_handle_mmap(const struct file *file,
82546+ const unsigned long prot);
82547+int gr_acl_handle_mprotect(const struct file *file,
82548+ const unsigned long prot);
82549+int gr_check_hidden_task(const struct task_struct *tsk);
82550+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
82551+ const struct vfsmount *mnt);
82552+__u32 gr_acl_handle_utime(const struct dentry *dentry,
82553+ const struct vfsmount *mnt);
82554+__u32 gr_acl_handle_access(const struct dentry *dentry,
82555+ const struct vfsmount *mnt, const int fmode);
82556+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
82557+ const struct vfsmount *mnt, umode_t *mode);
82558+__u32 gr_acl_handle_chown(const struct dentry *dentry,
82559+ const struct vfsmount *mnt);
82560+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
82561+ const struct vfsmount *mnt);
82562+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
82563+ const struct vfsmount *mnt);
82564+int gr_handle_ptrace(struct task_struct *task, const long request);
82565+int gr_handle_proc_ptrace(struct task_struct *task);
82566+__u32 gr_acl_handle_execve(const struct dentry *dentry,
82567+ const struct vfsmount *mnt);
82568+int gr_check_crash_exec(const struct file *filp);
82569+int gr_acl_is_enabled(void);
82570+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
82571+ const kgid_t gid);
82572+int gr_set_proc_label(const struct dentry *dentry,
82573+ const struct vfsmount *mnt,
82574+ const int unsafe_flags);
82575+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
82576+ const struct vfsmount *mnt);
82577+__u32 gr_acl_handle_open(const struct dentry *dentry,
82578+ const struct vfsmount *mnt, int acc_mode);
82579+__u32 gr_acl_handle_creat(const struct dentry *dentry,
82580+ const struct dentry *p_dentry,
82581+ const struct vfsmount *p_mnt,
82582+ int open_flags, int acc_mode, const int imode);
82583+void gr_handle_create(const struct dentry *dentry,
82584+ const struct vfsmount *mnt);
82585+void gr_handle_proc_create(const struct dentry *dentry,
82586+ const struct inode *inode);
82587+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
82588+ const struct dentry *parent_dentry,
82589+ const struct vfsmount *parent_mnt,
82590+ const int mode);
82591+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
82592+ const struct dentry *parent_dentry,
82593+ const struct vfsmount *parent_mnt);
82594+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
82595+ const struct vfsmount *mnt);
82596+void gr_handle_delete(const ino_t ino, const dev_t dev);
82597+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
82598+ const struct vfsmount *mnt);
82599+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
82600+ const struct dentry *parent_dentry,
82601+ const struct vfsmount *parent_mnt,
82602+ const struct filename *from);
82603+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
82604+ const struct dentry *parent_dentry,
82605+ const struct vfsmount *parent_mnt,
82606+ const struct dentry *old_dentry,
82607+ const struct vfsmount *old_mnt, const struct filename *to);
82608+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
82609+int gr_acl_handle_rename(struct dentry *new_dentry,
82610+ struct dentry *parent_dentry,
82611+ const struct vfsmount *parent_mnt,
82612+ struct dentry *old_dentry,
82613+ struct inode *old_parent_inode,
82614+ struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
82615+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
82616+ struct dentry *old_dentry,
82617+ struct dentry *new_dentry,
82618+ struct vfsmount *mnt, const __u8 replace, unsigned int flags);
82619+__u32 gr_check_link(const struct dentry *new_dentry,
82620+ const struct dentry *parent_dentry,
82621+ const struct vfsmount *parent_mnt,
82622+ const struct dentry *old_dentry,
82623+ const struct vfsmount *old_mnt);
82624+int gr_acl_handle_filldir(const struct file *file, const char *name,
82625+ const unsigned int namelen, const ino_t ino);
82626+
82627+__u32 gr_acl_handle_unix(const struct dentry *dentry,
82628+ const struct vfsmount *mnt);
82629+void gr_acl_handle_exit(void);
82630+void gr_acl_handle_psacct(struct task_struct *task, const long code);
82631+int gr_acl_handle_procpidmem(const struct task_struct *task);
82632+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
82633+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
82634+void gr_audit_ptrace(struct task_struct *task);
82635+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
82636+void gr_put_exec_file(struct task_struct *task);
82637+
82638+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
82639+
82640+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
82641+extern void gr_learn_resource(const struct task_struct *task, const int res,
82642+ const unsigned long wanted, const int gt);
82643+#else
82644+static inline void gr_learn_resource(const struct task_struct *task, const int res,
82645+ const unsigned long wanted, const int gt)
82646+{
82647+}
82648+#endif
82649+
82650+#ifdef CONFIG_GRKERNSEC_RESLOG
82651+extern void gr_log_resource(const struct task_struct *task, const int res,
82652+ const unsigned long wanted, const int gt);
82653+#else
82654+static inline void gr_log_resource(const struct task_struct *task, const int res,
82655+ const unsigned long wanted, const int gt)
82656+{
82657+}
82658+#endif
82659+
82660+#ifdef CONFIG_GRKERNSEC
82661+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
82662+void gr_handle_vm86(void);
82663+void gr_handle_mem_readwrite(u64 from, u64 to);
82664+
82665+void gr_log_badprocpid(const char *entry);
82666+
82667+extern int grsec_enable_dmesg;
82668+extern int grsec_disable_privio;
82669+
82670+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
82671+extern kgid_t grsec_proc_gid;
82672+#endif
82673+
82674+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
82675+extern int grsec_enable_chroot_findtask;
82676+#endif
82677+#ifdef CONFIG_GRKERNSEC_SETXID
82678+extern int grsec_enable_setxid;
82679+#endif
82680+#endif
82681+
82682+#endif
82683diff --git a/include/linux/grsock.h b/include/linux/grsock.h
82684new file mode 100644
82685index 0000000..e7ffaaf
82686--- /dev/null
82687+++ b/include/linux/grsock.h
82688@@ -0,0 +1,19 @@
82689+#ifndef __GRSOCK_H
82690+#define __GRSOCK_H
82691+
82692+extern void gr_attach_curr_ip(const struct sock *sk);
82693+extern int gr_handle_sock_all(const int family, const int type,
82694+ const int protocol);
82695+extern int gr_handle_sock_server(const struct sockaddr *sck);
82696+extern int gr_handle_sock_server_other(const struct sock *sck);
82697+extern int gr_handle_sock_client(const struct sockaddr *sck);
82698+extern int gr_search_connect(struct socket * sock,
82699+ struct sockaddr_in * addr);
82700+extern int gr_search_bind(struct socket * sock,
82701+ struct sockaddr_in * addr);
82702+extern int gr_search_listen(struct socket * sock);
82703+extern int gr_search_accept(struct socket * sock);
82704+extern int gr_search_socket(const int domain, const int type,
82705+ const int protocol);
82706+
82707+#endif
82708diff --git a/include/linux/hash.h b/include/linux/hash.h
82709index d0494c3..69b7715 100644
82710--- a/include/linux/hash.h
82711+++ b/include/linux/hash.h
82712@@ -87,7 +87,7 @@ static inline u32 hash32_ptr(const void *ptr)
82713 struct fast_hash_ops {
82714 u32 (*hash)(const void *data, u32 len, u32 seed);
82715 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
82716-};
82717+} __no_const;
82718
82719 /**
82720 * arch_fast_hash - Caclulates a hash over a given buffer that can have
82721diff --git a/include/linux/highmem.h b/include/linux/highmem.h
82722index 9286a46..373f27f 100644
82723--- a/include/linux/highmem.h
82724+++ b/include/linux/highmem.h
82725@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
82726 kunmap_atomic(kaddr);
82727 }
82728
82729+static inline void sanitize_highpage(struct page *page)
82730+{
82731+ void *kaddr;
82732+ unsigned long flags;
82733+
82734+ local_irq_save(flags);
82735+ kaddr = kmap_atomic(page);
82736+ clear_page(kaddr);
82737+ kunmap_atomic(kaddr);
82738+ local_irq_restore(flags);
82739+}
82740+
82741 static inline void zero_user_segments(struct page *page,
82742 unsigned start1, unsigned end1,
82743 unsigned start2, unsigned end2)
82744diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
82745index 1c7b89a..7dda400 100644
82746--- a/include/linux/hwmon-sysfs.h
82747+++ b/include/linux/hwmon-sysfs.h
82748@@ -25,7 +25,8 @@
82749 struct sensor_device_attribute{
82750 struct device_attribute dev_attr;
82751 int index;
82752-};
82753+} __do_const;
82754+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
82755 #define to_sensor_dev_attr(_dev_attr) \
82756 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
82757
82758@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
82759 struct device_attribute dev_attr;
82760 u8 index;
82761 u8 nr;
82762-};
82763+} __do_const;
82764+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
82765 #define to_sensor_dev_attr_2(_dev_attr) \
82766 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
82767
82768diff --git a/include/linux/i2c.h b/include/linux/i2c.h
82769index b556e0a..c10a515 100644
82770--- a/include/linux/i2c.h
82771+++ b/include/linux/i2c.h
82772@@ -378,6 +378,7 @@ struct i2c_algorithm {
82773 /* To determine what the adapter supports */
82774 u32 (*functionality) (struct i2c_adapter *);
82775 };
82776+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
82777
82778 /**
82779 * struct i2c_bus_recovery_info - I2C bus recovery information
82780diff --git a/include/linux/i2o.h b/include/linux/i2o.h
82781index d23c3c2..eb63c81 100644
82782--- a/include/linux/i2o.h
82783+++ b/include/linux/i2o.h
82784@@ -565,7 +565,7 @@ struct i2o_controller {
82785 struct i2o_device *exec; /* Executive */
82786 #if BITS_PER_LONG == 64
82787 spinlock_t context_list_lock; /* lock for context_list */
82788- atomic_t context_list_counter; /* needed for unique contexts */
82789+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
82790 struct list_head context_list; /* list of context id's
82791 and pointers */
82792 #endif
82793diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
82794index aff7ad8..3942bbd 100644
82795--- a/include/linux/if_pppox.h
82796+++ b/include/linux/if_pppox.h
82797@@ -76,7 +76,7 @@ struct pppox_proto {
82798 int (*ioctl)(struct socket *sock, unsigned int cmd,
82799 unsigned long arg);
82800 struct module *owner;
82801-};
82802+} __do_const;
82803
82804 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
82805 extern void unregister_pppox_proto(int proto_num);
82806diff --git a/include/linux/init.h b/include/linux/init.h
82807index 2df8e8d..3e1280d 100644
82808--- a/include/linux/init.h
82809+++ b/include/linux/init.h
82810@@ -37,9 +37,17 @@
82811 * section.
82812 */
82813
82814+#define add_init_latent_entropy __latent_entropy
82815+
82816+#ifdef CONFIG_MEMORY_HOTPLUG
82817+#define add_meminit_latent_entropy
82818+#else
82819+#define add_meminit_latent_entropy __latent_entropy
82820+#endif
82821+
82822 /* These are for everybody (although not all archs will actually
82823 discard it in modules) */
82824-#define __init __section(.init.text) __cold notrace
82825+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
82826 #define __initdata __section(.init.data)
82827 #define __initconst __constsection(.init.rodata)
82828 #define __exitdata __section(.exit.data)
82829@@ -100,7 +108,7 @@
82830 #define __cpuexitconst
82831
82832 /* Used for MEMORY_HOTPLUG */
82833-#define __meminit __section(.meminit.text) __cold notrace
82834+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
82835 #define __meminitdata __section(.meminit.data)
82836 #define __meminitconst __constsection(.meminit.rodata)
82837 #define __memexit __section(.memexit.text) __exitused __cold notrace
82838diff --git a/include/linux/init_task.h b/include/linux/init_task.h
82839index 2bb4c4f3..e0fac69 100644
82840--- a/include/linux/init_task.h
82841+++ b/include/linux/init_task.h
82842@@ -149,6 +149,12 @@ extern struct task_group root_task_group;
82843
82844 #define INIT_TASK_COMM "swapper"
82845
82846+#ifdef CONFIG_X86
82847+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
82848+#else
82849+#define INIT_TASK_THREAD_INFO
82850+#endif
82851+
82852 #ifdef CONFIG_RT_MUTEXES
82853 # define INIT_RT_MUTEXES(tsk) \
82854 .pi_waiters = RB_ROOT, \
82855@@ -196,6 +202,7 @@ extern struct task_group root_task_group;
82856 RCU_POINTER_INITIALIZER(cred, &init_cred), \
82857 .comm = INIT_TASK_COMM, \
82858 .thread = INIT_THREAD, \
82859+ INIT_TASK_THREAD_INFO \
82860 .fs = &init_fs, \
82861 .files = &init_files, \
82862 .signal = &init_signals, \
82863diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
82864index 698ad05..8601bb7 100644
82865--- a/include/linux/interrupt.h
82866+++ b/include/linux/interrupt.h
82867@@ -418,8 +418,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
82868
82869 struct softirq_action
82870 {
82871- void (*action)(struct softirq_action *);
82872-};
82873+ void (*action)(void);
82874+} __no_const;
82875
82876 asmlinkage void do_softirq(void);
82877 asmlinkage void __do_softirq(void);
82878@@ -433,7 +433,7 @@ static inline void do_softirq_own_stack(void)
82879 }
82880 #endif
82881
82882-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
82883+extern void open_softirq(int nr, void (*action)(void));
82884 extern void softirq_init(void);
82885 extern void __raise_softirq_irqoff(unsigned int nr);
82886
82887diff --git a/include/linux/iommu.h b/include/linux/iommu.h
82888index 20f9a52..63ee2e3 100644
82889--- a/include/linux/iommu.h
82890+++ b/include/linux/iommu.h
82891@@ -131,7 +131,7 @@ struct iommu_ops {
82892 u32 (*domain_get_windows)(struct iommu_domain *domain);
82893
82894 unsigned long pgsize_bitmap;
82895-};
82896+} __do_const;
82897
82898 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
82899 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
82900diff --git a/include/linux/ioport.h b/include/linux/ioport.h
82901index 142ec54..873e033 100644
82902--- a/include/linux/ioport.h
82903+++ b/include/linux/ioport.h
82904@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
82905 int adjust_resource(struct resource *res, resource_size_t start,
82906 resource_size_t size);
82907 resource_size_t resource_alignment(struct resource *res);
82908-static inline resource_size_t resource_size(const struct resource *res)
82909+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
82910 {
82911 return res->end - res->start + 1;
82912 }
82913diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
82914index 35e7eca..6afb7ad 100644
82915--- a/include/linux/ipc_namespace.h
82916+++ b/include/linux/ipc_namespace.h
82917@@ -69,7 +69,7 @@ struct ipc_namespace {
82918 struct user_namespace *user_ns;
82919
82920 unsigned int proc_inum;
82921-};
82922+} __randomize_layout;
82923
82924 extern struct ipc_namespace init_ipc_ns;
82925 extern atomic_t nr_ipc_ns;
82926diff --git a/include/linux/irq.h b/include/linux/irq.h
82927index 62af592..cc3b0d0 100644
82928--- a/include/linux/irq.h
82929+++ b/include/linux/irq.h
82930@@ -344,7 +344,8 @@ struct irq_chip {
82931 void (*irq_release_resources)(struct irq_data *data);
82932
82933 unsigned long flags;
82934-};
82935+} __do_const;
82936+typedef struct irq_chip __no_const irq_chip_no_const;
82937
82938 /*
82939 * irq_chip specific flags
82940diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
82941index 45e2d8c..26d85da 100644
82942--- a/include/linux/irqchip/arm-gic.h
82943+++ b/include/linux/irqchip/arm-gic.h
82944@@ -75,9 +75,11 @@
82945
82946 #ifndef __ASSEMBLY__
82947
82948+#include <linux/irq.h>
82949+
82950 struct device_node;
82951
82952-extern struct irq_chip gic_arch_extn;
82953+extern irq_chip_no_const gic_arch_extn;
82954
82955 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
82956 u32 offset, struct device_node *);
82957diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
82958index c367cbd..c9b79e6 100644
82959--- a/include/linux/jiffies.h
82960+++ b/include/linux/jiffies.h
82961@@ -280,20 +280,20 @@ extern unsigned long preset_lpj;
82962 /*
82963 * Convert various time units to each other:
82964 */
82965-extern unsigned int jiffies_to_msecs(const unsigned long j);
82966-extern unsigned int jiffies_to_usecs(const unsigned long j);
82967+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
82968+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
82969
82970-static inline u64 jiffies_to_nsecs(const unsigned long j)
82971+static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
82972 {
82973 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
82974 }
82975
82976-extern unsigned long msecs_to_jiffies(const unsigned int m);
82977-extern unsigned long usecs_to_jiffies(const unsigned int u);
82978+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
82979+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
82980 extern unsigned long timespec_to_jiffies(const struct timespec *value);
82981 extern void jiffies_to_timespec(const unsigned long jiffies,
82982- struct timespec *value);
82983-extern unsigned long timeval_to_jiffies(const struct timeval *value);
82984+ struct timespec *value) __intentional_overflow(-1);
82985+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
82986 extern void jiffies_to_timeval(const unsigned long jiffies,
82987 struct timeval *value);
82988
82989diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
82990index 6883e19..e854fcb 100644
82991--- a/include/linux/kallsyms.h
82992+++ b/include/linux/kallsyms.h
82993@@ -15,7 +15,8 @@
82994
82995 struct module;
82996
82997-#ifdef CONFIG_KALLSYMS
82998+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
82999+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
83000 /* Lookup the address for a symbol. Returns 0 if not found. */
83001 unsigned long kallsyms_lookup_name(const char *name);
83002
83003@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
83004 /* Stupid that this does nothing, but I didn't create this mess. */
83005 #define __print_symbol(fmt, addr)
83006 #endif /*CONFIG_KALLSYMS*/
83007+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
83008+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
83009+extern unsigned long kallsyms_lookup_name(const char *name);
83010+extern void __print_symbol(const char *fmt, unsigned long address);
83011+extern int sprint_backtrace(char *buffer, unsigned long address);
83012+extern int sprint_symbol(char *buffer, unsigned long address);
83013+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
83014+const char *kallsyms_lookup(unsigned long addr,
83015+ unsigned long *symbolsize,
83016+ unsigned long *offset,
83017+ char **modname, char *namebuf);
83018+extern int kallsyms_lookup_size_offset(unsigned long addr,
83019+ unsigned long *symbolsize,
83020+ unsigned long *offset);
83021+#endif
83022
83023 /* This macro allows us to keep printk typechecking */
83024 static __printf(1, 2)
83025diff --git a/include/linux/key-type.h b/include/linux/key-type.h
83026index 44792ee..6172f2a 100644
83027--- a/include/linux/key-type.h
83028+++ b/include/linux/key-type.h
83029@@ -132,7 +132,7 @@ struct key_type {
83030 /* internal fields */
83031 struct list_head link; /* link in types list */
83032 struct lock_class_key lock_class; /* key->sem lock class */
83033-};
83034+} __do_const;
83035
83036 extern struct key_type key_type_keyring;
83037
83038diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
83039index 6b06d37..19f605f 100644
83040--- a/include/linux/kgdb.h
83041+++ b/include/linux/kgdb.h
83042@@ -52,7 +52,7 @@ extern int kgdb_connected;
83043 extern int kgdb_io_module_registered;
83044
83045 extern atomic_t kgdb_setting_breakpoint;
83046-extern atomic_t kgdb_cpu_doing_single_step;
83047+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
83048
83049 extern struct task_struct *kgdb_usethread;
83050 extern struct task_struct *kgdb_contthread;
83051@@ -254,7 +254,7 @@ struct kgdb_arch {
83052 void (*correct_hw_break)(void);
83053
83054 void (*enable_nmi)(bool on);
83055-};
83056+} __do_const;
83057
83058 /**
83059 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
83060@@ -279,11 +279,11 @@ struct kgdb_io {
83061 void (*pre_exception) (void);
83062 void (*post_exception) (void);
83063 int is_console;
83064-};
83065+} __do_const;
83066
83067 extern struct kgdb_arch arch_kgdb_ops;
83068
83069-extern unsigned long __weak kgdb_arch_pc(int exception, struct pt_regs *regs);
83070+extern unsigned long kgdb_arch_pc(int exception, struct pt_regs *regs);
83071
83072 #ifdef CONFIG_SERIAL_KGDB_NMI
83073 extern int kgdb_register_nmi_console(void);
83074diff --git a/include/linux/kmod.h b/include/linux/kmod.h
83075index 0555cc6..40116ce 100644
83076--- a/include/linux/kmod.h
83077+++ b/include/linux/kmod.h
83078@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
83079 * usually useless though. */
83080 extern __printf(2, 3)
83081 int __request_module(bool wait, const char *name, ...);
83082+extern __printf(3, 4)
83083+int ___request_module(bool wait, char *param_name, const char *name, ...);
83084 #define request_module(mod...) __request_module(true, mod)
83085 #define request_module_nowait(mod...) __request_module(false, mod)
83086 #define try_then_request_module(x, mod...) \
83087@@ -57,6 +59,9 @@ struct subprocess_info {
83088 struct work_struct work;
83089 struct completion *complete;
83090 char *path;
83091+#ifdef CONFIG_GRKERNSEC
83092+ char *origpath;
83093+#endif
83094 char **argv;
83095 char **envp;
83096 int wait;
83097diff --git a/include/linux/kobject.h b/include/linux/kobject.h
83098index 2d61b90..a1d0a13 100644
83099--- a/include/linux/kobject.h
83100+++ b/include/linux/kobject.h
83101@@ -118,7 +118,7 @@ struct kobj_type {
83102 struct attribute **default_attrs;
83103 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
83104 const void *(*namespace)(struct kobject *kobj);
83105-};
83106+} __do_const;
83107
83108 struct kobj_uevent_env {
83109 char *argv[3];
83110@@ -142,6 +142,7 @@ struct kobj_attribute {
83111 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
83112 const char *buf, size_t count);
83113 };
83114+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
83115
83116 extern const struct sysfs_ops kobj_sysfs_ops;
83117
83118@@ -169,7 +170,7 @@ struct kset {
83119 spinlock_t list_lock;
83120 struct kobject kobj;
83121 const struct kset_uevent_ops *uevent_ops;
83122-};
83123+} __randomize_layout;
83124
83125 extern void kset_init(struct kset *kset);
83126 extern int __must_check kset_register(struct kset *kset);
83127diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
83128index df32d25..fb52e27 100644
83129--- a/include/linux/kobject_ns.h
83130+++ b/include/linux/kobject_ns.h
83131@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
83132 const void *(*netlink_ns)(struct sock *sk);
83133 const void *(*initial_ns)(void);
83134 void (*drop_ns)(void *);
83135-};
83136+} __do_const;
83137
83138 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
83139 int kobj_ns_type_registered(enum kobj_ns_type type);
83140diff --git a/include/linux/kref.h b/include/linux/kref.h
83141index 484604d..0f6c5b6 100644
83142--- a/include/linux/kref.h
83143+++ b/include/linux/kref.h
83144@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
83145 static inline int kref_sub(struct kref *kref, unsigned int count,
83146 void (*release)(struct kref *kref))
83147 {
83148- WARN_ON(release == NULL);
83149+ BUG_ON(release == NULL);
83150
83151 if (atomic_sub_and_test((int) count, &kref->refcount)) {
83152 release(kref);
83153diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
83154index a4c33b3..e854710 100644
83155--- a/include/linux/kvm_host.h
83156+++ b/include/linux/kvm_host.h
83157@@ -452,7 +452,7 @@ static inline void kvm_irqfd_exit(void)
83158 {
83159 }
83160 #endif
83161-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83162+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
83163 struct module *module);
83164 void kvm_exit(void);
83165
83166@@ -618,7 +618,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
83167 struct kvm_guest_debug *dbg);
83168 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
83169
83170-int kvm_arch_init(void *opaque);
83171+int kvm_arch_init(const void *opaque);
83172 void kvm_arch_exit(void);
83173
83174 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
83175diff --git a/include/linux/libata.h b/include/linux/libata.h
83176index 92abb49..e7fff2a 100644
83177--- a/include/linux/libata.h
83178+++ b/include/linux/libata.h
83179@@ -976,7 +976,7 @@ struct ata_port_operations {
83180 * fields must be pointers.
83181 */
83182 const struct ata_port_operations *inherits;
83183-};
83184+} __do_const;
83185
83186 struct ata_port_info {
83187 unsigned long flags;
83188diff --git a/include/linux/linkage.h b/include/linux/linkage.h
83189index a6a42dd..6c5ebce 100644
83190--- a/include/linux/linkage.h
83191+++ b/include/linux/linkage.h
83192@@ -36,6 +36,7 @@
83193 #endif
83194
83195 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
83196+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
83197 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
83198
83199 /*
83200diff --git a/include/linux/list.h b/include/linux/list.h
83201index cbbb96f..602d023 100644
83202--- a/include/linux/list.h
83203+++ b/include/linux/list.h
83204@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
83205 extern void list_del(struct list_head *entry);
83206 #endif
83207
83208+extern void __pax_list_add(struct list_head *new,
83209+ struct list_head *prev,
83210+ struct list_head *next);
83211+static inline void pax_list_add(struct list_head *new, struct list_head *head)
83212+{
83213+ __pax_list_add(new, head, head->next);
83214+}
83215+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
83216+{
83217+ __pax_list_add(new, head->prev, head);
83218+}
83219+extern void pax_list_del(struct list_head *entry);
83220+
83221 /**
83222 * list_replace - replace old entry by new one
83223 * @old : the element to be replaced
83224@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
83225 INIT_LIST_HEAD(entry);
83226 }
83227
83228+extern void pax_list_del_init(struct list_head *entry);
83229+
83230 /**
83231 * list_move - delete from one list and add as another's head
83232 * @list: the entry to move
83233diff --git a/include/linux/lockref.h b/include/linux/lockref.h
83234index 4bfde0e..d6e2e09 100644
83235--- a/include/linux/lockref.h
83236+++ b/include/linux/lockref.h
83237@@ -47,4 +47,36 @@ static inline int __lockref_is_dead(const struct lockref *l)
83238 return ((int)l->count < 0);
83239 }
83240
83241+static inline unsigned int __lockref_read(struct lockref *lockref)
83242+{
83243+ return lockref->count;
83244+}
83245+
83246+static inline void __lockref_set(struct lockref *lockref, unsigned int count)
83247+{
83248+ lockref->count = count;
83249+}
83250+
83251+static inline void __lockref_inc(struct lockref *lockref)
83252+{
83253+
83254+#ifdef CONFIG_PAX_REFCOUNT
83255+ atomic_inc((atomic_t *)&lockref->count);
83256+#else
83257+ lockref->count++;
83258+#endif
83259+
83260+}
83261+
83262+static inline void __lockref_dec(struct lockref *lockref)
83263+{
83264+
83265+#ifdef CONFIG_PAX_REFCOUNT
83266+ atomic_dec((atomic_t *)&lockref->count);
83267+#else
83268+ lockref->count--;
83269+#endif
83270+
83271+}
83272+
83273 #endif /* __LINUX_LOCKREF_H */
83274diff --git a/include/linux/math64.h b/include/linux/math64.h
83275index c45c089..298841c 100644
83276--- a/include/linux/math64.h
83277+++ b/include/linux/math64.h
83278@@ -15,7 +15,7 @@
83279 * This is commonly provided by 32bit archs to provide an optimized 64bit
83280 * divide.
83281 */
83282-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83283+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83284 {
83285 *remainder = dividend % divisor;
83286 return dividend / divisor;
83287@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
83288 /**
83289 * div64_u64 - unsigned 64bit divide with 64bit divisor
83290 */
83291-static inline u64 div64_u64(u64 dividend, u64 divisor)
83292+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
83293 {
83294 return dividend / divisor;
83295 }
83296@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
83297 #define div64_ul(x, y) div_u64((x), (y))
83298
83299 #ifndef div_u64_rem
83300-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83301+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
83302 {
83303 *remainder = do_div(dividend, divisor);
83304 return dividend;
83305@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
83306 #endif
83307
83308 #ifndef div64_u64
83309-extern u64 div64_u64(u64 dividend, u64 divisor);
83310+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
83311 #endif
83312
83313 #ifndef div64_s64
83314@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
83315 * divide.
83316 */
83317 #ifndef div_u64
83318-static inline u64 div_u64(u64 dividend, u32 divisor)
83319+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
83320 {
83321 u32 remainder;
83322 return div_u64_rem(dividend, divisor, &remainder);
83323diff --git a/include/linux/memory.h b/include/linux/memory.h
83324index bb7384e..8b8d8d1 100644
83325--- a/include/linux/memory.h
83326+++ b/include/linux/memory.h
83327@@ -35,7 +35,7 @@ struct memory_block {
83328 };
83329
83330 int arch_get_memory_phys_device(unsigned long start_pfn);
83331-unsigned long __weak memory_block_size_bytes(void);
83332+unsigned long memory_block_size_bytes(void);
83333
83334 /* These states are exposed to userspace as text strings in sysfs */
83335 #define MEM_ONLINE (1<<0) /* exposed to userspace */
83336diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
83337index f230a97..714c006 100644
83338--- a/include/linux/mempolicy.h
83339+++ b/include/linux/mempolicy.h
83340@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
83341 }
83342
83343 #define vma_policy(vma) ((vma)->vm_policy)
83344+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83345+{
83346+ vma->vm_policy = pol;
83347+}
83348
83349 static inline void mpol_get(struct mempolicy *pol)
83350 {
83351@@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
83352 }
83353
83354 #define vma_policy(vma) NULL
83355+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
83356+{
83357+}
83358
83359 static inline int
83360 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
83361diff --git a/include/linux/mm.h b/include/linux/mm.h
83362index f952cc8..b9f6135 100644
83363--- a/include/linux/mm.h
83364+++ b/include/linux/mm.h
83365@@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
83366 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
83367 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
83368 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
83369+
83370+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
83371+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
83372+#endif
83373+
83374 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
83375
83376 #ifdef CONFIG_MEM_SOFT_DIRTY
83377@@ -237,8 +242,8 @@ struct vm_operations_struct {
83378 /* called by access_process_vm when get_user_pages() fails, typically
83379 * for use by special VMAs that can switch between memory and hardware
83380 */
83381- int (*access)(struct vm_area_struct *vma, unsigned long addr,
83382- void *buf, int len, int write);
83383+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
83384+ void *buf, size_t len, int write);
83385
83386 /* Called by the /proc/PID/maps code to ask the vma whether it
83387 * has a special name. Returning non-NULL will also cause this
83388@@ -274,6 +279,7 @@ struct vm_operations_struct {
83389 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
83390 unsigned long size, pgoff_t pgoff);
83391 };
83392+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
83393
83394 struct mmu_gather;
83395 struct inode;
83396@@ -1163,8 +1169,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
83397 unsigned long *pfn);
83398 int follow_phys(struct vm_area_struct *vma, unsigned long address,
83399 unsigned int flags, unsigned long *prot, resource_size_t *phys);
83400-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83401- void *buf, int len, int write);
83402+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
83403+ void *buf, size_t len, int write);
83404
83405 static inline void unmap_shared_mapping_range(struct address_space *mapping,
83406 loff_t const holebegin, loff_t const holelen)
83407@@ -1204,9 +1210,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
83408 }
83409 #endif
83410
83411-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
83412-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83413- void *buf, int len, int write);
83414+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
83415+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83416+ void *buf, size_t len, int write);
83417
83418 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
83419 unsigned long start, unsigned long nr_pages,
83420@@ -1238,34 +1244,6 @@ int set_page_dirty_lock(struct page *page);
83421 int clear_page_dirty_for_io(struct page *page);
83422 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
83423
83424-/* Is the vma a continuation of the stack vma above it? */
83425-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
83426-{
83427- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
83428-}
83429-
83430-static inline int stack_guard_page_start(struct vm_area_struct *vma,
83431- unsigned long addr)
83432-{
83433- return (vma->vm_flags & VM_GROWSDOWN) &&
83434- (vma->vm_start == addr) &&
83435- !vma_growsdown(vma->vm_prev, addr);
83436-}
83437-
83438-/* Is the vma a continuation of the stack vma below it? */
83439-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
83440-{
83441- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
83442-}
83443-
83444-static inline int stack_guard_page_end(struct vm_area_struct *vma,
83445- unsigned long addr)
83446-{
83447- return (vma->vm_flags & VM_GROWSUP) &&
83448- (vma->vm_end == addr) &&
83449- !vma_growsup(vma->vm_next, addr);
83450-}
83451-
83452 extern pid_t
83453 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
83454
83455@@ -1365,6 +1343,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
83456 }
83457 #endif
83458
83459+#ifdef CONFIG_MMU
83460+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
83461+#else
83462+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
83463+{
83464+ return __pgprot(0);
83465+}
83466+#endif
83467+
83468 int vma_wants_writenotify(struct vm_area_struct *vma);
83469
83470 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
83471@@ -1383,8 +1370,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
83472 {
83473 return 0;
83474 }
83475+
83476+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
83477+ unsigned long address)
83478+{
83479+ return 0;
83480+}
83481 #else
83482 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83483+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
83484 #endif
83485
83486 #ifdef __PAGETABLE_PMD_FOLDED
83487@@ -1393,8 +1387,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
83488 {
83489 return 0;
83490 }
83491+
83492+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
83493+ unsigned long address)
83494+{
83495+ return 0;
83496+}
83497 #else
83498 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
83499+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
83500 #endif
83501
83502 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
83503@@ -1412,11 +1413,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
83504 NULL: pud_offset(pgd, address);
83505 }
83506
83507+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
83508+{
83509+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
83510+ NULL: pud_offset(pgd, address);
83511+}
83512+
83513 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
83514 {
83515 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
83516 NULL: pmd_offset(pud, address);
83517 }
83518+
83519+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
83520+{
83521+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
83522+ NULL: pmd_offset(pud, address);
83523+}
83524 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
83525
83526 #if USE_SPLIT_PTE_PTLOCKS
83527@@ -1815,7 +1828,7 @@ extern int install_special_mapping(struct mm_struct *mm,
83528 unsigned long addr, unsigned long len,
83529 unsigned long flags, struct page **pages);
83530
83531-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
83532+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
83533
83534 extern unsigned long mmap_region(struct file *file, unsigned long addr,
83535 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
83536@@ -1823,6 +1836,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
83537 unsigned long len, unsigned long prot, unsigned long flags,
83538 unsigned long pgoff, unsigned long *populate);
83539 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
83540+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
83541
83542 #ifdef CONFIG_MMU
83543 extern int __mm_populate(unsigned long addr, unsigned long len,
83544@@ -1851,10 +1865,11 @@ struct vm_unmapped_area_info {
83545 unsigned long high_limit;
83546 unsigned long align_mask;
83547 unsigned long align_offset;
83548+ unsigned long threadstack_offset;
83549 };
83550
83551-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
83552-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83553+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
83554+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
83555
83556 /*
83557 * Search for an unmapped address range.
83558@@ -1866,7 +1881,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
83559 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
83560 */
83561 static inline unsigned long
83562-vm_unmapped_area(struct vm_unmapped_area_info *info)
83563+vm_unmapped_area(const struct vm_unmapped_area_info *info)
83564 {
83565 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
83566 return unmapped_area(info);
83567@@ -1928,6 +1943,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
83568 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
83569 struct vm_area_struct **pprev);
83570
83571+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
83572+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
83573+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
83574+
83575 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
83576 NULL if none. Assume start_addr < end_addr. */
83577 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
83578@@ -1956,15 +1975,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
83579 return vma;
83580 }
83581
83582-#ifdef CONFIG_MMU
83583-pgprot_t vm_get_page_prot(unsigned long vm_flags);
83584-#else
83585-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
83586-{
83587- return __pgprot(0);
83588-}
83589-#endif
83590-
83591 #ifdef CONFIG_NUMA_BALANCING
83592 unsigned long change_prot_numa(struct vm_area_struct *vma,
83593 unsigned long start, unsigned long end);
83594@@ -2016,6 +2026,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
83595 static inline void vm_stat_account(struct mm_struct *mm,
83596 unsigned long flags, struct file *file, long pages)
83597 {
83598+
83599+#ifdef CONFIG_PAX_RANDMMAP
83600+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
83601+#endif
83602+
83603 mm->total_vm += pages;
83604 }
83605 #endif /* CONFIG_PROC_FS */
83606@@ -2104,7 +2119,7 @@ extern int unpoison_memory(unsigned long pfn);
83607 extern int sysctl_memory_failure_early_kill;
83608 extern int sysctl_memory_failure_recovery;
83609 extern void shake_page(struct page *p, int access);
83610-extern atomic_long_t num_poisoned_pages;
83611+extern atomic_long_unchecked_t num_poisoned_pages;
83612 extern int soft_offline_page(struct page *page, int flags);
83613
83614 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
83615@@ -2139,5 +2154,11 @@ void __init setup_nr_node_ids(void);
83616 static inline void setup_nr_node_ids(void) {}
83617 #endif
83618
83619+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83620+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
83621+#else
83622+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
83623+#endif
83624+
83625 #endif /* __KERNEL__ */
83626 #endif /* _LINUX_MM_H */
83627diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
83628index 6e0b286..90d9c0d 100644
83629--- a/include/linux/mm_types.h
83630+++ b/include/linux/mm_types.h
83631@@ -308,7 +308,9 @@ struct vm_area_struct {
83632 #ifdef CONFIG_NUMA
83633 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
83634 #endif
83635-};
83636+
83637+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
83638+} __randomize_layout;
83639
83640 struct core_thread {
83641 struct task_struct *task;
83642@@ -454,7 +456,25 @@ struct mm_struct {
83643 bool tlb_flush_pending;
83644 #endif
83645 struct uprobes_state uprobes_state;
83646-};
83647+
83648+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
83649+ unsigned long pax_flags;
83650+#endif
83651+
83652+#ifdef CONFIG_PAX_DLRESOLVE
83653+ unsigned long call_dl_resolve;
83654+#endif
83655+
83656+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
83657+ unsigned long call_syscall;
83658+#endif
83659+
83660+#ifdef CONFIG_PAX_ASLR
83661+ unsigned long delta_mmap; /* randomized offset */
83662+ unsigned long delta_stack; /* randomized offset */
83663+#endif
83664+
83665+} __randomize_layout;
83666
83667 static inline void mm_init_cpumask(struct mm_struct *mm)
83668 {
83669diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
83670index c5d5278..f0b68c8 100644
83671--- a/include/linux/mmiotrace.h
83672+++ b/include/linux/mmiotrace.h
83673@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
83674 /* Called from ioremap.c */
83675 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
83676 void __iomem *addr);
83677-extern void mmiotrace_iounmap(volatile void __iomem *addr);
83678+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
83679
83680 /* For anyone to insert markers. Remember trailing newline. */
83681 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
83682@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
83683 {
83684 }
83685
83686-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
83687+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
83688 {
83689 }
83690
83691diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
83692index 318df70..b74ec01 100644
83693--- a/include/linux/mmzone.h
83694+++ b/include/linux/mmzone.h
83695@@ -518,7 +518,7 @@ struct zone {
83696
83697 ZONE_PADDING(_pad3_)
83698 /* Zone statistics */
83699- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83700+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83701 } ____cacheline_internodealigned_in_smp;
83702
83703 typedef enum {
83704diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
83705index 44eeef0..a92d3f9 100644
83706--- a/include/linux/mod_devicetable.h
83707+++ b/include/linux/mod_devicetable.h
83708@@ -139,7 +139,7 @@ struct usb_device_id {
83709 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
83710 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
83711
83712-#define HID_ANY_ID (~0)
83713+#define HID_ANY_ID (~0U)
83714 #define HID_BUS_ANY 0xffff
83715 #define HID_GROUP_ANY 0x0000
83716
83717@@ -475,7 +475,7 @@ struct dmi_system_id {
83718 const char *ident;
83719 struct dmi_strmatch matches[4];
83720 void *driver_data;
83721-};
83722+} __do_const;
83723 /*
83724 * struct dmi_device_id appears during expansion of
83725 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
83726diff --git a/include/linux/module.h b/include/linux/module.h
83727index 71f282a..b2387e2 100644
83728--- a/include/linux/module.h
83729+++ b/include/linux/module.h
83730@@ -17,9 +17,11 @@
83731 #include <linux/moduleparam.h>
83732 #include <linux/jump_label.h>
83733 #include <linux/export.h>
83734+#include <linux/fs.h>
83735
83736 #include <linux/percpu.h>
83737 #include <asm/module.h>
83738+#include <asm/pgtable.h>
83739
83740 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
83741 #define MODULE_SIG_STRING "~Module signature appended~\n"
83742@@ -42,7 +44,7 @@ struct module_kobject {
83743 struct kobject *drivers_dir;
83744 struct module_param_attrs *mp;
83745 struct completion *kobj_completion;
83746-};
83747+} __randomize_layout;
83748
83749 struct module_attribute {
83750 struct attribute attr;
83751@@ -54,12 +56,13 @@ struct module_attribute {
83752 int (*test)(struct module *);
83753 void (*free)(struct module *);
83754 };
83755+typedef struct module_attribute __no_const module_attribute_no_const;
83756
83757 struct module_version_attribute {
83758 struct module_attribute mattr;
83759 const char *module_name;
83760 const char *version;
83761-} __attribute__ ((__aligned__(sizeof(void *))));
83762+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
83763
83764 extern ssize_t __modver_version_show(struct module_attribute *,
83765 struct module_kobject *, char *);
83766@@ -235,7 +238,7 @@ struct module {
83767
83768 /* Sysfs stuff. */
83769 struct module_kobject mkobj;
83770- struct module_attribute *modinfo_attrs;
83771+ module_attribute_no_const *modinfo_attrs;
83772 const char *version;
83773 const char *srcversion;
83774 struct kobject *holders_dir;
83775@@ -284,19 +287,16 @@ struct module {
83776 int (*init)(void);
83777
83778 /* If this is non-NULL, vfree after init() returns */
83779- void *module_init;
83780+ void *module_init_rx, *module_init_rw;
83781
83782 /* Here is the actual code + data, vfree'd on unload. */
83783- void *module_core;
83784+ void *module_core_rx, *module_core_rw;
83785
83786 /* Here are the sizes of the init and core sections */
83787- unsigned int init_size, core_size;
83788+ unsigned int init_size_rw, core_size_rw;
83789
83790 /* The size of the executable code in each section. */
83791- unsigned int init_text_size, core_text_size;
83792-
83793- /* Size of RO sections of the module (text+rodata) */
83794- unsigned int init_ro_size, core_ro_size;
83795+ unsigned int init_size_rx, core_size_rx;
83796
83797 /* Arch-specific module values */
83798 struct mod_arch_specific arch;
83799@@ -352,6 +352,10 @@ struct module {
83800 #ifdef CONFIG_EVENT_TRACING
83801 struct ftrace_event_call **trace_events;
83802 unsigned int num_trace_events;
83803+ struct file_operations trace_id;
83804+ struct file_operations trace_enable;
83805+ struct file_operations trace_format;
83806+ struct file_operations trace_filter;
83807 #endif
83808 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
83809 unsigned int num_ftrace_callsites;
83810@@ -375,7 +379,7 @@ struct module {
83811 ctor_fn_t *ctors;
83812 unsigned int num_ctors;
83813 #endif
83814-};
83815+} __randomize_layout;
83816 #ifndef MODULE_ARCH_INIT
83817 #define MODULE_ARCH_INIT {}
83818 #endif
83819@@ -396,18 +400,48 @@ bool is_module_address(unsigned long addr);
83820 bool is_module_percpu_address(unsigned long addr);
83821 bool is_module_text_address(unsigned long addr);
83822
83823+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
83824+{
83825+
83826+#ifdef CONFIG_PAX_KERNEXEC
83827+ if (ktla_ktva(addr) >= (unsigned long)start &&
83828+ ktla_ktva(addr) < (unsigned long)start + size)
83829+ return 1;
83830+#endif
83831+
83832+ return ((void *)addr >= start && (void *)addr < start + size);
83833+}
83834+
83835+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
83836+{
83837+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
83838+}
83839+
83840+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
83841+{
83842+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
83843+}
83844+
83845+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
83846+{
83847+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
83848+}
83849+
83850+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
83851+{
83852+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
83853+}
83854+
83855 static inline bool within_module_core(unsigned long addr,
83856 const struct module *mod)
83857 {
83858- return (unsigned long)mod->module_core <= addr &&
83859- addr < (unsigned long)mod->module_core + mod->core_size;
83860+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
83861 }
83862
83863 static inline bool within_module_init(unsigned long addr,
83864 const struct module *mod)
83865 {
83866- return (unsigned long)mod->module_init <= addr &&
83867- addr < (unsigned long)mod->module_init + mod->init_size;
83868+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
83869 }
83870
83871 static inline bool within_module(unsigned long addr, const struct module *mod)
83872diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
83873index 7eeb9bb..68f37e0 100644
83874--- a/include/linux/moduleloader.h
83875+++ b/include/linux/moduleloader.h
83876@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
83877 sections. Returns NULL on failure. */
83878 void *module_alloc(unsigned long size);
83879
83880+#ifdef CONFIG_PAX_KERNEXEC
83881+void *module_alloc_exec(unsigned long size);
83882+#else
83883+#define module_alloc_exec(x) module_alloc(x)
83884+#endif
83885+
83886 /* Free memory returned from module_alloc. */
83887 void module_free(struct module *mod, void *module_region);
83888
83889+#ifdef CONFIG_PAX_KERNEXEC
83890+void module_free_exec(struct module *mod, void *module_region);
83891+#else
83892+#define module_free_exec(x, y) module_free((x), (y))
83893+#endif
83894+
83895 /*
83896 * Apply the given relocation to the (simplified) ELF. Return -error
83897 * or 0.
83898@@ -45,8 +57,10 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
83899 unsigned int relsec,
83900 struct module *me)
83901 {
83902+#ifdef CONFIG_MODULES
83903 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83904 module_name(me));
83905+#endif
83906 return -ENOEXEC;
83907 }
83908 #endif
83909@@ -68,8 +82,10 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
83910 unsigned int relsec,
83911 struct module *me)
83912 {
83913+#ifdef CONFIG_MODULES
83914 printk(KERN_ERR "module %s: REL relocation unsupported\n",
83915 module_name(me));
83916+#endif
83917 return -ENOEXEC;
83918 }
83919 #endif
83920diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
83921index 494f99e..5059f63 100644
83922--- a/include/linux/moduleparam.h
83923+++ b/include/linux/moduleparam.h
83924@@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
83925 * @len is usually just sizeof(string).
83926 */
83927 #define module_param_string(name, string, len, perm) \
83928- static const struct kparam_string __param_string_##name \
83929+ static const struct kparam_string __param_string_##name __used \
83930 = { len, string }; \
83931 __module_param_call(MODULE_PARAM_PREFIX, name, \
83932 &param_ops_string, \
83933@@ -437,7 +437,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
83934 */
83935 #define module_param_array_named(name, array, type, nump, perm) \
83936 param_check_##type(name, &(array)[0]); \
83937- static const struct kparam_array __param_arr_##name \
83938+ static const struct kparam_array __param_arr_##name __used \
83939 = { .max = ARRAY_SIZE(array), .num = nump, \
83940 .ops = &param_ops_##type, \
83941 .elemsize = sizeof(array[0]), .elem = array }; \
83942diff --git a/include/linux/mount.h b/include/linux/mount.h
83943index 9262e4b..0a45f98 100644
83944--- a/include/linux/mount.h
83945+++ b/include/linux/mount.h
83946@@ -66,7 +66,7 @@ struct vfsmount {
83947 struct dentry *mnt_root; /* root of the mounted tree */
83948 struct super_block *mnt_sb; /* pointer to superblock */
83949 int mnt_flags;
83950-};
83951+} __randomize_layout;
83952
83953 struct file; /* forward dec */
83954 struct path;
83955diff --git a/include/linux/namei.h b/include/linux/namei.h
83956index 492de72..1bddcd4 100644
83957--- a/include/linux/namei.h
83958+++ b/include/linux/namei.h
83959@@ -19,7 +19,7 @@ struct nameidata {
83960 unsigned seq, m_seq;
83961 int last_type;
83962 unsigned depth;
83963- char *saved_names[MAX_NESTED_LINKS + 1];
83964+ const char *saved_names[MAX_NESTED_LINKS + 1];
83965 };
83966
83967 /*
83968@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
83969
83970 extern void nd_jump_link(struct nameidata *nd, struct path *path);
83971
83972-static inline void nd_set_link(struct nameidata *nd, char *path)
83973+static inline void nd_set_link(struct nameidata *nd, const char *path)
83974 {
83975 nd->saved_names[nd->depth] = path;
83976 }
83977
83978-static inline char *nd_get_link(struct nameidata *nd)
83979+static inline const char *nd_get_link(const struct nameidata *nd)
83980 {
83981 return nd->saved_names[nd->depth];
83982 }
83983diff --git a/include/linux/net.h b/include/linux/net.h
83984index 17d8339..81656c0 100644
83985--- a/include/linux/net.h
83986+++ b/include/linux/net.h
83987@@ -192,7 +192,7 @@ struct net_proto_family {
83988 int (*create)(struct net *net, struct socket *sock,
83989 int protocol, int kern);
83990 struct module *owner;
83991-};
83992+} __do_const;
83993
83994 struct iovec;
83995 struct kvec;
83996diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
83997index c8e388e..5d8cd9b 100644
83998--- a/include/linux/netdevice.h
83999+++ b/include/linux/netdevice.h
84000@@ -1147,6 +1147,7 @@ struct net_device_ops {
84001 void *priv);
84002 int (*ndo_get_lock_subclass)(struct net_device *dev);
84003 };
84004+typedef struct net_device_ops __no_const net_device_ops_no_const;
84005
84006 /**
84007 * enum net_device_priv_flags - &struct net_device priv_flags
84008@@ -1485,10 +1486,10 @@ struct net_device {
84009
84010 struct net_device_stats stats;
84011
84012- atomic_long_t rx_dropped;
84013- atomic_long_t tx_dropped;
84014+ atomic_long_unchecked_t rx_dropped;
84015+ atomic_long_unchecked_t tx_dropped;
84016
84017- atomic_t carrier_changes;
84018+ atomic_unchecked_t carrier_changes;
84019
84020 #ifdef CONFIG_WIRELESS_EXT
84021 const struct iw_handler_def * wireless_handlers;
84022diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
84023index 2517ece..0bbfcfb 100644
84024--- a/include/linux/netfilter.h
84025+++ b/include/linux/netfilter.h
84026@@ -85,7 +85,7 @@ struct nf_sockopt_ops {
84027 #endif
84028 /* Use the module struct to lock set/get code in place */
84029 struct module *owner;
84030-};
84031+} __do_const;
84032
84033 /* Function to register/unregister hook points. */
84034 int nf_register_hook(struct nf_hook_ops *reg);
84035diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
84036index e955d47..04a5338 100644
84037--- a/include/linux/netfilter/nfnetlink.h
84038+++ b/include/linux/netfilter/nfnetlink.h
84039@@ -19,7 +19,7 @@ struct nfnl_callback {
84040 const struct nlattr * const cda[]);
84041 const struct nla_policy *policy; /* netlink attribute policy */
84042 const u_int16_t attr_count; /* number of nlattr's */
84043-};
84044+} __do_const;
84045
84046 struct nfnetlink_subsystem {
84047 const char *name;
84048diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
84049new file mode 100644
84050index 0000000..33f4af8
84051--- /dev/null
84052+++ b/include/linux/netfilter/xt_gradm.h
84053@@ -0,0 +1,9 @@
84054+#ifndef _LINUX_NETFILTER_XT_GRADM_H
84055+#define _LINUX_NETFILTER_XT_GRADM_H 1
84056+
84057+struct xt_gradm_mtinfo {
84058+ __u16 flags;
84059+ __u16 invflags;
84060+};
84061+
84062+#endif
84063diff --git a/include/linux/nls.h b/include/linux/nls.h
84064index 520681b..2b7fabb 100644
84065--- a/include/linux/nls.h
84066+++ b/include/linux/nls.h
84067@@ -31,7 +31,7 @@ struct nls_table {
84068 const unsigned char *charset2upper;
84069 struct module *owner;
84070 struct nls_table *next;
84071-};
84072+} __do_const;
84073
84074 /* this value hold the maximum octet of charset */
84075 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
84076@@ -46,7 +46,7 @@ enum utf16_endian {
84077 /* nls_base.c */
84078 extern int __register_nls(struct nls_table *, struct module *);
84079 extern int unregister_nls(struct nls_table *);
84080-extern struct nls_table *load_nls(char *);
84081+extern struct nls_table *load_nls(const char *);
84082 extern void unload_nls(struct nls_table *);
84083 extern struct nls_table *load_nls_default(void);
84084 #define register_nls(nls) __register_nls((nls), THIS_MODULE)
84085diff --git a/include/linux/notifier.h b/include/linux/notifier.h
84086index d14a4c3..a078786 100644
84087--- a/include/linux/notifier.h
84088+++ b/include/linux/notifier.h
84089@@ -54,7 +54,8 @@ struct notifier_block {
84090 notifier_fn_t notifier_call;
84091 struct notifier_block __rcu *next;
84092 int priority;
84093-};
84094+} __do_const;
84095+typedef struct notifier_block __no_const notifier_block_no_const;
84096
84097 struct atomic_notifier_head {
84098 spinlock_t lock;
84099diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
84100index b2a0f15..4d7da32 100644
84101--- a/include/linux/oprofile.h
84102+++ b/include/linux/oprofile.h
84103@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
84104 int oprofilefs_create_ro_ulong(struct dentry * root,
84105 char const * name, ulong * val);
84106
84107-/** Create a file for read-only access to an atomic_t. */
84108+/** Create a file for read-only access to an atomic_unchecked_t. */
84109 int oprofilefs_create_ro_atomic(struct dentry * root,
84110- char const * name, atomic_t * val);
84111+ char const * name, atomic_unchecked_t * val);
84112
84113 /** create a directory */
84114 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
84115diff --git a/include/linux/padata.h b/include/linux/padata.h
84116index 4386946..f50c615 100644
84117--- a/include/linux/padata.h
84118+++ b/include/linux/padata.h
84119@@ -129,7 +129,7 @@ struct parallel_data {
84120 struct padata_serial_queue __percpu *squeue;
84121 atomic_t reorder_objects;
84122 atomic_t refcnt;
84123- atomic_t seq_nr;
84124+ atomic_unchecked_t seq_nr;
84125 struct padata_cpumask cpumask;
84126 spinlock_t lock ____cacheline_aligned;
84127 unsigned int processed;
84128diff --git a/include/linux/path.h b/include/linux/path.h
84129index d137218..be0c176 100644
84130--- a/include/linux/path.h
84131+++ b/include/linux/path.h
84132@@ -1,13 +1,15 @@
84133 #ifndef _LINUX_PATH_H
84134 #define _LINUX_PATH_H
84135
84136+#include <linux/compiler.h>
84137+
84138 struct dentry;
84139 struct vfsmount;
84140
84141 struct path {
84142 struct vfsmount *mnt;
84143 struct dentry *dentry;
84144-};
84145+} __randomize_layout;
84146
84147 extern void path_get(const struct path *);
84148 extern void path_put(const struct path *);
84149diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
84150index 5f2e559..7d59314 100644
84151--- a/include/linux/pci_hotplug.h
84152+++ b/include/linux/pci_hotplug.h
84153@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
84154 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
84155 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
84156 int (*reset_slot) (struct hotplug_slot *slot, int probe);
84157-};
84158+} __do_const;
84159+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
84160
84161 /**
84162 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
84163diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
84164index 707617a..28a2e7e 100644
84165--- a/include/linux/perf_event.h
84166+++ b/include/linux/perf_event.h
84167@@ -339,8 +339,8 @@ struct perf_event {
84168
84169 enum perf_event_active_state state;
84170 unsigned int attach_state;
84171- local64_t count;
84172- atomic64_t child_count;
84173+ local64_t count; /* PaX: fix it one day */
84174+ atomic64_unchecked_t child_count;
84175
84176 /*
84177 * These are the total time in nanoseconds that the event
84178@@ -391,8 +391,8 @@ struct perf_event {
84179 * These accumulate total time (in nanoseconds) that children
84180 * events have been enabled and running, respectively.
84181 */
84182- atomic64_t child_total_time_enabled;
84183- atomic64_t child_total_time_running;
84184+ atomic64_unchecked_t child_total_time_enabled;
84185+ atomic64_unchecked_t child_total_time_running;
84186
84187 /*
84188 * Protect attach/detach and child_list:
84189@@ -722,7 +722,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
84190 entry->ip[entry->nr++] = ip;
84191 }
84192
84193-extern int sysctl_perf_event_paranoid;
84194+extern int sysctl_perf_event_legitimately_concerned;
84195 extern int sysctl_perf_event_mlock;
84196 extern int sysctl_perf_event_sample_rate;
84197 extern int sysctl_perf_cpu_time_max_percent;
84198@@ -737,19 +737,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
84199 loff_t *ppos);
84200
84201
84202+static inline bool perf_paranoid_any(void)
84203+{
84204+ return sysctl_perf_event_legitimately_concerned > 2;
84205+}
84206+
84207 static inline bool perf_paranoid_tracepoint_raw(void)
84208 {
84209- return sysctl_perf_event_paranoid > -1;
84210+ return sysctl_perf_event_legitimately_concerned > -1;
84211 }
84212
84213 static inline bool perf_paranoid_cpu(void)
84214 {
84215- return sysctl_perf_event_paranoid > 0;
84216+ return sysctl_perf_event_legitimately_concerned > 0;
84217 }
84218
84219 static inline bool perf_paranoid_kernel(void)
84220 {
84221- return sysctl_perf_event_paranoid > 1;
84222+ return sysctl_perf_event_legitimately_concerned > 1;
84223 }
84224
84225 extern void perf_event_init(void);
84226@@ -880,7 +885,7 @@ struct perf_pmu_events_attr {
84227 struct device_attribute attr;
84228 u64 id;
84229 const char *event_str;
84230-};
84231+} __do_const;
84232
84233 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
84234 static struct perf_pmu_events_attr _var = { \
84235diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
84236index 1997ffc..4f1f44d 100644
84237--- a/include/linux/pid_namespace.h
84238+++ b/include/linux/pid_namespace.h
84239@@ -44,7 +44,7 @@ struct pid_namespace {
84240 int hide_pid;
84241 int reboot; /* group exit code if this pidns was rebooted */
84242 unsigned int proc_inum;
84243-};
84244+} __randomize_layout;
84245
84246 extern struct pid_namespace init_pid_ns;
84247
84248diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
84249index eb8b8ac..62649e1 100644
84250--- a/include/linux/pipe_fs_i.h
84251+++ b/include/linux/pipe_fs_i.h
84252@@ -47,10 +47,10 @@ struct pipe_inode_info {
84253 struct mutex mutex;
84254 wait_queue_head_t wait;
84255 unsigned int nrbufs, curbuf, buffers;
84256- unsigned int readers;
84257- unsigned int writers;
84258- unsigned int files;
84259- unsigned int waiting_writers;
84260+ atomic_t readers;
84261+ atomic_t writers;
84262+ atomic_t files;
84263+ atomic_t waiting_writers;
84264 unsigned int r_counter;
84265 unsigned int w_counter;
84266 struct page *tmp_page;
84267diff --git a/include/linux/pm.h b/include/linux/pm.h
84268index 72c0fe0..26918ed 100644
84269--- a/include/linux/pm.h
84270+++ b/include/linux/pm.h
84271@@ -620,6 +620,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
84272 struct dev_pm_domain {
84273 struct dev_pm_ops ops;
84274 };
84275+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
84276
84277 /*
84278 * The PM_EVENT_ messages are also used by drivers implementing the legacy
84279diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
84280index ebc4c76..7fab7b0 100644
84281--- a/include/linux/pm_domain.h
84282+++ b/include/linux/pm_domain.h
84283@@ -44,11 +44,11 @@ struct gpd_dev_ops {
84284 int (*thaw_early)(struct device *dev);
84285 int (*thaw)(struct device *dev);
84286 bool (*active_wakeup)(struct device *dev);
84287-};
84288+} __no_const;
84289
84290 struct gpd_cpu_data {
84291 unsigned int saved_exit_latency;
84292- struct cpuidle_state *idle_state;
84293+ cpuidle_state_no_const *idle_state;
84294 };
84295
84296 struct generic_pm_domain {
84297diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
84298index 367f49b..d2f5a14 100644
84299--- a/include/linux/pm_runtime.h
84300+++ b/include/linux/pm_runtime.h
84301@@ -125,7 +125,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
84302
84303 static inline void pm_runtime_mark_last_busy(struct device *dev)
84304 {
84305- ACCESS_ONCE(dev->power.last_busy) = jiffies;
84306+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
84307 }
84308
84309 #else /* !CONFIG_PM_RUNTIME */
84310diff --git a/include/linux/pnp.h b/include/linux/pnp.h
84311index 195aafc..49a7bc2 100644
84312--- a/include/linux/pnp.h
84313+++ b/include/linux/pnp.h
84314@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
84315 struct pnp_fixup {
84316 char id[7];
84317 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
84318-};
84319+} __do_const;
84320
84321 /* config parameters */
84322 #define PNP_CONFIG_NORMAL 0x0001
84323diff --git a/include/linux/poison.h b/include/linux/poison.h
84324index 2110a81..13a11bb 100644
84325--- a/include/linux/poison.h
84326+++ b/include/linux/poison.h
84327@@ -19,8 +19,8 @@
84328 * under normal circumstances, used to verify that nobody uses
84329 * non-initialized list entries.
84330 */
84331-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
84332-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
84333+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
84334+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
84335
84336 /********** include/linux/timer.h **********/
84337 /*
84338diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
84339index d8b187c3..9a9257a 100644
84340--- a/include/linux/power/smartreflex.h
84341+++ b/include/linux/power/smartreflex.h
84342@@ -238,7 +238,7 @@ struct omap_sr_class_data {
84343 int (*notify)(struct omap_sr *sr, u32 status);
84344 u8 notify_flags;
84345 u8 class_type;
84346-};
84347+} __do_const;
84348
84349 /**
84350 * struct omap_sr_nvalue_table - Smartreflex n-target value info
84351diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
84352index 4ea1d37..80f4b33 100644
84353--- a/include/linux/ppp-comp.h
84354+++ b/include/linux/ppp-comp.h
84355@@ -84,7 +84,7 @@ struct compressor {
84356 struct module *owner;
84357 /* Extra skb space needed by the compressor algorithm */
84358 unsigned int comp_extra;
84359-};
84360+} __do_const;
84361
84362 /*
84363 * The return value from decompress routine is the length of the
84364diff --git a/include/linux/preempt.h b/include/linux/preempt.h
84365index de83b4e..c4b997d 100644
84366--- a/include/linux/preempt.h
84367+++ b/include/linux/preempt.h
84368@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
84369 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
84370 #endif
84371
84372+#define raw_preempt_count_add(val) __preempt_count_add(val)
84373+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
84374+
84375 #define __preempt_count_inc() __preempt_count_add(1)
84376 #define __preempt_count_dec() __preempt_count_sub(1)
84377
84378 #define preempt_count_inc() preempt_count_add(1)
84379+#define raw_preempt_count_inc() raw_preempt_count_add(1)
84380 #define preempt_count_dec() preempt_count_sub(1)
84381+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
84382
84383 #ifdef CONFIG_PREEMPT_COUNT
84384
84385@@ -41,6 +46,12 @@ do { \
84386 barrier(); \
84387 } while (0)
84388
84389+#define raw_preempt_disable() \
84390+do { \
84391+ raw_preempt_count_inc(); \
84392+ barrier(); \
84393+} while (0)
84394+
84395 #define sched_preempt_enable_no_resched() \
84396 do { \
84397 barrier(); \
84398@@ -49,6 +60,12 @@ do { \
84399
84400 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
84401
84402+#define raw_preempt_enable_no_resched() \
84403+do { \
84404+ barrier(); \
84405+ raw_preempt_count_dec(); \
84406+} while (0)
84407+
84408 #ifdef CONFIG_PREEMPT
84409 #define preempt_enable() \
84410 do { \
84411@@ -113,8 +130,10 @@ do { \
84412 * region.
84413 */
84414 #define preempt_disable() barrier()
84415+#define raw_preempt_disable() barrier()
84416 #define sched_preempt_enable_no_resched() barrier()
84417 #define preempt_enable_no_resched() barrier()
84418+#define raw_preempt_enable_no_resched() barrier()
84419 #define preempt_enable() barrier()
84420 #define preempt_check_resched() do { } while (0)
84421
84422@@ -128,11 +147,13 @@ do { \
84423 /*
84424 * Modules have no business playing preemption tricks.
84425 */
84426+#ifndef CONFIG_PAX_KERNEXEC
84427 #undef sched_preempt_enable_no_resched
84428 #undef preempt_enable_no_resched
84429 #undef preempt_enable_no_resched_notrace
84430 #undef preempt_check_resched
84431 #endif
84432+#endif
84433
84434 #define preempt_set_need_resched() \
84435 do { \
84436diff --git a/include/linux/printk.h b/include/linux/printk.h
84437index d78125f..7f36596 100644
84438--- a/include/linux/printk.h
84439+++ b/include/linux/printk.h
84440@@ -124,6 +124,8 @@ static inline __printf(1, 2) __cold
84441 void early_printk(const char *s, ...) { }
84442 #endif
84443
84444+extern int kptr_restrict;
84445+
84446 #ifdef CONFIG_PRINTK
84447 asmlinkage __printf(5, 0)
84448 int vprintk_emit(int facility, int level,
84449@@ -158,7 +160,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
84450
84451 extern int printk_delay_msec;
84452 extern int dmesg_restrict;
84453-extern int kptr_restrict;
84454
84455 extern void wake_up_klogd(void);
84456
84457diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
84458index 9d117f6..d832b31 100644
84459--- a/include/linux/proc_fs.h
84460+++ b/include/linux/proc_fs.h
84461@@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
84462 extern struct proc_dir_entry *proc_symlink(const char *,
84463 struct proc_dir_entry *, const char *);
84464 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
84465+extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
84466 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
84467 struct proc_dir_entry *, void *);
84468+extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
84469+ struct proc_dir_entry *, void *);
84470 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
84471 struct proc_dir_entry *);
84472
84473@@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
84474 return proc_create_data(name, mode, parent, proc_fops, NULL);
84475 }
84476
84477+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
84478+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
84479+{
84480+#ifdef CONFIG_GRKERNSEC_PROC_USER
84481+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
84482+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84483+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
84484+#else
84485+ return proc_create_data(name, mode, parent, proc_fops, NULL);
84486+#endif
84487+}
84488+
84489+
84490 extern void proc_set_size(struct proc_dir_entry *, loff_t);
84491 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
84492 extern void *PDE_DATA(const struct inode *);
84493@@ -56,8 +72,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
84494 struct proc_dir_entry *parent,const char *dest) { return NULL;}
84495 static inline struct proc_dir_entry *proc_mkdir(const char *name,
84496 struct proc_dir_entry *parent) {return NULL;}
84497+static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
84498+ struct proc_dir_entry *parent) { return NULL; }
84499 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
84500 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84501+static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
84502+ umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
84503 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
84504 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
84505 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
84506@@ -77,7 +97,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
84507 static inline struct proc_dir_entry *proc_net_mkdir(
84508 struct net *net, const char *name, struct proc_dir_entry *parent)
84509 {
84510- return proc_mkdir_data(name, 0, parent, net);
84511+ return proc_mkdir_data_restrict(name, 0, parent, net);
84512 }
84513
84514 #endif /* _LINUX_PROC_FS_H */
84515diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
84516index 34a1e10..70f6bde 100644
84517--- a/include/linux/proc_ns.h
84518+++ b/include/linux/proc_ns.h
84519@@ -14,7 +14,7 @@ struct proc_ns_operations {
84520 void (*put)(void *ns);
84521 int (*install)(struct nsproxy *nsproxy, void *ns);
84522 unsigned int (*inum)(void *ns);
84523-};
84524+} __do_const __randomize_layout;
84525
84526 struct proc_ns {
84527 void *ns;
84528diff --git a/include/linux/quota.h b/include/linux/quota.h
84529index 80d345a..9e89a9a 100644
84530--- a/include/linux/quota.h
84531+++ b/include/linux/quota.h
84532@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
84533
84534 extern bool qid_eq(struct kqid left, struct kqid right);
84535 extern bool qid_lt(struct kqid left, struct kqid right);
84536-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
84537+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
84538 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
84539 extern bool qid_valid(struct kqid qid);
84540
84541diff --git a/include/linux/random.h b/include/linux/random.h
84542index 57fbbff..2170304 100644
84543--- a/include/linux/random.h
84544+++ b/include/linux/random.h
84545@@ -9,9 +9,19 @@
84546 #include <uapi/linux/random.h>
84547
84548 extern void add_device_randomness(const void *, unsigned int);
84549+
84550+static inline void add_latent_entropy(void)
84551+{
84552+
84553+#ifdef LATENT_ENTROPY_PLUGIN
84554+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84555+#endif
84556+
84557+}
84558+
84559 extern void add_input_randomness(unsigned int type, unsigned int code,
84560- unsigned int value);
84561-extern void add_interrupt_randomness(int irq, int irq_flags);
84562+ unsigned int value) __latent_entropy;
84563+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
84564
84565 extern void get_random_bytes(void *buf, int nbytes);
84566 extern void get_random_bytes_arch(void *buf, int nbytes);
84567@@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
84568 extern const struct file_operations random_fops, urandom_fops;
84569 #endif
84570
84571-unsigned int get_random_int(void);
84572+unsigned int __intentional_overflow(-1) get_random_int(void);
84573 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
84574
84575-u32 prandom_u32(void);
84576+u32 prandom_u32(void) __intentional_overflow(-1);
84577 void prandom_bytes(void *buf, int nbytes);
84578 void prandom_seed(u32 seed);
84579 void prandom_reseed_late(void);
84580@@ -37,6 +47,11 @@ struct rnd_state {
84581 u32 prandom_u32_state(struct rnd_state *state);
84582 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
84583
84584+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
84585+{
84586+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
84587+}
84588+
84589 /**
84590 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
84591 * @ep_ro: right open interval endpoint
84592@@ -49,7 +64,7 @@ void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
84593 *
84594 * Returns: pseudo-random number in interval [0, ep_ro)
84595 */
84596-static inline u32 prandom_u32_max(u32 ep_ro)
84597+static inline u32 __intentional_overflow(-1) prandom_u32_max(u32 ep_ro)
84598 {
84599 return (u32)(((u64) prandom_u32() * ep_ro) >> 32);
84600 }
84601diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
84602index fea49b5..2ac22bb 100644
84603--- a/include/linux/rbtree_augmented.h
84604+++ b/include/linux/rbtree_augmented.h
84605@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
84606 old->rbaugmented = rbcompute(old); \
84607 } \
84608 rbstatic const struct rb_augment_callbacks rbname = { \
84609- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
84610+ .propagate = rbname ## _propagate, \
84611+ .copy = rbname ## _copy, \
84612+ .rotate = rbname ## _rotate \
84613 };
84614
84615
84616diff --git a/include/linux/rculist.h b/include/linux/rculist.h
84617index 372ad5e..d4373f8 100644
84618--- a/include/linux/rculist.h
84619+++ b/include/linux/rculist.h
84620@@ -29,8 +29,8 @@
84621 */
84622 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
84623 {
84624- ACCESS_ONCE(list->next) = list;
84625- ACCESS_ONCE(list->prev) = list;
84626+ ACCESS_ONCE_RW(list->next) = list;
84627+ ACCESS_ONCE_RW(list->prev) = list;
84628 }
84629
84630 /*
84631@@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
84632 struct list_head *prev, struct list_head *next);
84633 #endif
84634
84635+void __pax_list_add_rcu(struct list_head *new,
84636+ struct list_head *prev, struct list_head *next);
84637+
84638 /**
84639 * list_add_rcu - add a new entry to rcu-protected list
84640 * @new: new entry to be added
84641@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
84642 __list_add_rcu(new, head, head->next);
84643 }
84644
84645+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
84646+{
84647+ __pax_list_add_rcu(new, head, head->next);
84648+}
84649+
84650 /**
84651 * list_add_tail_rcu - add a new entry to rcu-protected list
84652 * @new: new entry to be added
84653@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
84654 __list_add_rcu(new, head->prev, head);
84655 }
84656
84657+static inline void pax_list_add_tail_rcu(struct list_head *new,
84658+ struct list_head *head)
84659+{
84660+ __pax_list_add_rcu(new, head->prev, head);
84661+}
84662+
84663 /**
84664 * list_del_rcu - deletes entry from list without re-initialization
84665 * @entry: the element to delete from the list.
84666@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
84667 entry->prev = LIST_POISON2;
84668 }
84669
84670+extern void pax_list_del_rcu(struct list_head *entry);
84671+
84672 /**
84673 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
84674 * @n: the element to delete from the hash list.
84675diff --git a/include/linux/reboot.h b/include/linux/reboot.h
84676index 48bf152..d38b785 100644
84677--- a/include/linux/reboot.h
84678+++ b/include/linux/reboot.h
84679@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
84680 */
84681
84682 extern void migrate_to_reboot_cpu(void);
84683-extern void machine_restart(char *cmd);
84684-extern void machine_halt(void);
84685-extern void machine_power_off(void);
84686+extern void machine_restart(char *cmd) __noreturn;
84687+extern void machine_halt(void) __noreturn;
84688+extern void machine_power_off(void) __noreturn;
84689
84690 extern void machine_shutdown(void);
84691 struct pt_regs;
84692@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
84693 */
84694
84695 extern void kernel_restart_prepare(char *cmd);
84696-extern void kernel_restart(char *cmd);
84697-extern void kernel_halt(void);
84698-extern void kernel_power_off(void);
84699+extern void kernel_restart(char *cmd) __noreturn;
84700+extern void kernel_halt(void) __noreturn;
84701+extern void kernel_power_off(void) __noreturn;
84702
84703 extern int C_A_D; /* for sysctl */
84704 void ctrl_alt_del(void);
84705@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
84706 * Emergency restart, callable from an interrupt handler.
84707 */
84708
84709-extern void emergency_restart(void);
84710+extern void emergency_restart(void) __noreturn;
84711 #include <asm/emergency-restart.h>
84712
84713 #endif /* _LINUX_REBOOT_H */
84714diff --git a/include/linux/regset.h b/include/linux/regset.h
84715index 8e0c9fe..ac4d221 100644
84716--- a/include/linux/regset.h
84717+++ b/include/linux/regset.h
84718@@ -161,7 +161,8 @@ struct user_regset {
84719 unsigned int align;
84720 unsigned int bias;
84721 unsigned int core_note_type;
84722-};
84723+} __do_const;
84724+typedef struct user_regset __no_const user_regset_no_const;
84725
84726 /**
84727 * struct user_regset_view - available regsets
84728diff --git a/include/linux/relay.h b/include/linux/relay.h
84729index d7c8359..818daf5 100644
84730--- a/include/linux/relay.h
84731+++ b/include/linux/relay.h
84732@@ -157,7 +157,7 @@ struct rchan_callbacks
84733 * The callback should return 0 if successful, negative if not.
84734 */
84735 int (*remove_buf_file)(struct dentry *dentry);
84736-};
84737+} __no_const;
84738
84739 /*
84740 * CONFIG_RELAY kernel API, kernel/relay.c
84741diff --git a/include/linux/rio.h b/include/linux/rio.h
84742index 6bda06f..bf39a9b 100644
84743--- a/include/linux/rio.h
84744+++ b/include/linux/rio.h
84745@@ -358,7 +358,7 @@ struct rio_ops {
84746 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
84747 u64 rstart, u32 size, u32 flags);
84748 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
84749-};
84750+} __no_const;
84751
84752 #define RIO_RESOURCE_MEM 0x00000100
84753 #define RIO_RESOURCE_DOORBELL 0x00000200
84754diff --git a/include/linux/rmap.h b/include/linux/rmap.h
84755index be57450..31cf65e 100644
84756--- a/include/linux/rmap.h
84757+++ b/include/linux/rmap.h
84758@@ -144,8 +144,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
84759 void anon_vma_init(void); /* create anon_vma_cachep */
84760 int anon_vma_prepare(struct vm_area_struct *);
84761 void unlink_anon_vmas(struct vm_area_struct *);
84762-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
84763-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
84764+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
84765+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
84766
84767 static inline void anon_vma_merge(struct vm_area_struct *vma,
84768 struct vm_area_struct *next)
84769diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
84770index ed8f9e7..999bc96 100644
84771--- a/include/linux/scatterlist.h
84772+++ b/include/linux/scatterlist.h
84773@@ -1,6 +1,7 @@
84774 #ifndef _LINUX_SCATTERLIST_H
84775 #define _LINUX_SCATTERLIST_H
84776
84777+#include <linux/sched.h>
84778 #include <linux/string.h>
84779 #include <linux/bug.h>
84780 #include <linux/mm.h>
84781@@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
84782 #ifdef CONFIG_DEBUG_SG
84783 BUG_ON(!virt_addr_valid(buf));
84784 #endif
84785+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84786+ if (object_starts_on_stack(buf)) {
84787+ void *adjbuf = buf - current->stack + current->lowmem_stack;
84788+ sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
84789+ } else
84790+#endif
84791 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
84792 }
84793
84794diff --git a/include/linux/sched.h b/include/linux/sched.h
84795index 2b1d9e9..10ba706 100644
84796--- a/include/linux/sched.h
84797+++ b/include/linux/sched.h
84798@@ -132,6 +132,7 @@ struct fs_struct;
84799 struct perf_event_context;
84800 struct blk_plug;
84801 struct filename;
84802+struct linux_binprm;
84803
84804 #define VMACACHE_BITS 2
84805 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
84806@@ -374,7 +375,7 @@ extern char __sched_text_start[], __sched_text_end[];
84807 extern int in_sched_functions(unsigned long addr);
84808
84809 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
84810-extern signed long schedule_timeout(signed long timeout);
84811+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
84812 extern signed long schedule_timeout_interruptible(signed long timeout);
84813 extern signed long schedule_timeout_killable(signed long timeout);
84814 extern signed long schedule_timeout_uninterruptible(signed long timeout);
84815@@ -385,6 +386,19 @@ struct nsproxy;
84816 struct user_namespace;
84817
84818 #ifdef CONFIG_MMU
84819+
84820+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
84821+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
84822+#else
84823+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
84824+{
84825+ return 0;
84826+}
84827+#endif
84828+
84829+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
84830+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
84831+
84832 extern void arch_pick_mmap_layout(struct mm_struct *mm);
84833 extern unsigned long
84834 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
84835@@ -682,6 +696,17 @@ struct signal_struct {
84836 #ifdef CONFIG_TASKSTATS
84837 struct taskstats *stats;
84838 #endif
84839+
84840+#ifdef CONFIG_GRKERNSEC
84841+ u32 curr_ip;
84842+ u32 saved_ip;
84843+ u32 gr_saddr;
84844+ u32 gr_daddr;
84845+ u16 gr_sport;
84846+ u16 gr_dport;
84847+ u8 used_accept:1;
84848+#endif
84849+
84850 #ifdef CONFIG_AUDIT
84851 unsigned audit_tty;
84852 unsigned audit_tty_log_passwd;
84853@@ -708,7 +733,7 @@ struct signal_struct {
84854 struct mutex cred_guard_mutex; /* guard against foreign influences on
84855 * credential calculations
84856 * (notably. ptrace) */
84857-};
84858+} __randomize_layout;
84859
84860 /*
84861 * Bits in flags field of signal_struct.
84862@@ -761,6 +786,14 @@ struct user_struct {
84863 struct key *session_keyring; /* UID's default session keyring */
84864 #endif
84865
84866+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
84867+ unsigned char kernel_banned;
84868+#endif
84869+#ifdef CONFIG_GRKERNSEC_BRUTE
84870+ unsigned char suid_banned;
84871+ unsigned long suid_ban_expires;
84872+#endif
84873+
84874 /* Hash table maintenance information */
84875 struct hlist_node uidhash_node;
84876 kuid_t uid;
84877@@ -768,7 +801,7 @@ struct user_struct {
84878 #ifdef CONFIG_PERF_EVENTS
84879 atomic_long_t locked_vm;
84880 #endif
84881-};
84882+} __randomize_layout;
84883
84884 extern int uids_sysfs_init(void);
84885
84886@@ -1224,6 +1257,9 @@ enum perf_event_task_context {
84887 struct task_struct {
84888 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
84889 void *stack;
84890+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
84891+ void *lowmem_stack;
84892+#endif
84893 atomic_t usage;
84894 unsigned int flags; /* per process flags, defined below */
84895 unsigned int ptrace;
84896@@ -1345,8 +1381,8 @@ struct task_struct {
84897 struct list_head thread_node;
84898
84899 struct completion *vfork_done; /* for vfork() */
84900- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
84901- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84902+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
84903+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
84904
84905 cputime_t utime, stime, utimescaled, stimescaled;
84906 cputime_t gtime;
84907@@ -1371,11 +1407,6 @@ struct task_struct {
84908 struct task_cputime cputime_expires;
84909 struct list_head cpu_timers[3];
84910
84911-/* process credentials */
84912- const struct cred __rcu *real_cred; /* objective and real subjective task
84913- * credentials (COW) */
84914- const struct cred __rcu *cred; /* effective (overridable) subjective task
84915- * credentials (COW) */
84916 char comm[TASK_COMM_LEN]; /* executable name excluding path
84917 - access with [gs]et_task_comm (which lock
84918 it with task_lock())
84919@@ -1393,6 +1424,10 @@ struct task_struct {
84920 #endif
84921 /* CPU-specific state of this task */
84922 struct thread_struct thread;
84923+/* thread_info moved to task_struct */
84924+#ifdef CONFIG_X86
84925+ struct thread_info tinfo;
84926+#endif
84927 /* filesystem information */
84928 struct fs_struct *fs;
84929 /* open file information */
84930@@ -1467,6 +1502,10 @@ struct task_struct {
84931 gfp_t lockdep_reclaim_gfp;
84932 #endif
84933
84934+/* process credentials */
84935+ const struct cred __rcu *real_cred; /* objective and real subjective task
84936+ * credentials (COW) */
84937+
84938 /* journalling filesystem info */
84939 void *journal_info;
84940
84941@@ -1505,6 +1544,10 @@ struct task_struct {
84942 /* cg_list protected by css_set_lock and tsk->alloc_lock */
84943 struct list_head cg_list;
84944 #endif
84945+
84946+ const struct cred __rcu *cred; /* effective (overridable) subjective task
84947+ * credentials (COW) */
84948+
84949 #ifdef CONFIG_FUTEX
84950 struct robust_list_head __user *robust_list;
84951 #ifdef CONFIG_COMPAT
84952@@ -1644,7 +1687,78 @@ struct task_struct {
84953 unsigned int sequential_io;
84954 unsigned int sequential_io_avg;
84955 #endif
84956-};
84957+
84958+#ifdef CONFIG_GRKERNSEC
84959+ /* grsecurity */
84960+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
84961+ u64 exec_id;
84962+#endif
84963+#ifdef CONFIG_GRKERNSEC_SETXID
84964+ const struct cred *delayed_cred;
84965+#endif
84966+ struct dentry *gr_chroot_dentry;
84967+ struct acl_subject_label *acl;
84968+ struct acl_subject_label *tmpacl;
84969+ struct acl_role_label *role;
84970+ struct file *exec_file;
84971+ unsigned long brute_expires;
84972+ u16 acl_role_id;
84973+ u8 inherited;
84974+ /* is this the task that authenticated to the special role */
84975+ u8 acl_sp_role;
84976+ u8 is_writable;
84977+ u8 brute;
84978+ u8 gr_is_chrooted;
84979+#endif
84980+
84981+} __randomize_layout;
84982+
84983+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
84984+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
84985+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
84986+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
84987+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
84988+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
84989+
84990+#ifdef CONFIG_PAX_SOFTMODE
84991+extern int pax_softmode;
84992+#endif
84993+
84994+extern int pax_check_flags(unsigned long *);
84995+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
84996+
84997+/* if tsk != current then task_lock must be held on it */
84998+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
84999+static inline unsigned long pax_get_flags(struct task_struct *tsk)
85000+{
85001+ if (likely(tsk->mm))
85002+ return tsk->mm->pax_flags;
85003+ else
85004+ return 0UL;
85005+}
85006+
85007+/* if tsk != current then task_lock must be held on it */
85008+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
85009+{
85010+ if (likely(tsk->mm)) {
85011+ tsk->mm->pax_flags = flags;
85012+ return 0;
85013+ }
85014+ return -EINVAL;
85015+}
85016+#endif
85017+
85018+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
85019+extern void pax_set_initial_flags(struct linux_binprm *bprm);
85020+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
85021+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
85022+#endif
85023+
85024+struct path;
85025+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
85026+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
85027+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
85028+extern void pax_report_refcount_overflow(struct pt_regs *regs);
85029
85030 /* Future-safe accessor for struct task_struct's cpus_allowed. */
85031 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
85032@@ -1726,7 +1840,7 @@ struct pid_namespace;
85033 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
85034 struct pid_namespace *ns);
85035
85036-static inline pid_t task_pid_nr(struct task_struct *tsk)
85037+static inline pid_t task_pid_nr(const struct task_struct *tsk)
85038 {
85039 return tsk->pid;
85040 }
85041@@ -2097,6 +2211,25 @@ extern u64 sched_clock_cpu(int cpu);
85042
85043 extern void sched_clock_init(void);
85044
85045+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
85046+static inline void populate_stack(void)
85047+{
85048+ struct task_struct *curtask = current;
85049+ int c;
85050+ int *ptr = curtask->stack;
85051+ int *end = curtask->stack + THREAD_SIZE;
85052+
85053+ while (ptr < end) {
85054+ c = *(volatile int *)ptr;
85055+ ptr += PAGE_SIZE/sizeof(int);
85056+ }
85057+}
85058+#else
85059+static inline void populate_stack(void)
85060+{
85061+}
85062+#endif
85063+
85064 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
85065 static inline void sched_clock_tick(void)
85066 {
85067@@ -2230,7 +2363,9 @@ void yield(void);
85068 extern struct exec_domain default_exec_domain;
85069
85070 union thread_union {
85071+#ifndef CONFIG_X86
85072 struct thread_info thread_info;
85073+#endif
85074 unsigned long stack[THREAD_SIZE/sizeof(long)];
85075 };
85076
85077@@ -2263,6 +2398,7 @@ extern struct pid_namespace init_pid_ns;
85078 */
85079
85080 extern struct task_struct *find_task_by_vpid(pid_t nr);
85081+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
85082 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
85083 struct pid_namespace *ns);
85084
85085@@ -2427,7 +2563,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
85086 extern void exit_itimers(struct signal_struct *);
85087 extern void flush_itimer_signals(void);
85088
85089-extern void do_group_exit(int);
85090+extern __noreturn void do_group_exit(int);
85091
85092 extern int do_execve(struct filename *,
85093 const char __user * const __user *,
85094@@ -2642,9 +2778,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
85095
85096 #endif
85097
85098-static inline int object_is_on_stack(void *obj)
85099+static inline int object_starts_on_stack(const void *obj)
85100 {
85101- void *stack = task_stack_page(current);
85102+ const void *stack = task_stack_page(current);
85103
85104 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
85105 }
85106diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
85107index 596a0e0..bea77ec 100644
85108--- a/include/linux/sched/sysctl.h
85109+++ b/include/linux/sched/sysctl.h
85110@@ -34,6 +34,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
85111 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
85112
85113 extern int sysctl_max_map_count;
85114+extern unsigned long sysctl_heap_stack_gap;
85115
85116 extern unsigned int sysctl_sched_latency;
85117 extern unsigned int sysctl_sched_min_granularity;
85118diff --git a/include/linux/security.h b/include/linux/security.h
85119index 623f90e..90b39da 100644
85120--- a/include/linux/security.h
85121+++ b/include/linux/security.h
85122@@ -27,6 +27,7 @@
85123 #include <linux/slab.h>
85124 #include <linux/err.h>
85125 #include <linux/string.h>
85126+#include <linux/grsecurity.h>
85127
85128 struct linux_binprm;
85129 struct cred;
85130@@ -116,8 +117,6 @@ struct seq_file;
85131
85132 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
85133
85134-void reset_security_ops(void);
85135-
85136 #ifdef CONFIG_MMU
85137 extern unsigned long mmap_min_addr;
85138 extern unsigned long dac_mmap_min_addr;
85139@@ -1729,7 +1728,7 @@ struct security_operations {
85140 struct audit_context *actx);
85141 void (*audit_rule_free) (void *lsmrule);
85142 #endif /* CONFIG_AUDIT */
85143-};
85144+} __randomize_layout;
85145
85146 /* prototypes */
85147 extern int security_init(void);
85148diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
85149index dc368b8..e895209 100644
85150--- a/include/linux/semaphore.h
85151+++ b/include/linux/semaphore.h
85152@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
85153 }
85154
85155 extern void down(struct semaphore *sem);
85156-extern int __must_check down_interruptible(struct semaphore *sem);
85157+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
85158 extern int __must_check down_killable(struct semaphore *sem);
85159 extern int __must_check down_trylock(struct semaphore *sem);
85160 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
85161diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
85162index 52e0097..383f21d 100644
85163--- a/include/linux/seq_file.h
85164+++ b/include/linux/seq_file.h
85165@@ -27,6 +27,9 @@ struct seq_file {
85166 struct mutex lock;
85167 const struct seq_operations *op;
85168 int poll_event;
85169+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
85170+ u64 exec_id;
85171+#endif
85172 #ifdef CONFIG_USER_NS
85173 struct user_namespace *user_ns;
85174 #endif
85175@@ -39,6 +42,7 @@ struct seq_operations {
85176 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
85177 int (*show) (struct seq_file *m, void *v);
85178 };
85179+typedef struct seq_operations __no_const seq_operations_no_const;
85180
85181 #define SEQ_SKIP 1
85182
85183@@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
85184
85185 char *mangle_path(char *s, const char *p, const char *esc);
85186 int seq_open(struct file *, const struct seq_operations *);
85187+int seq_open_restrict(struct file *, const struct seq_operations *);
85188 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
85189 loff_t seq_lseek(struct file *, loff_t, int);
85190 int seq_release(struct inode *, struct file *);
85191@@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
85192 }
85193
85194 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
85195+int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
85196 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
85197 int single_release(struct inode *, struct file *);
85198 void *__seq_open_private(struct file *, const struct seq_operations *, int);
85199diff --git a/include/linux/shm.h b/include/linux/shm.h
85200index 6fb8016..ab4465e 100644
85201--- a/include/linux/shm.h
85202+++ b/include/linux/shm.h
85203@@ -22,6 +22,10 @@ struct shmid_kernel /* private to the kernel */
85204 /* The task created the shm object. NULL if the task is dead. */
85205 struct task_struct *shm_creator;
85206 struct list_head shm_clist; /* list by creator */
85207+#ifdef CONFIG_GRKERNSEC
85208+ u64 shm_createtime;
85209+ pid_t shm_lapid;
85210+#endif
85211 };
85212
85213 /* shm_mode upper byte flags */
85214diff --git a/include/linux/signal.h b/include/linux/signal.h
85215index 750196f..ae7a3a4 100644
85216--- a/include/linux/signal.h
85217+++ b/include/linux/signal.h
85218@@ -292,7 +292,7 @@ static inline void allow_signal(int sig)
85219 * know it'll be handled, so that they don't get converted to
85220 * SIGKILL or just silently dropped.
85221 */
85222- kernel_sigaction(sig, (__force __sighandler_t)2);
85223+ kernel_sigaction(sig, (__force_user __sighandler_t)2);
85224 }
85225
85226 static inline void disallow_signal(int sig)
85227diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
85228index abde271..bc9ece1 100644
85229--- a/include/linux/skbuff.h
85230+++ b/include/linux/skbuff.h
85231@@ -728,7 +728,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
85232 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
85233 int node);
85234 struct sk_buff *build_skb(void *data, unsigned int frag_size);
85235-static inline struct sk_buff *alloc_skb(unsigned int size,
85236+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
85237 gfp_t priority)
85238 {
85239 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
85240@@ -1845,7 +1845,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
85241 return skb->inner_transport_header - skb->inner_network_header;
85242 }
85243
85244-static inline int skb_network_offset(const struct sk_buff *skb)
85245+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
85246 {
85247 return skb_network_header(skb) - skb->data;
85248 }
85249@@ -1917,7 +1917,7 @@ static inline void skb_pop_rcv_encapsulation(struct sk_buff *skb)
85250 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
85251 */
85252 #ifndef NET_SKB_PAD
85253-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
85254+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
85255 #endif
85256
85257 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
85258@@ -2524,7 +2524,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
85259 int *err);
85260 unsigned int datagram_poll(struct file *file, struct socket *sock,
85261 struct poll_table_struct *wait);
85262-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85263+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
85264 struct iovec *to, int size);
85265 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
85266 struct iovec *iov);
85267@@ -2918,6 +2918,9 @@ static inline void nf_reset(struct sk_buff *skb)
85268 nf_bridge_put(skb->nf_bridge);
85269 skb->nf_bridge = NULL;
85270 #endif
85271+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
85272+ skb->nf_trace = 0;
85273+#endif
85274 }
85275
85276 static inline void nf_reset_trace(struct sk_buff *skb)
85277diff --git a/include/linux/slab.h b/include/linux/slab.h
85278index 1d9abb7..b1e8b10 100644
85279--- a/include/linux/slab.h
85280+++ b/include/linux/slab.h
85281@@ -14,15 +14,29 @@
85282 #include <linux/gfp.h>
85283 #include <linux/types.h>
85284 #include <linux/workqueue.h>
85285-
85286+#include <linux/err.h>
85287
85288 /*
85289 * Flags to pass to kmem_cache_create().
85290 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
85291 */
85292 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
85293+
85294+#ifdef CONFIG_PAX_USERCOPY_SLABS
85295+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
85296+#else
85297+#define SLAB_USERCOPY 0x00000000UL
85298+#endif
85299+
85300 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
85301 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
85302+
85303+#ifdef CONFIG_PAX_MEMORY_SANITIZE
85304+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
85305+#else
85306+#define SLAB_NO_SANITIZE 0x00000000UL
85307+#endif
85308+
85309 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
85310 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
85311 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
85312@@ -98,10 +112,13 @@
85313 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
85314 * Both make kfree a no-op.
85315 */
85316-#define ZERO_SIZE_PTR ((void *)16)
85317+#define ZERO_SIZE_PTR \
85318+({ \
85319+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
85320+ (void *)(-MAX_ERRNO-1L); \
85321+})
85322
85323-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
85324- (unsigned long)ZERO_SIZE_PTR)
85325+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
85326
85327 #include <linux/kmemleak.h>
85328
85329@@ -144,6 +161,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
85330 void kfree(const void *);
85331 void kzfree(const void *);
85332 size_t ksize(const void *);
85333+const char *check_heap_object(const void *ptr, unsigned long n);
85334+bool is_usercopy_object(const void *ptr);
85335
85336 /*
85337 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
85338@@ -176,7 +195,7 @@ struct kmem_cache {
85339 unsigned int align; /* Alignment as calculated */
85340 unsigned long flags; /* Active flags on the slab */
85341 const char *name; /* Slab name for sysfs */
85342- int refcount; /* Use counter */
85343+ atomic_t refcount; /* Use counter */
85344 void (*ctor)(void *); /* Called on object slot creation */
85345 struct list_head list; /* List of all slab caches on the system */
85346 };
85347@@ -261,6 +280,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
85348 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85349 #endif
85350
85351+#ifdef CONFIG_PAX_USERCOPY_SLABS
85352+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
85353+#endif
85354+
85355 /*
85356 * Figure out which kmalloc slab an allocation of a certain size
85357 * belongs to.
85358@@ -269,7 +292,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
85359 * 2 = 120 .. 192 bytes
85360 * n = 2^(n-1) .. 2^n -1
85361 */
85362-static __always_inline int kmalloc_index(size_t size)
85363+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
85364 {
85365 if (!size)
85366 return 0;
85367@@ -312,11 +335,11 @@ static __always_inline int kmalloc_index(size_t size)
85368 }
85369 #endif /* !CONFIG_SLOB */
85370
85371-void *__kmalloc(size_t size, gfp_t flags);
85372+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
85373 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
85374
85375 #ifdef CONFIG_NUMA
85376-void *__kmalloc_node(size_t size, gfp_t flags, int node);
85377+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
85378 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
85379 #else
85380 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
85381diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
85382index 8235dfb..47ce586 100644
85383--- a/include/linux/slab_def.h
85384+++ b/include/linux/slab_def.h
85385@@ -38,7 +38,7 @@ struct kmem_cache {
85386 /* 4) cache creation/removal */
85387 const char *name;
85388 struct list_head list;
85389- int refcount;
85390+ atomic_t refcount;
85391 int object_size;
85392 int align;
85393
85394@@ -54,10 +54,14 @@ struct kmem_cache {
85395 unsigned long node_allocs;
85396 unsigned long node_frees;
85397 unsigned long node_overflow;
85398- atomic_t allochit;
85399- atomic_t allocmiss;
85400- atomic_t freehit;
85401- atomic_t freemiss;
85402+ atomic_unchecked_t allochit;
85403+ atomic_unchecked_t allocmiss;
85404+ atomic_unchecked_t freehit;
85405+ atomic_unchecked_t freemiss;
85406+#ifdef CONFIG_PAX_MEMORY_SANITIZE
85407+ atomic_unchecked_t sanitized;
85408+ atomic_unchecked_t not_sanitized;
85409+#endif
85410
85411 /*
85412 * If debugging is enabled, then the allocator can add additional
85413diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
85414index d82abd4..408c3a0 100644
85415--- a/include/linux/slub_def.h
85416+++ b/include/linux/slub_def.h
85417@@ -74,7 +74,7 @@ struct kmem_cache {
85418 struct kmem_cache_order_objects max;
85419 struct kmem_cache_order_objects min;
85420 gfp_t allocflags; /* gfp flags to use on each alloc */
85421- int refcount; /* Refcount for slab cache destroy */
85422+ atomic_t refcount; /* Refcount for slab cache destroy */
85423 void (*ctor)(void *);
85424 int inuse; /* Offset to metadata */
85425 int align; /* Alignment */
85426diff --git a/include/linux/smp.h b/include/linux/smp.h
85427index 34347f2..8739978 100644
85428--- a/include/linux/smp.h
85429+++ b/include/linux/smp.h
85430@@ -174,7 +174,9 @@ static inline void kick_all_cpus_sync(void) { }
85431 #endif
85432
85433 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
85434+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
85435 #define put_cpu() preempt_enable()
85436+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
85437
85438 /*
85439 * Callback to arch code if there's nosmp or maxcpus=0 on the
85440diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
85441index 46cca4c..3323536 100644
85442--- a/include/linux/sock_diag.h
85443+++ b/include/linux/sock_diag.h
85444@@ -11,7 +11,7 @@ struct sock;
85445 struct sock_diag_handler {
85446 __u8 family;
85447 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
85448-};
85449+} __do_const;
85450
85451 int sock_diag_register(const struct sock_diag_handler *h);
85452 void sock_diag_unregister(const struct sock_diag_handler *h);
85453diff --git a/include/linux/sonet.h b/include/linux/sonet.h
85454index 680f9a3..f13aeb0 100644
85455--- a/include/linux/sonet.h
85456+++ b/include/linux/sonet.h
85457@@ -7,7 +7,7 @@
85458 #include <uapi/linux/sonet.h>
85459
85460 struct k_sonet_stats {
85461-#define __HANDLE_ITEM(i) atomic_t i
85462+#define __HANDLE_ITEM(i) atomic_unchecked_t i
85463 __SONET_ITEMS
85464 #undef __HANDLE_ITEM
85465 };
85466diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
85467index 07d8e53..dc934c9 100644
85468--- a/include/linux/sunrpc/addr.h
85469+++ b/include/linux/sunrpc/addr.h
85470@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
85471 {
85472 switch (sap->sa_family) {
85473 case AF_INET:
85474- return ntohs(((struct sockaddr_in *)sap)->sin_port);
85475+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
85476 case AF_INET6:
85477- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
85478+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
85479 }
85480 return 0;
85481 }
85482@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
85483 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
85484 const struct sockaddr *src)
85485 {
85486- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
85487+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
85488 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
85489
85490 dsin->sin_family = ssin->sin_family;
85491@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
85492 if (sa->sa_family != AF_INET6)
85493 return 0;
85494
85495- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
85496+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
85497 }
85498
85499 #endif /* _LINUX_SUNRPC_ADDR_H */
85500diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
85501index 70736b9..37f33db 100644
85502--- a/include/linux/sunrpc/clnt.h
85503+++ b/include/linux/sunrpc/clnt.h
85504@@ -97,7 +97,7 @@ struct rpc_procinfo {
85505 unsigned int p_timer; /* Which RTT timer to use */
85506 u32 p_statidx; /* Which procedure to account */
85507 const char * p_name; /* name of procedure */
85508-};
85509+} __do_const;
85510
85511 #ifdef __KERNEL__
85512
85513diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
85514index cf61ecd..a4a9bc0 100644
85515--- a/include/linux/sunrpc/svc.h
85516+++ b/include/linux/sunrpc/svc.h
85517@@ -417,7 +417,7 @@ struct svc_procedure {
85518 unsigned int pc_count; /* call count */
85519 unsigned int pc_cachetype; /* cache info (NFS) */
85520 unsigned int pc_xdrressize; /* maximum size of XDR reply */
85521-};
85522+} __do_const;
85523
85524 /*
85525 * Function prototypes.
85526diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
85527index 975da75..318c083 100644
85528--- a/include/linux/sunrpc/svc_rdma.h
85529+++ b/include/linux/sunrpc/svc_rdma.h
85530@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
85531 extern unsigned int svcrdma_max_requests;
85532 extern unsigned int svcrdma_max_req_size;
85533
85534-extern atomic_t rdma_stat_recv;
85535-extern atomic_t rdma_stat_read;
85536-extern atomic_t rdma_stat_write;
85537-extern atomic_t rdma_stat_sq_starve;
85538-extern atomic_t rdma_stat_rq_starve;
85539-extern atomic_t rdma_stat_rq_poll;
85540-extern atomic_t rdma_stat_rq_prod;
85541-extern atomic_t rdma_stat_sq_poll;
85542-extern atomic_t rdma_stat_sq_prod;
85543+extern atomic_unchecked_t rdma_stat_recv;
85544+extern atomic_unchecked_t rdma_stat_read;
85545+extern atomic_unchecked_t rdma_stat_write;
85546+extern atomic_unchecked_t rdma_stat_sq_starve;
85547+extern atomic_unchecked_t rdma_stat_rq_starve;
85548+extern atomic_unchecked_t rdma_stat_rq_poll;
85549+extern atomic_unchecked_t rdma_stat_rq_prod;
85550+extern atomic_unchecked_t rdma_stat_sq_poll;
85551+extern atomic_unchecked_t rdma_stat_sq_prod;
85552
85553 #define RPCRDMA_VERSION 1
85554
85555diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
85556index 8d71d65..f79586e 100644
85557--- a/include/linux/sunrpc/svcauth.h
85558+++ b/include/linux/sunrpc/svcauth.h
85559@@ -120,7 +120,7 @@ struct auth_ops {
85560 int (*release)(struct svc_rqst *rq);
85561 void (*domain_release)(struct auth_domain *);
85562 int (*set_client)(struct svc_rqst *rq);
85563-};
85564+} __do_const;
85565
85566 #define SVC_GARBAGE 1
85567 #define SVC_SYSERR 2
85568diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
85569index e7a018e..49f8b17 100644
85570--- a/include/linux/swiotlb.h
85571+++ b/include/linux/swiotlb.h
85572@@ -60,7 +60,8 @@ extern void
85573
85574 extern void
85575 swiotlb_free_coherent(struct device *hwdev, size_t size,
85576- void *vaddr, dma_addr_t dma_handle);
85577+ void *vaddr, dma_addr_t dma_handle,
85578+ struct dma_attrs *attrs);
85579
85580 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
85581 unsigned long offset, size_t size,
85582diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
85583index 0f86d85..dff3419 100644
85584--- a/include/linux/syscalls.h
85585+++ b/include/linux/syscalls.h
85586@@ -98,10 +98,16 @@ struct sigaltstack;
85587 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
85588
85589 #define __SC_DECL(t, a) t a
85590+#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))
85591 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
85592 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
85593 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
85594-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
85595+#define __SC_LONG(t, a) __typeof( \
85596+ __builtin_choose_expr( \
85597+ sizeof(t) > sizeof(int), \
85598+ (t) 0, \
85599+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
85600+ )) a
85601 #define __SC_CAST(t, a) (t) a
85602 #define __SC_ARGS(t, a) a
85603 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
85604@@ -383,11 +389,11 @@ asmlinkage long sys_sync(void);
85605 asmlinkage long sys_fsync(unsigned int fd);
85606 asmlinkage long sys_fdatasync(unsigned int fd);
85607 asmlinkage long sys_bdflush(int func, long data);
85608-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
85609- char __user *type, unsigned long flags,
85610+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
85611+ const char __user *type, unsigned long flags,
85612 void __user *data);
85613-asmlinkage long sys_umount(char __user *name, int flags);
85614-asmlinkage long sys_oldumount(char __user *name);
85615+asmlinkage long sys_umount(const char __user *name, int flags);
85616+asmlinkage long sys_oldumount(const char __user *name);
85617 asmlinkage long sys_truncate(const char __user *path, long length);
85618 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
85619 asmlinkage long sys_stat(const char __user *filename,
85620@@ -599,7 +605,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
85621 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
85622 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
85623 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
85624- struct sockaddr __user *, int);
85625+ struct sockaddr __user *, int) __intentional_overflow(0);
85626 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
85627 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
85628 unsigned int vlen, unsigned flags);
85629diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
85630index 27b3b0b..e093dd9 100644
85631--- a/include/linux/syscore_ops.h
85632+++ b/include/linux/syscore_ops.h
85633@@ -16,7 +16,7 @@ struct syscore_ops {
85634 int (*suspend)(void);
85635 void (*resume)(void);
85636 void (*shutdown)(void);
85637-};
85638+} __do_const;
85639
85640 extern void register_syscore_ops(struct syscore_ops *ops);
85641 extern void unregister_syscore_ops(struct syscore_ops *ops);
85642diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
85643index b7361f8..341a15a 100644
85644--- a/include/linux/sysctl.h
85645+++ b/include/linux/sysctl.h
85646@@ -39,6 +39,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
85647
85648 extern int proc_dostring(struct ctl_table *, int,
85649 void __user *, size_t *, loff_t *);
85650+extern int proc_dostring_modpriv(struct ctl_table *, int,
85651+ void __user *, size_t *, loff_t *);
85652 extern int proc_dointvec(struct ctl_table *, int,
85653 void __user *, size_t *, loff_t *);
85654 extern int proc_dointvec_minmax(struct ctl_table *, int,
85655@@ -113,7 +115,8 @@ struct ctl_table
85656 struct ctl_table_poll *poll;
85657 void *extra1;
85658 void *extra2;
85659-};
85660+} __do_const __randomize_layout;
85661+typedef struct ctl_table __no_const ctl_table_no_const;
85662
85663 struct ctl_node {
85664 struct rb_node node;
85665diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
85666index f97d0db..c1187dc 100644
85667--- a/include/linux/sysfs.h
85668+++ b/include/linux/sysfs.h
85669@@ -34,7 +34,8 @@ struct attribute {
85670 struct lock_class_key *key;
85671 struct lock_class_key skey;
85672 #endif
85673-};
85674+} __do_const;
85675+typedef struct attribute __no_const attribute_no_const;
85676
85677 /**
85678 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
85679@@ -63,7 +64,8 @@ struct attribute_group {
85680 struct attribute *, int);
85681 struct attribute **attrs;
85682 struct bin_attribute **bin_attrs;
85683-};
85684+} __do_const;
85685+typedef struct attribute_group __no_const attribute_group_no_const;
85686
85687 /**
85688 * Use these macros to make defining attributes easier. See include/linux/device.h
85689@@ -128,7 +130,8 @@ struct bin_attribute {
85690 char *, loff_t, size_t);
85691 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
85692 struct vm_area_struct *vma);
85693-};
85694+} __do_const;
85695+typedef struct bin_attribute __no_const bin_attribute_no_const;
85696
85697 /**
85698 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
85699diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
85700index 387fa7d..3fcde6b 100644
85701--- a/include/linux/sysrq.h
85702+++ b/include/linux/sysrq.h
85703@@ -16,6 +16,7 @@
85704
85705 #include <linux/errno.h>
85706 #include <linux/types.h>
85707+#include <linux/compiler.h>
85708
85709 /* Possible values of bitmask for enabling sysrq functions */
85710 /* 0x0001 is reserved for enable everything */
85711@@ -33,7 +34,7 @@ struct sysrq_key_op {
85712 char *help_msg;
85713 char *action_msg;
85714 int enable_mask;
85715-};
85716+} __do_const;
85717
85718 #ifdef CONFIG_MAGIC_SYSRQ
85719
85720diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
85721index ff307b5..f1a4468 100644
85722--- a/include/linux/thread_info.h
85723+++ b/include/linux/thread_info.h
85724@@ -145,6 +145,13 @@ static inline bool test_and_clear_restore_sigmask(void)
85725 #error "no set_restore_sigmask() provided and default one won't work"
85726 #endif
85727
85728+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
85729+
85730+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
85731+{
85732+ __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
85733+}
85734+
85735 #endif /* __KERNEL__ */
85736
85737 #endif /* _LINUX_THREAD_INFO_H */
85738diff --git a/include/linux/tty.h b/include/linux/tty.h
85739index 8413294..44391c7 100644
85740--- a/include/linux/tty.h
85741+++ b/include/linux/tty.h
85742@@ -202,7 +202,7 @@ struct tty_port {
85743 const struct tty_port_operations *ops; /* Port operations */
85744 spinlock_t lock; /* Lock protecting tty field */
85745 int blocked_open; /* Waiting to open */
85746- int count; /* Usage count */
85747+ atomic_t count; /* Usage count */
85748 wait_queue_head_t open_wait; /* Open waiters */
85749 wait_queue_head_t close_wait; /* Close waiters */
85750 wait_queue_head_t delta_msr_wait; /* Modem status change */
85751@@ -284,7 +284,7 @@ struct tty_struct {
85752 /* If the tty has a pending do_SAK, queue it here - akpm */
85753 struct work_struct SAK_work;
85754 struct tty_port *port;
85755-};
85756+} __randomize_layout;
85757
85758 /* Each of a tty's open files has private_data pointing to tty_file_private */
85759 struct tty_file_private {
85760@@ -548,7 +548,7 @@ extern int tty_port_open(struct tty_port *port,
85761 struct tty_struct *tty, struct file *filp);
85762 static inline int tty_port_users(struct tty_port *port)
85763 {
85764- return port->count + port->blocked_open;
85765+ return atomic_read(&port->count) + port->blocked_open;
85766 }
85767
85768 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
85769diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
85770index e48c608..6a19af2 100644
85771--- a/include/linux/tty_driver.h
85772+++ b/include/linux/tty_driver.h
85773@@ -287,7 +287,7 @@ struct tty_operations {
85774 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
85775 #endif
85776 const struct file_operations *proc_fops;
85777-};
85778+} __do_const __randomize_layout;
85779
85780 struct tty_driver {
85781 int magic; /* magic number for this structure */
85782@@ -321,7 +321,7 @@ struct tty_driver {
85783
85784 const struct tty_operations *ops;
85785 struct list_head tty_drivers;
85786-};
85787+} __randomize_layout;
85788
85789 extern struct list_head tty_drivers;
85790
85791diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
85792index 00c9d68..bc0188b 100644
85793--- a/include/linux/tty_ldisc.h
85794+++ b/include/linux/tty_ldisc.h
85795@@ -215,7 +215,7 @@ struct tty_ldisc_ops {
85796
85797 struct module *owner;
85798
85799- int refcount;
85800+ atomic_t refcount;
85801 };
85802
85803 struct tty_ldisc {
85804diff --git a/include/linux/types.h b/include/linux/types.h
85805index a0bb704..f511c77 100644
85806--- a/include/linux/types.h
85807+++ b/include/linux/types.h
85808@@ -177,10 +177,26 @@ typedef struct {
85809 int counter;
85810 } atomic_t;
85811
85812+#ifdef CONFIG_PAX_REFCOUNT
85813+typedef struct {
85814+ int counter;
85815+} atomic_unchecked_t;
85816+#else
85817+typedef atomic_t atomic_unchecked_t;
85818+#endif
85819+
85820 #ifdef CONFIG_64BIT
85821 typedef struct {
85822 long counter;
85823 } atomic64_t;
85824+
85825+#ifdef CONFIG_PAX_REFCOUNT
85826+typedef struct {
85827+ long counter;
85828+} atomic64_unchecked_t;
85829+#else
85830+typedef atomic64_t atomic64_unchecked_t;
85831+#endif
85832 #endif
85833
85834 struct list_head {
85835diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
85836index ecd3319..8a36ded 100644
85837--- a/include/linux/uaccess.h
85838+++ b/include/linux/uaccess.h
85839@@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
85840 long ret; \
85841 mm_segment_t old_fs = get_fs(); \
85842 \
85843- set_fs(KERNEL_DS); \
85844 pagefault_disable(); \
85845- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
85846- pagefault_enable(); \
85847+ set_fs(KERNEL_DS); \
85848+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
85849 set_fs(old_fs); \
85850+ pagefault_enable(); \
85851 ret; \
85852 })
85853
85854diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
85855index 2d1f9b6..d7a9fce 100644
85856--- a/include/linux/uidgid.h
85857+++ b/include/linux/uidgid.h
85858@@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
85859
85860 #endif /* CONFIG_USER_NS */
85861
85862+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
85863+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
85864+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
85865+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
85866+
85867 #endif /* _LINUX_UIDGID_H */
85868diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
85869index 99c1b4d..562e6f3 100644
85870--- a/include/linux/unaligned/access_ok.h
85871+++ b/include/linux/unaligned/access_ok.h
85872@@ -4,34 +4,34 @@
85873 #include <linux/kernel.h>
85874 #include <asm/byteorder.h>
85875
85876-static inline u16 get_unaligned_le16(const void *p)
85877+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
85878 {
85879- return le16_to_cpup((__le16 *)p);
85880+ return le16_to_cpup((const __le16 *)p);
85881 }
85882
85883-static inline u32 get_unaligned_le32(const void *p)
85884+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
85885 {
85886- return le32_to_cpup((__le32 *)p);
85887+ return le32_to_cpup((const __le32 *)p);
85888 }
85889
85890-static inline u64 get_unaligned_le64(const void *p)
85891+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
85892 {
85893- return le64_to_cpup((__le64 *)p);
85894+ return le64_to_cpup((const __le64 *)p);
85895 }
85896
85897-static inline u16 get_unaligned_be16(const void *p)
85898+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
85899 {
85900- return be16_to_cpup((__be16 *)p);
85901+ return be16_to_cpup((const __be16 *)p);
85902 }
85903
85904-static inline u32 get_unaligned_be32(const void *p)
85905+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
85906 {
85907- return be32_to_cpup((__be32 *)p);
85908+ return be32_to_cpup((const __be32 *)p);
85909 }
85910
85911-static inline u64 get_unaligned_be64(const void *p)
85912+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
85913 {
85914- return be64_to_cpup((__be64 *)p);
85915+ return be64_to_cpup((const __be64 *)p);
85916 }
85917
85918 static inline void put_unaligned_le16(u16 val, void *p)
85919diff --git a/include/linux/uprobes.h b/include/linux/uprobes.h
85920index 4f844c6..60beb5d 100644
85921--- a/include/linux/uprobes.h
85922+++ b/include/linux/uprobes.h
85923@@ -98,11 +98,11 @@ struct uprobes_state {
85924 struct xol_area *xol_area;
85925 };
85926
85927-extern int __weak set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
85928-extern int __weak set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
85929-extern bool __weak is_swbp_insn(uprobe_opcode_t *insn);
85930-extern bool __weak is_trap_insn(uprobe_opcode_t *insn);
85931-extern unsigned long __weak uprobe_get_swbp_addr(struct pt_regs *regs);
85932+extern int set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
85933+extern int set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
85934+extern bool is_swbp_insn(uprobe_opcode_t *insn);
85935+extern bool is_trap_insn(uprobe_opcode_t *insn);
85936+extern unsigned long uprobe_get_swbp_addr(struct pt_regs *regs);
85937 extern unsigned long uprobe_get_trap_addr(struct pt_regs *regs);
85938 extern int uprobe_write_opcode(struct mm_struct *mm, unsigned long vaddr, uprobe_opcode_t);
85939 extern int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
85940@@ -128,8 +128,8 @@ extern bool arch_uprobe_xol_was_trapped(struct task_struct *tsk);
85941 extern int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val, void *data);
85942 extern void arch_uprobe_abort_xol(struct arch_uprobe *aup, struct pt_regs *regs);
85943 extern unsigned long arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs *regs);
85944-extern bool __weak arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
85945-extern void __weak arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
85946+extern bool arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
85947+extern void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
85948 void *src, unsigned long len);
85949 #else /* !CONFIG_UPROBES */
85950 struct uprobes_state {
85951diff --git a/include/linux/usb.h b/include/linux/usb.h
85952index d2465bc..5256de4 100644
85953--- a/include/linux/usb.h
85954+++ b/include/linux/usb.h
85955@@ -571,7 +571,7 @@ struct usb_device {
85956 int maxchild;
85957
85958 u32 quirks;
85959- atomic_t urbnum;
85960+ atomic_unchecked_t urbnum;
85961
85962 unsigned long active_duration;
85963
85964@@ -1655,7 +1655,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
85965
85966 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
85967 __u8 request, __u8 requesttype, __u16 value, __u16 index,
85968- void *data, __u16 size, int timeout);
85969+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
85970 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
85971 void *data, int len, int *actual_length, int timeout);
85972 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
85973diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
85974index d5952bb..9a626d4 100644
85975--- a/include/linux/usb/renesas_usbhs.h
85976+++ b/include/linux/usb/renesas_usbhs.h
85977@@ -39,7 +39,7 @@ enum {
85978 */
85979 struct renesas_usbhs_driver_callback {
85980 int (*notify_hotplug)(struct platform_device *pdev);
85981-};
85982+} __no_const;
85983
85984 /*
85985 * callback functions for platform
85986diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
85987index e953726..8edb26a 100644
85988--- a/include/linux/user_namespace.h
85989+++ b/include/linux/user_namespace.h
85990@@ -33,7 +33,7 @@ struct user_namespace {
85991 struct key *persistent_keyring_register;
85992 struct rw_semaphore persistent_keyring_register_sem;
85993 #endif
85994-};
85995+} __randomize_layout;
85996
85997 extern struct user_namespace init_user_ns;
85998
85999diff --git a/include/linux/utsname.h b/include/linux/utsname.h
86000index 239e277..22a5cf5 100644
86001--- a/include/linux/utsname.h
86002+++ b/include/linux/utsname.h
86003@@ -24,7 +24,7 @@ struct uts_namespace {
86004 struct new_utsname name;
86005 struct user_namespace *user_ns;
86006 unsigned int proc_inum;
86007-};
86008+} __randomize_layout;
86009 extern struct uts_namespace init_uts_ns;
86010
86011 #ifdef CONFIG_UTS_NS
86012diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
86013index 6f8fbcf..4efc177 100644
86014--- a/include/linux/vermagic.h
86015+++ b/include/linux/vermagic.h
86016@@ -25,9 +25,42 @@
86017 #define MODULE_ARCH_VERMAGIC ""
86018 #endif
86019
86020+#ifdef CONFIG_PAX_REFCOUNT
86021+#define MODULE_PAX_REFCOUNT "REFCOUNT "
86022+#else
86023+#define MODULE_PAX_REFCOUNT ""
86024+#endif
86025+
86026+#ifdef CONSTIFY_PLUGIN
86027+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
86028+#else
86029+#define MODULE_CONSTIFY_PLUGIN ""
86030+#endif
86031+
86032+#ifdef STACKLEAK_PLUGIN
86033+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
86034+#else
86035+#define MODULE_STACKLEAK_PLUGIN ""
86036+#endif
86037+
86038+#ifdef RANDSTRUCT_PLUGIN
86039+#include <generated/randomize_layout_hash.h>
86040+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
86041+#else
86042+#define MODULE_RANDSTRUCT_PLUGIN
86043+#endif
86044+
86045+#ifdef CONFIG_GRKERNSEC
86046+#define MODULE_GRSEC "GRSEC "
86047+#else
86048+#define MODULE_GRSEC ""
86049+#endif
86050+
86051 #define VERMAGIC_STRING \
86052 UTS_RELEASE " " \
86053 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
86054 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
86055- MODULE_ARCH_VERMAGIC
86056+ MODULE_ARCH_VERMAGIC \
86057+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
86058+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
86059
86060diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
86061index b483abd..af305ad 100644
86062--- a/include/linux/vga_switcheroo.h
86063+++ b/include/linux/vga_switcheroo.h
86064@@ -63,9 +63,9 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
86065
86066 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
86067
86068-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
86069+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
86070 void vga_switcheroo_fini_domain_pm_ops(struct device *dev);
86071-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
86072+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
86073 #else
86074
86075 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
86076@@ -82,9 +82,9 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
86077
86078 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
86079
86080-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86081+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86082 static inline void vga_switcheroo_fini_domain_pm_ops(struct device *dev) {}
86083-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
86084+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
86085
86086 #endif
86087 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
86088diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
86089index b87696f..1d11de7 100644
86090--- a/include/linux/vmalloc.h
86091+++ b/include/linux/vmalloc.h
86092@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
86093 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
86094 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
86095 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
86096+
86097+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
86098+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
86099+#endif
86100+
86101 /* bits [20..32] reserved for arch specific ioremap internals */
86102
86103 /*
86104@@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
86105 unsigned long flags, pgprot_t prot);
86106 extern void vunmap(const void *addr);
86107
86108+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86109+extern void unmap_process_stacks(struct task_struct *task);
86110+#endif
86111+
86112 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
86113 unsigned long uaddr, void *kaddr,
86114 unsigned long size);
86115@@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
86116
86117 /* for /dev/kmem */
86118 extern long vread(char *buf, char *addr, unsigned long count);
86119-extern long vwrite(char *buf, char *addr, unsigned long count);
86120+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
86121
86122 /*
86123 * Internals. Dont't use..
86124diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
86125index 82e7db7..f8ce3d0 100644
86126--- a/include/linux/vmstat.h
86127+++ b/include/linux/vmstat.h
86128@@ -108,18 +108,18 @@ static inline void vm_events_fold_cpu(int cpu)
86129 /*
86130 * Zone based page accounting with per cpu differentials.
86131 */
86132-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86133+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
86134
86135 static inline void zone_page_state_add(long x, struct zone *zone,
86136 enum zone_stat_item item)
86137 {
86138- atomic_long_add(x, &zone->vm_stat[item]);
86139- atomic_long_add(x, &vm_stat[item]);
86140+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
86141+ atomic_long_add_unchecked(x, &vm_stat[item]);
86142 }
86143
86144-static inline unsigned long global_page_state(enum zone_stat_item item)
86145+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
86146 {
86147- long x = atomic_long_read(&vm_stat[item]);
86148+ long x = atomic_long_read_unchecked(&vm_stat[item]);
86149 #ifdef CONFIG_SMP
86150 if (x < 0)
86151 x = 0;
86152@@ -127,10 +127,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
86153 return x;
86154 }
86155
86156-static inline unsigned long zone_page_state(struct zone *zone,
86157+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
86158 enum zone_stat_item item)
86159 {
86160- long x = atomic_long_read(&zone->vm_stat[item]);
86161+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86162 #ifdef CONFIG_SMP
86163 if (x < 0)
86164 x = 0;
86165@@ -147,7 +147,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
86166 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
86167 enum zone_stat_item item)
86168 {
86169- long x = atomic_long_read(&zone->vm_stat[item]);
86170+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
86171
86172 #ifdef CONFIG_SMP
86173 int cpu;
86174@@ -234,14 +234,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
86175
86176 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
86177 {
86178- atomic_long_inc(&zone->vm_stat[item]);
86179- atomic_long_inc(&vm_stat[item]);
86180+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
86181+ atomic_long_inc_unchecked(&vm_stat[item]);
86182 }
86183
86184 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
86185 {
86186- atomic_long_dec(&zone->vm_stat[item]);
86187- atomic_long_dec(&vm_stat[item]);
86188+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
86189+ atomic_long_dec_unchecked(&vm_stat[item]);
86190 }
86191
86192 static inline void __inc_zone_page_state(struct page *page,
86193diff --git a/include/linux/xattr.h b/include/linux/xattr.h
86194index 91b0a68..0e9adf6 100644
86195--- a/include/linux/xattr.h
86196+++ b/include/linux/xattr.h
86197@@ -28,7 +28,7 @@ struct xattr_handler {
86198 size_t size, int handler_flags);
86199 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
86200 size_t size, int flags, int handler_flags);
86201-};
86202+} __do_const;
86203
86204 struct xattr {
86205 const char *name;
86206@@ -37,6 +37,9 @@ struct xattr {
86207 };
86208
86209 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
86210+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
86211+ssize_t pax_getxattr(struct dentry *, void *, size_t);
86212+#endif
86213 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
86214 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
86215 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
86216diff --git a/include/linux/zlib.h b/include/linux/zlib.h
86217index 92dbbd3..13ab0b3 100644
86218--- a/include/linux/zlib.h
86219+++ b/include/linux/zlib.h
86220@@ -31,6 +31,7 @@
86221 #define _ZLIB_H
86222
86223 #include <linux/zconf.h>
86224+#include <linux/compiler.h>
86225
86226 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
86227 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
86228@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
86229
86230 /* basic functions */
86231
86232-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
86233+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
86234 /*
86235 Returns the number of bytes that needs to be allocated for a per-
86236 stream workspace with the specified parameters. A pointer to this
86237diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
86238index eb76cfd..9fd0e7c 100644
86239--- a/include/media/v4l2-dev.h
86240+++ b/include/media/v4l2-dev.h
86241@@ -75,7 +75,7 @@ struct v4l2_file_operations {
86242 int (*mmap) (struct file *, struct vm_area_struct *);
86243 int (*open) (struct file *);
86244 int (*release) (struct file *);
86245-};
86246+} __do_const;
86247
86248 /*
86249 * Newer version of video_device, handled by videodev2.c
86250diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
86251index ffb69da..040393e 100644
86252--- a/include/media/v4l2-device.h
86253+++ b/include/media/v4l2-device.h
86254@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
86255 this function returns 0. If the name ends with a digit (e.g. cx18),
86256 then the name will be set to cx18-0 since cx180 looks really odd. */
86257 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
86258- atomic_t *instance);
86259+ atomic_unchecked_t *instance);
86260
86261 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
86262 Since the parent disappears this ensures that v4l2_dev doesn't have an
86263diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
86264index d9fa68f..45c88d1 100644
86265--- a/include/net/9p/transport.h
86266+++ b/include/net/9p/transport.h
86267@@ -63,7 +63,7 @@ struct p9_trans_module {
86268 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
86269 int (*zc_request)(struct p9_client *, struct p9_req_t *,
86270 char *, char *, int , int, int, int);
86271-};
86272+} __do_const;
86273
86274 void v9fs_register_trans(struct p9_trans_module *m);
86275 void v9fs_unregister_trans(struct p9_trans_module *m);
86276diff --git a/include/net/af_unix.h b/include/net/af_unix.h
86277index a175ba4..196eb82 100644
86278--- a/include/net/af_unix.h
86279+++ b/include/net/af_unix.h
86280@@ -36,7 +36,7 @@ struct unix_skb_parms {
86281 u32 secid; /* Security ID */
86282 #endif
86283 u32 consumed;
86284-};
86285+} __randomize_layout;
86286
86287 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
86288 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
86289diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
86290index 8df15ad..837fbedd 100644
86291--- a/include/net/bluetooth/l2cap.h
86292+++ b/include/net/bluetooth/l2cap.h
86293@@ -608,7 +608,7 @@ struct l2cap_ops {
86294 unsigned char *kdata,
86295 struct iovec *iov,
86296 int len);
86297-};
86298+} __do_const;
86299
86300 struct l2cap_conn {
86301 struct hci_conn *hcon;
86302diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
86303index f2ae33d..c457cf0 100644
86304--- a/include/net/caif/cfctrl.h
86305+++ b/include/net/caif/cfctrl.h
86306@@ -52,7 +52,7 @@ struct cfctrl_rsp {
86307 void (*radioset_rsp)(void);
86308 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
86309 struct cflayer *client_layer);
86310-};
86311+} __no_const;
86312
86313 /* Link Setup Parameters for CAIF-Links. */
86314 struct cfctrl_link_param {
86315@@ -101,8 +101,8 @@ struct cfctrl_request_info {
86316 struct cfctrl {
86317 struct cfsrvl serv;
86318 struct cfctrl_rsp res;
86319- atomic_t req_seq_no;
86320- atomic_t rsp_seq_no;
86321+ atomic_unchecked_t req_seq_no;
86322+ atomic_unchecked_t rsp_seq_no;
86323 struct list_head list;
86324 /* Protects from simultaneous access to first_req list */
86325 spinlock_t info_list_lock;
86326diff --git a/include/net/flow.h b/include/net/flow.h
86327index 8109a15..504466d 100644
86328--- a/include/net/flow.h
86329+++ b/include/net/flow.h
86330@@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
86331
86332 void flow_cache_flush(struct net *net);
86333 void flow_cache_flush_deferred(struct net *net);
86334-extern atomic_t flow_cache_genid;
86335+extern atomic_unchecked_t flow_cache_genid;
86336
86337 #endif
86338diff --git a/include/net/genetlink.h b/include/net/genetlink.h
86339index af10c2c..a431cc5 100644
86340--- a/include/net/genetlink.h
86341+++ b/include/net/genetlink.h
86342@@ -120,7 +120,7 @@ struct genl_ops {
86343 u8 cmd;
86344 u8 internal_flags;
86345 u8 flags;
86346-};
86347+} __do_const;
86348
86349 int __genl_register_family(struct genl_family *family);
86350
86351diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
86352index 734d9b5..48a9a4b 100644
86353--- a/include/net/gro_cells.h
86354+++ b/include/net/gro_cells.h
86355@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
86356 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
86357
86358 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
86359- atomic_long_inc(&dev->rx_dropped);
86360+ atomic_long_inc_unchecked(&dev->rx_dropped);
86361 kfree_skb(skb);
86362 return;
86363 }
86364diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
86365index 5fbe656..9ed3d8b 100644
86366--- a/include/net/inet_connection_sock.h
86367+++ b/include/net/inet_connection_sock.h
86368@@ -63,7 +63,7 @@ struct inet_connection_sock_af_ops {
86369 int (*bind_conflict)(const struct sock *sk,
86370 const struct inet_bind_bucket *tb, bool relax);
86371 void (*mtu_reduced)(struct sock *sk);
86372-};
86373+} __do_const;
86374
86375 /** inet_connection_sock - INET connection oriented sock
86376 *
86377diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
86378index 01d590e..f69c61d 100644
86379--- a/include/net/inetpeer.h
86380+++ b/include/net/inetpeer.h
86381@@ -47,7 +47,7 @@ struct inet_peer {
86382 */
86383 union {
86384 struct {
86385- atomic_t rid; /* Frag reception counter */
86386+ atomic_unchecked_t rid; /* Frag reception counter */
86387 };
86388 struct rcu_head rcu;
86389 struct inet_peer *gc_next;
86390diff --git a/include/net/ip.h b/include/net/ip.h
86391index db4a771..965a42a 100644
86392--- a/include/net/ip.h
86393+++ b/include/net/ip.h
86394@@ -316,7 +316,7 @@ static inline unsigned int ip_skb_dst_mtu(const struct sk_buff *skb)
86395 }
86396 }
86397
86398-u32 ip_idents_reserve(u32 hash, int segs);
86399+u32 ip_idents_reserve(u32 hash, int segs) __intentional_overflow(-1);
86400 void __ip_select_ident(struct iphdr *iph, int segs);
86401
86402 static inline void ip_select_ident_segs(struct sk_buff *skb, struct sock *sk, int segs)
86403diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
86404index 9922093..a1755d6 100644
86405--- a/include/net/ip_fib.h
86406+++ b/include/net/ip_fib.h
86407@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
86408
86409 #define FIB_RES_SADDR(net, res) \
86410 ((FIB_RES_NH(res).nh_saddr_genid == \
86411- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
86412+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
86413 FIB_RES_NH(res).nh_saddr : \
86414 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
86415 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
86416diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
86417index 624a8a5..b1e2a24 100644
86418--- a/include/net/ip_vs.h
86419+++ b/include/net/ip_vs.h
86420@@ -558,7 +558,7 @@ struct ip_vs_conn {
86421 struct ip_vs_conn *control; /* Master control connection */
86422 atomic_t n_control; /* Number of controlled ones */
86423 struct ip_vs_dest *dest; /* real server */
86424- atomic_t in_pkts; /* incoming packet counter */
86425+ atomic_unchecked_t in_pkts; /* incoming packet counter */
86426
86427 /* packet transmitter for different forwarding methods. If it
86428 mangles the packet, it must return NF_DROP or better NF_STOLEN,
86429@@ -705,7 +705,7 @@ struct ip_vs_dest {
86430 __be16 port; /* port number of the server */
86431 union nf_inet_addr addr; /* IP address of the server */
86432 volatile unsigned int flags; /* dest status flags */
86433- atomic_t conn_flags; /* flags to copy to conn */
86434+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
86435 atomic_t weight; /* server weight */
86436
86437 atomic_t refcnt; /* reference counter */
86438@@ -960,11 +960,11 @@ struct netns_ipvs {
86439 /* ip_vs_lblc */
86440 int sysctl_lblc_expiration;
86441 struct ctl_table_header *lblc_ctl_header;
86442- struct ctl_table *lblc_ctl_table;
86443+ ctl_table_no_const *lblc_ctl_table;
86444 /* ip_vs_lblcr */
86445 int sysctl_lblcr_expiration;
86446 struct ctl_table_header *lblcr_ctl_header;
86447- struct ctl_table *lblcr_ctl_table;
86448+ ctl_table_no_const *lblcr_ctl_table;
86449 /* ip_vs_est */
86450 struct list_head est_list; /* estimator list */
86451 spinlock_t est_lock;
86452diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
86453index 8d4f588..2e37ad2 100644
86454--- a/include/net/irda/ircomm_tty.h
86455+++ b/include/net/irda/ircomm_tty.h
86456@@ -33,6 +33,7 @@
86457 #include <linux/termios.h>
86458 #include <linux/timer.h>
86459 #include <linux/tty.h> /* struct tty_struct */
86460+#include <asm/local.h>
86461
86462 #include <net/irda/irias_object.h>
86463 #include <net/irda/ircomm_core.h>
86464diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
86465index 714cc9a..ea05f3e 100644
86466--- a/include/net/iucv/af_iucv.h
86467+++ b/include/net/iucv/af_iucv.h
86468@@ -149,7 +149,7 @@ struct iucv_skb_cb {
86469 struct iucv_sock_list {
86470 struct hlist_head head;
86471 rwlock_t lock;
86472- atomic_t autobind_name;
86473+ atomic_unchecked_t autobind_name;
86474 };
86475
86476 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
86477diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
86478index f3be818..bf46196 100644
86479--- a/include/net/llc_c_ac.h
86480+++ b/include/net/llc_c_ac.h
86481@@ -87,7 +87,7 @@
86482 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
86483 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
86484
86485-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86486+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
86487
86488 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
86489 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
86490diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
86491index 3948cf1..83b28c4 100644
86492--- a/include/net/llc_c_ev.h
86493+++ b/include/net/llc_c_ev.h
86494@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
86495 return (struct llc_conn_state_ev *)skb->cb;
86496 }
86497
86498-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86499-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86500+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
86501+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
86502
86503 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
86504 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
86505diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
86506index 0e79cfb..f46db31 100644
86507--- a/include/net/llc_c_st.h
86508+++ b/include/net/llc_c_st.h
86509@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
86510 u8 next_state;
86511 llc_conn_ev_qfyr_t *ev_qualifiers;
86512 llc_conn_action_t *ev_actions;
86513-};
86514+} __do_const;
86515
86516 struct llc_conn_state {
86517 u8 current_state;
86518diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
86519index a61b98c..aade1eb 100644
86520--- a/include/net/llc_s_ac.h
86521+++ b/include/net/llc_s_ac.h
86522@@ -23,7 +23,7 @@
86523 #define SAP_ACT_TEST_IND 9
86524
86525 /* All action functions must look like this */
86526-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86527+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
86528
86529 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
86530 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
86531diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
86532index 567c681..cd73ac02 100644
86533--- a/include/net/llc_s_st.h
86534+++ b/include/net/llc_s_st.h
86535@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
86536 llc_sap_ev_t ev;
86537 u8 next_state;
86538 llc_sap_action_t *ev_actions;
86539-};
86540+} __do_const;
86541
86542 struct llc_sap_state {
86543 u8 curr_state;
86544diff --git a/include/net/mac80211.h b/include/net/mac80211.h
86545index dae2e24..89336e6 100644
86546--- a/include/net/mac80211.h
86547+++ b/include/net/mac80211.h
86548@@ -4650,7 +4650,7 @@ struct rate_control_ops {
86549 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
86550
86551 u32 (*get_expected_throughput)(void *priv_sta);
86552-};
86553+} __do_const;
86554
86555 static inline int rate_supported(struct ieee80211_sta *sta,
86556 enum ieee80211_band band,
86557diff --git a/include/net/neighbour.h b/include/net/neighbour.h
86558index 47f4254..fd095bc 100644
86559--- a/include/net/neighbour.h
86560+++ b/include/net/neighbour.h
86561@@ -163,7 +163,7 @@ struct neigh_ops {
86562 void (*error_report)(struct neighbour *, struct sk_buff *);
86563 int (*output)(struct neighbour *, struct sk_buff *);
86564 int (*connected_output)(struct neighbour *, struct sk_buff *);
86565-};
86566+} __do_const;
86567
86568 struct pneigh_entry {
86569 struct pneigh_entry *next;
86570@@ -217,7 +217,7 @@ struct neigh_table {
86571 struct neigh_statistics __percpu *stats;
86572 struct neigh_hash_table __rcu *nht;
86573 struct pneigh_entry **phash_buckets;
86574-};
86575+} __randomize_layout;
86576
86577 static inline int neigh_parms_family(struct neigh_parms *p)
86578 {
86579diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
86580index e0d6466..e2f3003 100644
86581--- a/include/net/net_namespace.h
86582+++ b/include/net/net_namespace.h
86583@@ -129,8 +129,8 @@ struct net {
86584 struct netns_ipvs *ipvs;
86585 #endif
86586 struct sock *diag_nlsk;
86587- atomic_t fnhe_genid;
86588-};
86589+ atomic_unchecked_t fnhe_genid;
86590+} __randomize_layout;
86591
86592 #include <linux/seq_file_net.h>
86593
86594@@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
86595 #define __net_init __init
86596 #define __net_exit __exit_refok
86597 #define __net_initdata __initdata
86598+#ifdef CONSTIFY_PLUGIN
86599 #define __net_initconst __initconst
86600+#else
86601+#define __net_initconst __initdata
86602+#endif
86603 #endif
86604
86605 struct pernet_operations {
86606@@ -296,7 +300,7 @@ struct pernet_operations {
86607 void (*exit_batch)(struct list_head *net_exit_list);
86608 int *id;
86609 size_t size;
86610-};
86611+} __do_const;
86612
86613 /*
86614 * Use these carefully. If you implement a network device and it
86615@@ -344,12 +348,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
86616
86617 static inline int rt_genid_ipv4(struct net *net)
86618 {
86619- return atomic_read(&net->ipv4.rt_genid);
86620+ return atomic_read_unchecked(&net->ipv4.rt_genid);
86621 }
86622
86623 static inline void rt_genid_bump_ipv4(struct net *net)
86624 {
86625- atomic_inc(&net->ipv4.rt_genid);
86626+ atomic_inc_unchecked(&net->ipv4.rt_genid);
86627 }
86628
86629 extern void (*__fib6_flush_trees)(struct net *net);
86630@@ -376,12 +380,12 @@ static inline void rt_genid_bump_all(struct net *net)
86631
86632 static inline int fnhe_genid(struct net *net)
86633 {
86634- return atomic_read(&net->fnhe_genid);
86635+ return atomic_read_unchecked(&net->fnhe_genid);
86636 }
86637
86638 static inline void fnhe_genid_bump(struct net *net)
86639 {
86640- atomic_inc(&net->fnhe_genid);
86641+ atomic_inc_unchecked(&net->fnhe_genid);
86642 }
86643
86644 #endif /* __NET_NET_NAMESPACE_H */
86645diff --git a/include/net/netdma.h b/include/net/netdma.h
86646index 8ba8ce2..99b7fff 100644
86647--- a/include/net/netdma.h
86648+++ b/include/net/netdma.h
86649@@ -24,7 +24,7 @@
86650 #include <linux/dmaengine.h>
86651 #include <linux/skbuff.h>
86652
86653-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
86654+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
86655 struct sk_buff *skb, int offset, struct iovec *to,
86656 size_t len, struct dma_pinned_list *pinned_list);
86657
86658diff --git a/include/net/netlink.h b/include/net/netlink.h
86659index 6c10762..3e5de0c 100644
86660--- a/include/net/netlink.h
86661+++ b/include/net/netlink.h
86662@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
86663 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
86664 {
86665 if (mark)
86666- skb_trim(skb, (unsigned char *) mark - skb->data);
86667+ skb_trim(skb, (const unsigned char *) mark - skb->data);
86668 }
86669
86670 /**
86671diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
86672index 29d6a94..235d3d8 100644
86673--- a/include/net/netns/conntrack.h
86674+++ b/include/net/netns/conntrack.h
86675@@ -14,10 +14,10 @@ struct nf_conntrack_ecache;
86676 struct nf_proto_net {
86677 #ifdef CONFIG_SYSCTL
86678 struct ctl_table_header *ctl_table_header;
86679- struct ctl_table *ctl_table;
86680+ ctl_table_no_const *ctl_table;
86681 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
86682 struct ctl_table_header *ctl_compat_header;
86683- struct ctl_table *ctl_compat_table;
86684+ ctl_table_no_const *ctl_compat_table;
86685 #endif
86686 #endif
86687 unsigned int users;
86688@@ -60,7 +60,7 @@ struct nf_ip_net {
86689 struct nf_icmp_net icmpv6;
86690 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
86691 struct ctl_table_header *ctl_table_header;
86692- struct ctl_table *ctl_table;
86693+ ctl_table_no_const *ctl_table;
86694 #endif
86695 };
86696
86697diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
86698index aec5e12..807233f 100644
86699--- a/include/net/netns/ipv4.h
86700+++ b/include/net/netns/ipv4.h
86701@@ -82,7 +82,7 @@ struct netns_ipv4 {
86702
86703 struct ping_group_range ping_group_range;
86704
86705- atomic_t dev_addr_genid;
86706+ atomic_unchecked_t dev_addr_genid;
86707
86708 #ifdef CONFIG_SYSCTL
86709 unsigned long *sysctl_local_reserved_ports;
86710@@ -96,6 +96,6 @@ struct netns_ipv4 {
86711 struct fib_rules_ops *mr_rules_ops;
86712 #endif
86713 #endif
86714- atomic_t rt_genid;
86715+ atomic_unchecked_t rt_genid;
86716 };
86717 #endif
86718diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
86719index eade27a..42894dd 100644
86720--- a/include/net/netns/ipv6.h
86721+++ b/include/net/netns/ipv6.h
86722@@ -75,8 +75,8 @@ struct netns_ipv6 {
86723 struct fib_rules_ops *mr6_rules_ops;
86724 #endif
86725 #endif
86726- atomic_t dev_addr_genid;
86727- atomic_t rt_genid;
86728+ atomic_unchecked_t dev_addr_genid;
86729+ atomic_unchecked_t rt_genid;
86730 };
86731
86732 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
86733diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
86734index 3492434..209f58c 100644
86735--- a/include/net/netns/xfrm.h
86736+++ b/include/net/netns/xfrm.h
86737@@ -64,7 +64,7 @@ struct netns_xfrm {
86738
86739 /* flow cache part */
86740 struct flow_cache flow_cache_global;
86741- atomic_t flow_cache_genid;
86742+ atomic_unchecked_t flow_cache_genid;
86743 struct list_head flow_cache_gc_list;
86744 spinlock_t flow_cache_gc_lock;
86745 struct work_struct flow_cache_gc_work;
86746diff --git a/include/net/ping.h b/include/net/ping.h
86747index 026479b..d9b2829 100644
86748--- a/include/net/ping.h
86749+++ b/include/net/ping.h
86750@@ -54,7 +54,7 @@ struct ping_iter_state {
86751
86752 extern struct proto ping_prot;
86753 #if IS_ENABLED(CONFIG_IPV6)
86754-extern struct pingv6_ops pingv6_ops;
86755+extern struct pingv6_ops *pingv6_ops;
86756 #endif
86757
86758 struct pingfakehdr {
86759diff --git a/include/net/protocol.h b/include/net/protocol.h
86760index d6fcc1f..ca277058 100644
86761--- a/include/net/protocol.h
86762+++ b/include/net/protocol.h
86763@@ -49,7 +49,7 @@ struct net_protocol {
86764 * socket lookup?
86765 */
86766 icmp_strict_tag_validation:1;
86767-};
86768+} __do_const;
86769
86770 #if IS_ENABLED(CONFIG_IPV6)
86771 struct inet6_protocol {
86772@@ -62,7 +62,7 @@ struct inet6_protocol {
86773 u8 type, u8 code, int offset,
86774 __be32 info);
86775 unsigned int flags; /* INET6_PROTO_xxx */
86776-};
86777+} __do_const;
86778
86779 #define INET6_PROTO_NOPOLICY 0x1
86780 #define INET6_PROTO_FINAL 0x2
86781diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
86782index e21b9f9..0191ef0 100644
86783--- a/include/net/rtnetlink.h
86784+++ b/include/net/rtnetlink.h
86785@@ -93,7 +93,7 @@ struct rtnl_link_ops {
86786 int (*fill_slave_info)(struct sk_buff *skb,
86787 const struct net_device *dev,
86788 const struct net_device *slave_dev);
86789-};
86790+} __do_const;
86791
86792 int __rtnl_link_register(struct rtnl_link_ops *ops);
86793 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
86794diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
86795index 4a5b9a3..ca27d73 100644
86796--- a/include/net/sctp/checksum.h
86797+++ b/include/net/sctp/checksum.h
86798@@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
86799 unsigned int offset)
86800 {
86801 struct sctphdr *sh = sctp_hdr(skb);
86802- __le32 ret, old = sh->checksum;
86803- const struct skb_checksum_ops ops = {
86804+ __le32 ret, old = sh->checksum;
86805+ static const struct skb_checksum_ops ops = {
86806 .update = sctp_csum_update,
86807 .combine = sctp_csum_combine,
86808 };
86809diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
86810index 9fbd856..856f01c 100644
86811--- a/include/net/sctp/sctp.h
86812+++ b/include/net/sctp/sctp.h
86813@@ -426,6 +426,11 @@ static inline void sctp_assoc_pending_pmtu(struct sock *sk, struct sctp_associat
86814 asoc->pmtu_pending = 0;
86815 }
86816
86817+static inline bool sctp_chunk_pending(const struct sctp_chunk *chunk)
86818+{
86819+ return !list_empty(&chunk->list);
86820+}
86821+
86822 /* Walk through a list of TLV parameters. Don't trust the
86823 * individual parameter lengths and instead depend on
86824 * the chunk length to indicate when to stop. Make sure
86825diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
86826index 7f4eeb3..aaa63d9 100644
86827--- a/include/net/sctp/sm.h
86828+++ b/include/net/sctp/sm.h
86829@@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
86830 typedef struct {
86831 sctp_state_fn_t *fn;
86832 const char *name;
86833-} sctp_sm_table_entry_t;
86834+} __do_const sctp_sm_table_entry_t;
86835
86836 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
86837 * currently in use.
86838@@ -248,9 +248,9 @@ struct sctp_chunk *sctp_make_asconf_update_ip(struct sctp_association *,
86839 int, __be16);
86840 struct sctp_chunk *sctp_make_asconf_set_prim(struct sctp_association *asoc,
86841 union sctp_addr *addr);
86842-int sctp_verify_asconf(const struct sctp_association *asoc,
86843- struct sctp_paramhdr *param_hdr, void *chunk_end,
86844- struct sctp_paramhdr **errp);
86845+bool sctp_verify_asconf(const struct sctp_association *asoc,
86846+ struct sctp_chunk *chunk, bool addr_param_needed,
86847+ struct sctp_paramhdr **errp);
86848 struct sctp_chunk *sctp_process_asconf(struct sctp_association *asoc,
86849 struct sctp_chunk *asconf);
86850 int sctp_process_asconf_ack(struct sctp_association *asoc,
86851@@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
86852 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
86853
86854 /* Extern declarations for major data structures. */
86855-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86856+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
86857
86858
86859 /* Get the size of a DATA chunk payload. */
86860diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
86861index 4ff3f67..89ae38e 100644
86862--- a/include/net/sctp/structs.h
86863+++ b/include/net/sctp/structs.h
86864@@ -509,7 +509,7 @@ struct sctp_pf {
86865 void (*to_sk_saddr)(union sctp_addr *, struct sock *sk);
86866 void (*to_sk_daddr)(union sctp_addr *, struct sock *sk);
86867 struct sctp_af *af;
86868-};
86869+} __do_const;
86870
86871
86872 /* Structure to track chunk fragments that have been acked, but peer
86873diff --git a/include/net/sock.h b/include/net/sock.h
86874index b9a5bd0..dcd5f3c 100644
86875--- a/include/net/sock.h
86876+++ b/include/net/sock.h
86877@@ -356,7 +356,7 @@ struct sock {
86878 unsigned int sk_napi_id;
86879 unsigned int sk_ll_usec;
86880 #endif
86881- atomic_t sk_drops;
86882+ atomic_unchecked_t sk_drops;
86883 int sk_rcvbuf;
86884
86885 struct sk_filter __rcu *sk_filter;
86886@@ -1053,7 +1053,7 @@ struct proto {
86887 void (*destroy_cgroup)(struct mem_cgroup *memcg);
86888 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
86889 #endif
86890-};
86891+} __randomize_layout;
86892
86893 /*
86894 * Bits in struct cg_proto.flags
86895@@ -1240,7 +1240,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
86896 return ret >> PAGE_SHIFT;
86897 }
86898
86899-static inline long
86900+static inline long __intentional_overflow(-1)
86901 sk_memory_allocated(const struct sock *sk)
86902 {
86903 struct proto *prot = sk->sk_prot;
86904@@ -1385,7 +1385,7 @@ struct sock_iocb {
86905 struct scm_cookie *scm;
86906 struct msghdr *msg, async_msg;
86907 struct kiocb *kiocb;
86908-};
86909+} __randomize_layout;
86910
86911 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
86912 {
86913@@ -1820,7 +1820,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
86914 }
86915
86916 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
86917- char __user *from, char *to,
86918+ char __user *from, unsigned char *to,
86919 int copy, int offset)
86920 {
86921 if (skb->ip_summed == CHECKSUM_NONE) {
86922@@ -2091,7 +2091,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
86923 }
86924 }
86925
86926-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86927+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
86928
86929 /**
86930 * sk_page_frag - return an appropriate page_frag
86931diff --git a/include/net/tcp.h b/include/net/tcp.h
86932index 590e01a..76498f3 100644
86933--- a/include/net/tcp.h
86934+++ b/include/net/tcp.h
86935@@ -523,7 +523,7 @@ void tcp_retransmit_timer(struct sock *sk);
86936 void tcp_xmit_retransmit_queue(struct sock *);
86937 void tcp_simple_retransmit(struct sock *);
86938 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
86939-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86940+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int, gfp_t);
86941
86942 void tcp_send_probe0(struct sock *);
86943 void tcp_send_partial(struct sock *);
86944@@ -696,8 +696,8 @@ struct tcp_skb_cb {
86945 struct inet6_skb_parm h6;
86946 #endif
86947 } header; /* For incoming frames */
86948- __u32 seq; /* Starting sequence number */
86949- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
86950+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
86951+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
86952 __u32 when; /* used to compute rtt's */
86953 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
86954
86955@@ -713,7 +713,7 @@ struct tcp_skb_cb {
86956
86957 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
86958 /* 1 byte hole */
86959- __u32 ack_seq; /* Sequence number ACK'd */
86960+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
86961 };
86962
86963 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
86964diff --git a/include/net/xfrm.h b/include/net/xfrm.h
86965index 721e9c3b..3c81bbf 100644
86966--- a/include/net/xfrm.h
86967+++ b/include/net/xfrm.h
86968@@ -285,7 +285,6 @@ struct xfrm_dst;
86969 struct xfrm_policy_afinfo {
86970 unsigned short family;
86971 struct dst_ops *dst_ops;
86972- void (*garbage_collect)(struct net *net);
86973 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
86974 const xfrm_address_t *saddr,
86975 const xfrm_address_t *daddr);
86976@@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
86977 struct net_device *dev,
86978 const struct flowi *fl);
86979 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
86980-};
86981+} __do_const;
86982
86983 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
86984 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
86985@@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
86986 int (*transport_finish)(struct sk_buff *skb,
86987 int async);
86988 void (*local_error)(struct sk_buff *skb, u32 mtu);
86989-};
86990+} __do_const;
86991
86992 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
86993 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
86994@@ -437,7 +436,7 @@ struct xfrm_mode {
86995 struct module *owner;
86996 unsigned int encap;
86997 int flags;
86998-};
86999+} __do_const;
87000
87001 /* Flags for xfrm_mode. */
87002 enum {
87003@@ -534,7 +533,7 @@ struct xfrm_policy {
87004 struct timer_list timer;
87005
87006 struct flow_cache_object flo;
87007- atomic_t genid;
87008+ atomic_unchecked_t genid;
87009 u32 priority;
87010 u32 index;
87011 struct xfrm_mark mark;
87012@@ -1167,6 +1166,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
87013 }
87014
87015 void xfrm_garbage_collect(struct net *net);
87016+void xfrm_garbage_collect_deferred(struct net *net);
87017
87018 #else
87019
87020@@ -1205,6 +1205,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
87021 static inline void xfrm_garbage_collect(struct net *net)
87022 {
87023 }
87024+static inline void xfrm_garbage_collect_deferred(struct net *net)
87025+{
87026+}
87027 #endif
87028
87029 static __inline__
87030diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
87031index 1017e0b..227aa4d 100644
87032--- a/include/rdma/iw_cm.h
87033+++ b/include/rdma/iw_cm.h
87034@@ -122,7 +122,7 @@ struct iw_cm_verbs {
87035 int backlog);
87036
87037 int (*destroy_listen)(struct iw_cm_id *cm_id);
87038-};
87039+} __no_const;
87040
87041 /**
87042 * iw_create_cm_id - Create an IW CM identifier.
87043diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
87044index 52beadf..598734c 100644
87045--- a/include/scsi/libfc.h
87046+++ b/include/scsi/libfc.h
87047@@ -771,6 +771,7 @@ struct libfc_function_template {
87048 */
87049 void (*disc_stop_final) (struct fc_lport *);
87050 };
87051+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
87052
87053 /**
87054 * struct fc_disc - Discovery context
87055@@ -875,7 +876,7 @@ struct fc_lport {
87056 struct fc_vport *vport;
87057
87058 /* Operational Information */
87059- struct libfc_function_template tt;
87060+ libfc_function_template_no_const tt;
87061 u8 link_up;
87062 u8 qfull;
87063 enum fc_lport_state state;
87064diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
87065index 1a0d184..4fb841f 100644
87066--- a/include/scsi/scsi_device.h
87067+++ b/include/scsi/scsi_device.h
87068@@ -185,9 +185,9 @@ struct scsi_device {
87069 unsigned int max_device_blocked; /* what device_blocked counts down from */
87070 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
87071
87072- atomic_t iorequest_cnt;
87073- atomic_t iodone_cnt;
87074- atomic_t ioerr_cnt;
87075+ atomic_unchecked_t iorequest_cnt;
87076+ atomic_unchecked_t iodone_cnt;
87077+ atomic_unchecked_t ioerr_cnt;
87078
87079 struct device sdev_gendev,
87080 sdev_dev;
87081diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
87082index 007a0bc..7188db8 100644
87083--- a/include/scsi/scsi_transport_fc.h
87084+++ b/include/scsi/scsi_transport_fc.h
87085@@ -756,7 +756,8 @@ struct fc_function_template {
87086 unsigned long show_host_system_hostname:1;
87087
87088 unsigned long disable_target_scan:1;
87089-};
87090+} __do_const;
87091+typedef struct fc_function_template __no_const fc_function_template_no_const;
87092
87093
87094 /**
87095diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
87096index ae6c3b8..fd748ac 100644
87097--- a/include/sound/compress_driver.h
87098+++ b/include/sound/compress_driver.h
87099@@ -128,7 +128,7 @@ struct snd_compr_ops {
87100 struct snd_compr_caps *caps);
87101 int (*get_codec_caps) (struct snd_compr_stream *stream,
87102 struct snd_compr_codec_caps *codec);
87103-};
87104+} __no_const;
87105
87106 /**
87107 * struct snd_compr: Compressed device
87108diff --git a/include/sound/soc.h b/include/sound/soc.h
87109index c83a334..27c8038 100644
87110--- a/include/sound/soc.h
87111+++ b/include/sound/soc.h
87112@@ -817,7 +817,7 @@ struct snd_soc_codec_driver {
87113 /* probe ordering - for components with runtime dependencies */
87114 int probe_order;
87115 int remove_order;
87116-};
87117+} __do_const;
87118
87119 /* SoC platform interface */
87120 struct snd_soc_platform_driver {
87121@@ -861,7 +861,7 @@ struct snd_soc_platform_driver {
87122 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
87123 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
87124 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
87125-};
87126+} __do_const;
87127
87128 struct snd_soc_dai_link_component {
87129 const char *name;
87130diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
87131index 9ec9864..e2ee1ee 100644
87132--- a/include/target/target_core_base.h
87133+++ b/include/target/target_core_base.h
87134@@ -761,7 +761,7 @@ struct se_device {
87135 atomic_long_t write_bytes;
87136 /* Active commands on this virtual SE device */
87137 atomic_t simple_cmds;
87138- atomic_t dev_ordered_id;
87139+ atomic_unchecked_t dev_ordered_id;
87140 atomic_t dev_ordered_sync;
87141 atomic_t dev_qf_count;
87142 int export_count;
87143diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
87144new file mode 100644
87145index 0000000..fb634b7
87146--- /dev/null
87147+++ b/include/trace/events/fs.h
87148@@ -0,0 +1,53 @@
87149+#undef TRACE_SYSTEM
87150+#define TRACE_SYSTEM fs
87151+
87152+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
87153+#define _TRACE_FS_H
87154+
87155+#include <linux/fs.h>
87156+#include <linux/tracepoint.h>
87157+
87158+TRACE_EVENT(do_sys_open,
87159+
87160+ TP_PROTO(const char *filename, int flags, int mode),
87161+
87162+ TP_ARGS(filename, flags, mode),
87163+
87164+ TP_STRUCT__entry(
87165+ __string( filename, filename )
87166+ __field( int, flags )
87167+ __field( int, mode )
87168+ ),
87169+
87170+ TP_fast_assign(
87171+ __assign_str(filename, filename);
87172+ __entry->flags = flags;
87173+ __entry->mode = mode;
87174+ ),
87175+
87176+ TP_printk("\"%s\" %x %o",
87177+ __get_str(filename), __entry->flags, __entry->mode)
87178+);
87179+
87180+TRACE_EVENT(open_exec,
87181+
87182+ TP_PROTO(const char *filename),
87183+
87184+ TP_ARGS(filename),
87185+
87186+ TP_STRUCT__entry(
87187+ __string( filename, filename )
87188+ ),
87189+
87190+ TP_fast_assign(
87191+ __assign_str(filename, filename);
87192+ ),
87193+
87194+ TP_printk("\"%s\"",
87195+ __get_str(filename))
87196+);
87197+
87198+#endif /* _TRACE_FS_H */
87199+
87200+/* This part must be outside protection */
87201+#include <trace/define_trace.h>
87202diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
87203index 3608beb..df39d8a 100644
87204--- a/include/trace/events/irq.h
87205+++ b/include/trace/events/irq.h
87206@@ -36,7 +36,7 @@ struct softirq_action;
87207 */
87208 TRACE_EVENT(irq_handler_entry,
87209
87210- TP_PROTO(int irq, struct irqaction *action),
87211+ TP_PROTO(int irq, const struct irqaction *action),
87212
87213 TP_ARGS(irq, action),
87214
87215@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
87216 */
87217 TRACE_EVENT(irq_handler_exit,
87218
87219- TP_PROTO(int irq, struct irqaction *action, int ret),
87220+ TP_PROTO(int irq, const struct irqaction *action, int ret),
87221
87222 TP_ARGS(irq, action, ret),
87223
87224diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
87225index 7caf44c..23c6f27 100644
87226--- a/include/uapi/linux/a.out.h
87227+++ b/include/uapi/linux/a.out.h
87228@@ -39,6 +39,14 @@ enum machine_type {
87229 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
87230 };
87231
87232+/* Constants for the N_FLAGS field */
87233+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87234+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
87235+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
87236+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
87237+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87238+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87239+
87240 #if !defined (N_MAGIC)
87241 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
87242 #endif
87243diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
87244index 22b6ad3..aeba37e 100644
87245--- a/include/uapi/linux/bcache.h
87246+++ b/include/uapi/linux/bcache.h
87247@@ -5,6 +5,7 @@
87248 * Bcache on disk data structures
87249 */
87250
87251+#include <linux/compiler.h>
87252 #include <asm/types.h>
87253
87254 #define BITMASK(name, type, field, offset, size) \
87255@@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
87256 /* Btree keys - all units are in sectors */
87257
87258 struct bkey {
87259- __u64 high;
87260- __u64 low;
87261+ __u64 high __intentional_overflow(-1);
87262+ __u64 low __intentional_overflow(-1);
87263 __u64 ptr[];
87264 };
87265
87266diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
87267index d876736..ccce5c0 100644
87268--- a/include/uapi/linux/byteorder/little_endian.h
87269+++ b/include/uapi/linux/byteorder/little_endian.h
87270@@ -42,51 +42,51 @@
87271
87272 static inline __le64 __cpu_to_le64p(const __u64 *p)
87273 {
87274- return (__force __le64)*p;
87275+ return (__force const __le64)*p;
87276 }
87277-static inline __u64 __le64_to_cpup(const __le64 *p)
87278+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
87279 {
87280- return (__force __u64)*p;
87281+ return (__force const __u64)*p;
87282 }
87283 static inline __le32 __cpu_to_le32p(const __u32 *p)
87284 {
87285- return (__force __le32)*p;
87286+ return (__force const __le32)*p;
87287 }
87288 static inline __u32 __le32_to_cpup(const __le32 *p)
87289 {
87290- return (__force __u32)*p;
87291+ return (__force const __u32)*p;
87292 }
87293 static inline __le16 __cpu_to_le16p(const __u16 *p)
87294 {
87295- return (__force __le16)*p;
87296+ return (__force const __le16)*p;
87297 }
87298 static inline __u16 __le16_to_cpup(const __le16 *p)
87299 {
87300- return (__force __u16)*p;
87301+ return (__force const __u16)*p;
87302 }
87303 static inline __be64 __cpu_to_be64p(const __u64 *p)
87304 {
87305- return (__force __be64)__swab64p(p);
87306+ return (__force const __be64)__swab64p(p);
87307 }
87308 static inline __u64 __be64_to_cpup(const __be64 *p)
87309 {
87310- return __swab64p((__u64 *)p);
87311+ return __swab64p((const __u64 *)p);
87312 }
87313 static inline __be32 __cpu_to_be32p(const __u32 *p)
87314 {
87315- return (__force __be32)__swab32p(p);
87316+ return (__force const __be32)__swab32p(p);
87317 }
87318-static inline __u32 __be32_to_cpup(const __be32 *p)
87319+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
87320 {
87321- return __swab32p((__u32 *)p);
87322+ return __swab32p((const __u32 *)p);
87323 }
87324 static inline __be16 __cpu_to_be16p(const __u16 *p)
87325 {
87326- return (__force __be16)__swab16p(p);
87327+ return (__force const __be16)__swab16p(p);
87328 }
87329 static inline __u16 __be16_to_cpup(const __be16 *p)
87330 {
87331- return __swab16p((__u16 *)p);
87332+ return __swab16p((const __u16 *)p);
87333 }
87334 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
87335 #define __le64_to_cpus(x) do { (void)(x); } while (0)
87336diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
87337index ef6103b..d4e65dd 100644
87338--- a/include/uapi/linux/elf.h
87339+++ b/include/uapi/linux/elf.h
87340@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
87341 #define PT_GNU_EH_FRAME 0x6474e550
87342
87343 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
87344+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
87345+
87346+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
87347+
87348+/* Constants for the e_flags field */
87349+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
87350+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
87351+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
87352+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
87353+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
87354+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
87355
87356 /*
87357 * Extended Numbering
87358@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
87359 #define DT_DEBUG 21
87360 #define DT_TEXTREL 22
87361 #define DT_JMPREL 23
87362+#define DT_FLAGS 30
87363+ #define DF_TEXTREL 0x00000004
87364 #define DT_ENCODING 32
87365 #define OLD_DT_LOOS 0x60000000
87366 #define DT_LOOS 0x6000000d
87367@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
87368 #define PF_W 0x2
87369 #define PF_X 0x1
87370
87371+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
87372+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
87373+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
87374+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
87375+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
87376+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
87377+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
87378+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
87379+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
87380+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
87381+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
87382+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
87383+
87384 typedef struct elf32_phdr{
87385 Elf32_Word p_type;
87386 Elf32_Off p_offset;
87387@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
87388 #define EI_OSABI 7
87389 #define EI_PAD 8
87390
87391+#define EI_PAX 14
87392+
87393 #define ELFMAG0 0x7f /* EI_MAG */
87394 #define ELFMAG1 'E'
87395 #define ELFMAG2 'L'
87396diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
87397index aa169c4..6a2771d 100644
87398--- a/include/uapi/linux/personality.h
87399+++ b/include/uapi/linux/personality.h
87400@@ -30,6 +30,7 @@ enum {
87401 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
87402 ADDR_NO_RANDOMIZE | \
87403 ADDR_COMPAT_LAYOUT | \
87404+ ADDR_LIMIT_3GB | \
87405 MMAP_PAGE_ZERO)
87406
87407 /*
87408diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
87409index 7530e74..e714828 100644
87410--- a/include/uapi/linux/screen_info.h
87411+++ b/include/uapi/linux/screen_info.h
87412@@ -43,7 +43,8 @@ struct screen_info {
87413 __u16 pages; /* 0x32 */
87414 __u16 vesa_attributes; /* 0x34 */
87415 __u32 capabilities; /* 0x36 */
87416- __u8 _reserved[6]; /* 0x3a */
87417+ __u16 vesapm_size; /* 0x3a */
87418+ __u8 _reserved[4]; /* 0x3c */
87419 } __attribute__((packed));
87420
87421 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
87422diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
87423index 0e011eb..82681b1 100644
87424--- a/include/uapi/linux/swab.h
87425+++ b/include/uapi/linux/swab.h
87426@@ -43,7 +43,7 @@
87427 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
87428 */
87429
87430-static inline __attribute_const__ __u16 __fswab16(__u16 val)
87431+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
87432 {
87433 #ifdef __HAVE_BUILTIN_BSWAP16__
87434 return __builtin_bswap16(val);
87435@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
87436 #endif
87437 }
87438
87439-static inline __attribute_const__ __u32 __fswab32(__u32 val)
87440+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
87441 {
87442 #ifdef __HAVE_BUILTIN_BSWAP32__
87443 return __builtin_bswap32(val);
87444@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
87445 #endif
87446 }
87447
87448-static inline __attribute_const__ __u64 __fswab64(__u64 val)
87449+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
87450 {
87451 #ifdef __HAVE_BUILTIN_BSWAP64__
87452 return __builtin_bswap64(val);
87453diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
87454index 43aaba1..1c30b48 100644
87455--- a/include/uapi/linux/sysctl.h
87456+++ b/include/uapi/linux/sysctl.h
87457@@ -155,8 +155,6 @@ enum
87458 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
87459 };
87460
87461-
87462-
87463 /* CTL_VM names: */
87464 enum
87465 {
87466diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
87467index 778a329..1416ffb 100644
87468--- a/include/uapi/linux/videodev2.h
87469+++ b/include/uapi/linux/videodev2.h
87470@@ -1285,7 +1285,7 @@ struct v4l2_ext_control {
87471 union {
87472 __s32 value;
87473 __s64 value64;
87474- char *string;
87475+ char __user *string;
87476 __u8 *p_u8;
87477 __u16 *p_u16;
87478 __u32 *p_u32;
87479diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
87480index 1590c49..5eab462 100644
87481--- a/include/uapi/linux/xattr.h
87482+++ b/include/uapi/linux/xattr.h
87483@@ -73,5 +73,9 @@
87484 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
87485 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
87486
87487+/* User namespace */
87488+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
87489+#define XATTR_PAX_FLAGS_SUFFIX "flags"
87490+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
87491
87492 #endif /* _UAPI_LINUX_XATTR_H */
87493diff --git a/include/video/udlfb.h b/include/video/udlfb.h
87494index f9466fa..f4e2b81 100644
87495--- a/include/video/udlfb.h
87496+++ b/include/video/udlfb.h
87497@@ -53,10 +53,10 @@ struct dlfb_data {
87498 u32 pseudo_palette[256];
87499 int blank_mode; /*one of FB_BLANK_ */
87500 /* blit-only rendering path metrics, exposed through sysfs */
87501- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87502- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
87503- atomic_t bytes_sent; /* to usb, after compression including overhead */
87504- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
87505+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
87506+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
87507+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
87508+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
87509 };
87510
87511 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
87512diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
87513index 30f5362..8ed8ac9 100644
87514--- a/include/video/uvesafb.h
87515+++ b/include/video/uvesafb.h
87516@@ -122,6 +122,7 @@ struct uvesafb_par {
87517 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
87518 u8 pmi_setpal; /* PMI for palette changes */
87519 u16 *pmi_base; /* protected mode interface location */
87520+ u8 *pmi_code; /* protected mode code location */
87521 void *pmi_start;
87522 void *pmi_pal;
87523 u8 *vbe_state_orig; /*
87524diff --git a/init/Kconfig b/init/Kconfig
87525index 80a6907..baf7d53 100644
87526--- a/init/Kconfig
87527+++ b/init/Kconfig
87528@@ -1150,6 +1150,7 @@ endif # CGROUPS
87529
87530 config CHECKPOINT_RESTORE
87531 bool "Checkpoint/restore support" if EXPERT
87532+ depends on !GRKERNSEC
87533 default n
87534 help
87535 Enables additional kernel features in a sake of checkpoint/restore.
87536@@ -1635,7 +1636,7 @@ config SLUB_DEBUG
87537
87538 config COMPAT_BRK
87539 bool "Disable heap randomization"
87540- default y
87541+ default n
87542 help
87543 Randomizing heap placement makes heap exploits harder, but it
87544 also breaks ancient binaries (including anything libc5 based).
87545@@ -1923,7 +1924,7 @@ config INIT_ALL_POSSIBLE
87546 config STOP_MACHINE
87547 bool
87548 default y
87549- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
87550+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
87551 help
87552 Need stop_machine() primitive.
87553
87554diff --git a/init/Makefile b/init/Makefile
87555index 7bc47ee..6da2dc7 100644
87556--- a/init/Makefile
87557+++ b/init/Makefile
87558@@ -2,6 +2,9 @@
87559 # Makefile for the linux kernel.
87560 #
87561
87562+ccflags-y := $(GCC_PLUGINS_CFLAGS)
87563+asflags-y := $(GCC_PLUGINS_AFLAGS)
87564+
87565 obj-y := main.o version.o mounts.o
87566 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
87567 obj-y += noinitramfs.o
87568diff --git a/init/do_mounts.c b/init/do_mounts.c
87569index 82f2288..ea1430a 100644
87570--- a/init/do_mounts.c
87571+++ b/init/do_mounts.c
87572@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
87573 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
87574 {
87575 struct super_block *s;
87576- int err = sys_mount(name, "/root", fs, flags, data);
87577+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
87578 if (err)
87579 return err;
87580
87581- sys_chdir("/root");
87582+ sys_chdir((const char __force_user *)"/root");
87583 s = current->fs->pwd.dentry->d_sb;
87584 ROOT_DEV = s->s_dev;
87585 printk(KERN_INFO
87586@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
87587 va_start(args, fmt);
87588 vsprintf(buf, fmt, args);
87589 va_end(args);
87590- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
87591+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
87592 if (fd >= 0) {
87593 sys_ioctl(fd, FDEJECT, 0);
87594 sys_close(fd);
87595 }
87596 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
87597- fd = sys_open("/dev/console", O_RDWR, 0);
87598+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
87599 if (fd >= 0) {
87600 sys_ioctl(fd, TCGETS, (long)&termios);
87601 termios.c_lflag &= ~ICANON;
87602 sys_ioctl(fd, TCSETSF, (long)&termios);
87603- sys_read(fd, &c, 1);
87604+ sys_read(fd, (char __user *)&c, 1);
87605 termios.c_lflag |= ICANON;
87606 sys_ioctl(fd, TCSETSF, (long)&termios);
87607 sys_close(fd);
87608@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
87609 mount_root();
87610 out:
87611 devtmpfs_mount("dev");
87612- sys_mount(".", "/", NULL, MS_MOVE, NULL);
87613- sys_chroot(".");
87614+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87615+ sys_chroot((const char __force_user *)".");
87616 }
87617
87618 static bool is_tmpfs;
87619diff --git a/init/do_mounts.h b/init/do_mounts.h
87620index f5b978a..69dbfe8 100644
87621--- a/init/do_mounts.h
87622+++ b/init/do_mounts.h
87623@@ -15,15 +15,15 @@ extern int root_mountflags;
87624
87625 static inline int create_dev(char *name, dev_t dev)
87626 {
87627- sys_unlink(name);
87628- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
87629+ sys_unlink((char __force_user *)name);
87630+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
87631 }
87632
87633 #if BITS_PER_LONG == 32
87634 static inline u32 bstat(char *name)
87635 {
87636 struct stat64 stat;
87637- if (sys_stat64(name, &stat) != 0)
87638+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
87639 return 0;
87640 if (!S_ISBLK(stat.st_mode))
87641 return 0;
87642@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
87643 static inline u32 bstat(char *name)
87644 {
87645 struct stat stat;
87646- if (sys_newstat(name, &stat) != 0)
87647+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
87648 return 0;
87649 if (!S_ISBLK(stat.st_mode))
87650 return 0;
87651diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
87652index 3e0878e..8a9d7a0 100644
87653--- a/init/do_mounts_initrd.c
87654+++ b/init/do_mounts_initrd.c
87655@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
87656 {
87657 sys_unshare(CLONE_FS | CLONE_FILES);
87658 /* stdin/stdout/stderr for /linuxrc */
87659- sys_open("/dev/console", O_RDWR, 0);
87660+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
87661 sys_dup(0);
87662 sys_dup(0);
87663 /* move initrd over / and chdir/chroot in initrd root */
87664- sys_chdir("/root");
87665- sys_mount(".", "/", NULL, MS_MOVE, NULL);
87666- sys_chroot(".");
87667+ sys_chdir((const char __force_user *)"/root");
87668+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
87669+ sys_chroot((const char __force_user *)".");
87670 sys_setsid();
87671 return 0;
87672 }
87673@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
87674 create_dev("/dev/root.old", Root_RAM0);
87675 /* mount initrd on rootfs' /root */
87676 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
87677- sys_mkdir("/old", 0700);
87678- sys_chdir("/old");
87679+ sys_mkdir((const char __force_user *)"/old", 0700);
87680+ sys_chdir((const char __force_user *)"/old");
87681
87682 /* try loading default modules from initrd */
87683 load_default_modules();
87684@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
87685 current->flags &= ~PF_FREEZER_SKIP;
87686
87687 /* move initrd to rootfs' /old */
87688- sys_mount("..", ".", NULL, MS_MOVE, NULL);
87689+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
87690 /* switch root and cwd back to / of rootfs */
87691- sys_chroot("..");
87692+ sys_chroot((const char __force_user *)"..");
87693
87694 if (new_decode_dev(real_root_dev) == Root_RAM0) {
87695- sys_chdir("/old");
87696+ sys_chdir((const char __force_user *)"/old");
87697 return;
87698 }
87699
87700- sys_chdir("/");
87701+ sys_chdir((const char __force_user *)"/");
87702 ROOT_DEV = new_decode_dev(real_root_dev);
87703 mount_root();
87704
87705 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
87706- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
87707+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
87708 if (!error)
87709 printk("okay\n");
87710 else {
87711- int fd = sys_open("/dev/root.old", O_RDWR, 0);
87712+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
87713 if (error == -ENOENT)
87714 printk("/initrd does not exist. Ignored.\n");
87715 else
87716 printk("failed\n");
87717 printk(KERN_NOTICE "Unmounting old root\n");
87718- sys_umount("/old", MNT_DETACH);
87719+ sys_umount((char __force_user *)"/old", MNT_DETACH);
87720 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
87721 if (fd < 0) {
87722 error = fd;
87723@@ -127,11 +127,11 @@ int __init initrd_load(void)
87724 * mounted in the normal path.
87725 */
87726 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
87727- sys_unlink("/initrd.image");
87728+ sys_unlink((const char __force_user *)"/initrd.image");
87729 handle_initrd();
87730 return 1;
87731 }
87732 }
87733- sys_unlink("/initrd.image");
87734+ sys_unlink((const char __force_user *)"/initrd.image");
87735 return 0;
87736 }
87737diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
87738index 8cb6db5..d729f50 100644
87739--- a/init/do_mounts_md.c
87740+++ b/init/do_mounts_md.c
87741@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
87742 partitioned ? "_d" : "", minor,
87743 md_setup_args[ent].device_names);
87744
87745- fd = sys_open(name, 0, 0);
87746+ fd = sys_open((char __force_user *)name, 0, 0);
87747 if (fd < 0) {
87748 printk(KERN_ERR "md: open failed - cannot start "
87749 "array %s\n", name);
87750@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
87751 * array without it
87752 */
87753 sys_close(fd);
87754- fd = sys_open(name, 0, 0);
87755+ fd = sys_open((char __force_user *)name, 0, 0);
87756 sys_ioctl(fd, BLKRRPART, 0);
87757 }
87758 sys_close(fd);
87759@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
87760
87761 wait_for_device_probe();
87762
87763- fd = sys_open("/dev/md0", 0, 0);
87764+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
87765 if (fd >= 0) {
87766 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
87767 sys_close(fd);
87768diff --git a/init/init_task.c b/init/init_task.c
87769index ba0a7f36..2bcf1d5 100644
87770--- a/init/init_task.c
87771+++ b/init/init_task.c
87772@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
87773 * Initial thread structure. Alignment of this is handled by a special
87774 * linker map entry.
87775 */
87776+#ifdef CONFIG_X86
87777+union thread_union init_thread_union __init_task_data;
87778+#else
87779 union thread_union init_thread_union __init_task_data =
87780 { INIT_THREAD_INFO(init_task) };
87781+#endif
87782diff --git a/init/initramfs.c b/init/initramfs.c
87783index bece48c..e911bd8 100644
87784--- a/init/initramfs.c
87785+++ b/init/initramfs.c
87786@@ -25,7 +25,7 @@ static ssize_t __init xwrite(int fd, const char *p, size_t count)
87787
87788 /* sys_write only can write MAX_RW_COUNT aka 2G-4K bytes at most */
87789 while (count) {
87790- ssize_t rv = sys_write(fd, p, count);
87791+ ssize_t rv = sys_write(fd, (char __force_user *)p, count);
87792
87793 if (rv < 0) {
87794 if (rv == -EINTR || rv == -EAGAIN)
87795@@ -107,7 +107,7 @@ static void __init free_hash(void)
87796 }
87797 }
87798
87799-static long __init do_utime(char *filename, time_t mtime)
87800+static long __init do_utime(char __force_user *filename, time_t mtime)
87801 {
87802 struct timespec t[2];
87803
87804@@ -142,7 +142,7 @@ static void __init dir_utime(void)
87805 struct dir_entry *de, *tmp;
87806 list_for_each_entry_safe(de, tmp, &dir_list, list) {
87807 list_del(&de->list);
87808- do_utime(de->name, de->mtime);
87809+ do_utime((char __force_user *)de->name, de->mtime);
87810 kfree(de->name);
87811 kfree(de);
87812 }
87813@@ -304,7 +304,7 @@ static int __init maybe_link(void)
87814 if (nlink >= 2) {
87815 char *old = find_link(major, minor, ino, mode, collected);
87816 if (old)
87817- return (sys_link(old, collected) < 0) ? -1 : 1;
87818+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
87819 }
87820 return 0;
87821 }
87822@@ -313,11 +313,11 @@ static void __init clean_path(char *path, umode_t mode)
87823 {
87824 struct stat st;
87825
87826- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
87827+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
87828 if (S_ISDIR(st.st_mode))
87829- sys_rmdir(path);
87830+ sys_rmdir((char __force_user *)path);
87831 else
87832- sys_unlink(path);
87833+ sys_unlink((char __force_user *)path);
87834 }
87835 }
87836
87837@@ -338,7 +338,7 @@ static int __init do_name(void)
87838 int openflags = O_WRONLY|O_CREAT;
87839 if (ml != 1)
87840 openflags |= O_TRUNC;
87841- wfd = sys_open(collected, openflags, mode);
87842+ wfd = sys_open((char __force_user *)collected, openflags, mode);
87843
87844 if (wfd >= 0) {
87845 sys_fchown(wfd, uid, gid);
87846@@ -350,17 +350,17 @@ static int __init do_name(void)
87847 }
87848 }
87849 } else if (S_ISDIR(mode)) {
87850- sys_mkdir(collected, mode);
87851- sys_chown(collected, uid, gid);
87852- sys_chmod(collected, mode);
87853+ sys_mkdir((char __force_user *)collected, mode);
87854+ sys_chown((char __force_user *)collected, uid, gid);
87855+ sys_chmod((char __force_user *)collected, mode);
87856 dir_add(collected, mtime);
87857 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
87858 S_ISFIFO(mode) || S_ISSOCK(mode)) {
87859 if (maybe_link() == 0) {
87860- sys_mknod(collected, mode, rdev);
87861- sys_chown(collected, uid, gid);
87862- sys_chmod(collected, mode);
87863- do_utime(collected, mtime);
87864+ sys_mknod((char __force_user *)collected, mode, rdev);
87865+ sys_chown((char __force_user *)collected, uid, gid);
87866+ sys_chmod((char __force_user *)collected, mode);
87867+ do_utime((char __force_user *)collected, mtime);
87868 }
87869 }
87870 return 0;
87871@@ -372,7 +372,7 @@ static int __init do_copy(void)
87872 if (xwrite(wfd, victim, body_len) != body_len)
87873 error("write error");
87874 sys_close(wfd);
87875- do_utime(vcollected, mtime);
87876+ do_utime((char __force_user *)vcollected, mtime);
87877 kfree(vcollected);
87878 eat(body_len);
87879 state = SkipIt;
87880@@ -390,9 +390,9 @@ static int __init do_symlink(void)
87881 {
87882 collected[N_ALIGN(name_len) + body_len] = '\0';
87883 clean_path(collected, 0);
87884- sys_symlink(collected + N_ALIGN(name_len), collected);
87885- sys_lchown(collected, uid, gid);
87886- do_utime(collected, mtime);
87887+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
87888+ sys_lchown((char __force_user *)collected, uid, gid);
87889+ do_utime((char __force_user *)collected, mtime);
87890 state = SkipIt;
87891 next_state = Reset;
87892 return 0;
87893diff --git a/init/main.c b/init/main.c
87894index bb1aed9..64f9745 100644
87895--- a/init/main.c
87896+++ b/init/main.c
87897@@ -98,6 +98,8 @@ extern void radix_tree_init(void);
87898 static inline void mark_rodata_ro(void) { }
87899 #endif
87900
87901+extern void grsecurity_init(void);
87902+
87903 /*
87904 * Debug helper: via this flag we know that we are in 'early bootup code'
87905 * where only the boot processor is running with IRQ disabled. This means
87906@@ -159,6 +161,75 @@ static int __init set_reset_devices(char *str)
87907
87908 __setup("reset_devices", set_reset_devices);
87909
87910+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
87911+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
87912+static int __init setup_grsec_proc_gid(char *str)
87913+{
87914+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
87915+ return 1;
87916+}
87917+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
87918+#endif
87919+
87920+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
87921+unsigned long pax_user_shadow_base __read_only;
87922+EXPORT_SYMBOL(pax_user_shadow_base);
87923+extern char pax_enter_kernel_user[];
87924+extern char pax_exit_kernel_user[];
87925+#endif
87926+
87927+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
87928+static int __init setup_pax_nouderef(char *str)
87929+{
87930+#ifdef CONFIG_X86_32
87931+ unsigned int cpu;
87932+ struct desc_struct *gdt;
87933+
87934+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
87935+ gdt = get_cpu_gdt_table(cpu);
87936+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
87937+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
87938+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
87939+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
87940+ }
87941+ loadsegment(ds, __KERNEL_DS);
87942+ loadsegment(es, __KERNEL_DS);
87943+ loadsegment(ss, __KERNEL_DS);
87944+#else
87945+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
87946+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
87947+ clone_pgd_mask = ~(pgdval_t)0UL;
87948+ pax_user_shadow_base = 0UL;
87949+ setup_clear_cpu_cap(X86_FEATURE_PCID);
87950+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
87951+#endif
87952+
87953+ return 0;
87954+}
87955+early_param("pax_nouderef", setup_pax_nouderef);
87956+
87957+#ifdef CONFIG_X86_64
87958+static int __init setup_pax_weakuderef(char *str)
87959+{
87960+ if (clone_pgd_mask != ~(pgdval_t)0UL)
87961+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
87962+ return 1;
87963+}
87964+__setup("pax_weakuderef", setup_pax_weakuderef);
87965+#endif
87966+#endif
87967+
87968+#ifdef CONFIG_PAX_SOFTMODE
87969+int pax_softmode;
87970+
87971+static int __init setup_pax_softmode(char *str)
87972+{
87973+ get_option(&str, &pax_softmode);
87974+ return 1;
87975+}
87976+__setup("pax_softmode=", setup_pax_softmode);
87977+#endif
87978+
87979 static const char *argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
87980 const char *envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
87981 static const char *panic_later, *panic_param;
87982@@ -728,7 +799,7 @@ static bool __init_or_module initcall_blacklisted(initcall_t fn)
87983 struct blacklist_entry *entry;
87984 char *fn_name;
87985
87986- fn_name = kasprintf(GFP_KERNEL, "%pf", fn);
87987+ fn_name = kasprintf(GFP_KERNEL, "%pX", fn);
87988 if (!fn_name)
87989 return false;
87990
87991@@ -780,7 +851,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
87992 {
87993 int count = preempt_count();
87994 int ret;
87995- char msgbuf[64];
87996+ const char *msg1 = "", *msg2 = "";
87997
87998 if (initcall_blacklisted(fn))
87999 return -EPERM;
88000@@ -790,18 +861,17 @@ int __init_or_module do_one_initcall(initcall_t fn)
88001 else
88002 ret = fn();
88003
88004- msgbuf[0] = 0;
88005-
88006 if (preempt_count() != count) {
88007- sprintf(msgbuf, "preemption imbalance ");
88008+ msg1 = " preemption imbalance";
88009 preempt_count_set(count);
88010 }
88011 if (irqs_disabled()) {
88012- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
88013+ msg2 = " disabled interrupts";
88014 local_irq_enable();
88015 }
88016- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
88017+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
88018
88019+ add_latent_entropy();
88020 return ret;
88021 }
88022
88023@@ -908,8 +978,8 @@ static int run_init_process(const char *init_filename)
88024 {
88025 argv_init[0] = init_filename;
88026 return do_execve(getname_kernel(init_filename),
88027- (const char __user *const __user *)argv_init,
88028- (const char __user *const __user *)envp_init);
88029+ (const char __user *const __force_user *)argv_init,
88030+ (const char __user *const __force_user *)envp_init);
88031 }
88032
88033 static int try_to_run_init_process(const char *init_filename)
88034@@ -926,6 +996,10 @@ static int try_to_run_init_process(const char *init_filename)
88035 return ret;
88036 }
88037
88038+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
88039+extern int gr_init_ran;
88040+#endif
88041+
88042 static noinline void __init kernel_init_freeable(void);
88043
88044 static int __ref kernel_init(void *unused)
88045@@ -950,6 +1024,11 @@ static int __ref kernel_init(void *unused)
88046 ramdisk_execute_command, ret);
88047 }
88048
88049+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
88050+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
88051+ gr_init_ran = 1;
88052+#endif
88053+
88054 /*
88055 * We try each of these until one succeeds.
88056 *
88057@@ -1005,7 +1084,7 @@ static noinline void __init kernel_init_freeable(void)
88058 do_basic_setup();
88059
88060 /* Open the /dev/console on the rootfs, this should never fail */
88061- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
88062+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
88063 pr_err("Warning: unable to open an initial console.\n");
88064
88065 (void) sys_dup(0);
88066@@ -1018,11 +1097,13 @@ static noinline void __init kernel_init_freeable(void)
88067 if (!ramdisk_execute_command)
88068 ramdisk_execute_command = "/init";
88069
88070- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
88071+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
88072 ramdisk_execute_command = NULL;
88073 prepare_namespace();
88074 }
88075
88076+ grsecurity_init();
88077+
88078 /*
88079 * Ok, we have completed the initial bootup, and
88080 * we're essentially up and running. Get rid of the
88081diff --git a/ipc/compat.c b/ipc/compat.c
88082index b5ef4f7..ff31d87 100644
88083--- a/ipc/compat.c
88084+++ b/ipc/compat.c
88085@@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
88086 COMPAT_SHMLBA);
88087 if (err < 0)
88088 return err;
88089- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
88090+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
88091 }
88092 case SHMDT:
88093 return sys_shmdt(compat_ptr(ptr));
88094diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
88095index c3f0326..d4e0579 100644
88096--- a/ipc/ipc_sysctl.c
88097+++ b/ipc/ipc_sysctl.c
88098@@ -30,7 +30,7 @@ static void *get_ipc(struct ctl_table *table)
88099 static int proc_ipc_dointvec(struct ctl_table *table, int write,
88100 void __user *buffer, size_t *lenp, loff_t *ppos)
88101 {
88102- struct ctl_table ipc_table;
88103+ ctl_table_no_const ipc_table;
88104
88105 memcpy(&ipc_table, table, sizeof(ipc_table));
88106 ipc_table.data = get_ipc(table);
88107@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(struct ctl_table *table, int write,
88108 static int proc_ipc_dointvec_minmax(struct ctl_table *table, int write,
88109 void __user *buffer, size_t *lenp, loff_t *ppos)
88110 {
88111- struct ctl_table ipc_table;
88112+ ctl_table_no_const ipc_table;
88113
88114 memcpy(&ipc_table, table, sizeof(ipc_table));
88115 ipc_table.data = get_ipc(table);
88116@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(struct ctl_table *table, int write,
88117 static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88118 void __user *buffer, size_t *lenp, loff_t *ppos)
88119 {
88120- struct ctl_table ipc_table;
88121+ ctl_table_no_const ipc_table;
88122 size_t lenp_bef = *lenp;
88123 int rc;
88124
88125@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(struct ctl_table *table, int write,
88126 static int proc_ipc_doulongvec_minmax(struct ctl_table *table, int write,
88127 void __user *buffer, size_t *lenp, loff_t *ppos)
88128 {
88129- struct ctl_table ipc_table;
88130+ ctl_table_no_const ipc_table;
88131 memcpy(&ipc_table, table, sizeof(ipc_table));
88132 ipc_table.data = get_ipc(table);
88133
88134@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
88135 static int proc_ipcauto_dointvec_minmax(struct ctl_table *table, int write,
88136 void __user *buffer, size_t *lenp, loff_t *ppos)
88137 {
88138- struct ctl_table ipc_table;
88139+ ctl_table_no_const ipc_table;
88140 size_t lenp_bef = *lenp;
88141 int oldval;
88142 int rc;
88143diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
88144index 68d4e95..1477ded 100644
88145--- a/ipc/mq_sysctl.c
88146+++ b/ipc/mq_sysctl.c
88147@@ -25,7 +25,7 @@ static void *get_mq(struct ctl_table *table)
88148 static int proc_mq_dointvec(struct ctl_table *table, int write,
88149 void __user *buffer, size_t *lenp, loff_t *ppos)
88150 {
88151- struct ctl_table mq_table;
88152+ ctl_table_no_const mq_table;
88153 memcpy(&mq_table, table, sizeof(mq_table));
88154 mq_table.data = get_mq(table);
88155
88156@@ -35,7 +35,7 @@ static int proc_mq_dointvec(struct ctl_table *table, int write,
88157 static int proc_mq_dointvec_minmax(struct ctl_table *table, int write,
88158 void __user *buffer, size_t *lenp, loff_t *ppos)
88159 {
88160- struct ctl_table mq_table;
88161+ ctl_table_no_const mq_table;
88162 memcpy(&mq_table, table, sizeof(mq_table));
88163 mq_table.data = get_mq(table);
88164
88165diff --git a/ipc/mqueue.c b/ipc/mqueue.c
88166index 4fcf39a..d3cc2ec 100644
88167--- a/ipc/mqueue.c
88168+++ b/ipc/mqueue.c
88169@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
88170 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
88171 info->attr.mq_msgsize);
88172
88173+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
88174 spin_lock(&mq_lock);
88175 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
88176 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
88177diff --git a/ipc/shm.c b/ipc/shm.c
88178index 7fc9f9f..95e201f 100644
88179--- a/ipc/shm.c
88180+++ b/ipc/shm.c
88181@@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
88182 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
88183 #endif
88184
88185+#ifdef CONFIG_GRKERNSEC
88186+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88187+ const u64 shm_createtime, const kuid_t cuid,
88188+ const int shmid);
88189+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
88190+ const u64 shm_createtime);
88191+#endif
88192+
88193 void shm_init_ns(struct ipc_namespace *ns)
88194 {
88195 ns->shm_ctlmax = SHMMAX;
88196@@ -559,6 +567,9 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
88197 shp->shm_lprid = 0;
88198 shp->shm_atim = shp->shm_dtim = 0;
88199 shp->shm_ctim = get_seconds();
88200+#ifdef CONFIG_GRKERNSEC
88201+ shp->shm_createtime = ktime_get_ns();
88202+#endif
88203 shp->shm_segsz = size;
88204 shp->shm_nattch = 0;
88205 shp->shm_file = file;
88206@@ -1095,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88207 f_mode = FMODE_READ | FMODE_WRITE;
88208 }
88209 if (shmflg & SHM_EXEC) {
88210+
88211+#ifdef CONFIG_PAX_MPROTECT
88212+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
88213+ goto out;
88214+#endif
88215+
88216 prot |= PROT_EXEC;
88217 acc_mode |= S_IXUGO;
88218 }
88219@@ -1119,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88220 if (err)
88221 goto out_unlock;
88222
88223+#ifdef CONFIG_GRKERNSEC
88224+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
88225+ shp->shm_perm.cuid, shmid) ||
88226+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
88227+ err = -EACCES;
88228+ goto out_unlock;
88229+ }
88230+#endif
88231+
88232 ipc_lock_object(&shp->shm_perm);
88233
88234 /* check if shm_destroy() is tearing down shp */
88235@@ -1131,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
88236 path = shp->shm_file->f_path;
88237 path_get(&path);
88238 shp->shm_nattch++;
88239+#ifdef CONFIG_GRKERNSEC
88240+ shp->shm_lapid = current->pid;
88241+#endif
88242 size = i_size_read(path.dentry->d_inode);
88243 ipc_unlock_object(&shp->shm_perm);
88244 rcu_read_unlock();
88245diff --git a/ipc/util.c b/ipc/util.c
88246index 27d74e6..8be0be2 100644
88247--- a/ipc/util.c
88248+++ b/ipc/util.c
88249@@ -71,6 +71,8 @@ struct ipc_proc_iface {
88250 int (*show)(struct seq_file *, void *);
88251 };
88252
88253+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
88254+
88255 static void ipc_memory_notifier(struct work_struct *work)
88256 {
88257 ipcns_notify(IPCNS_MEMCHANGED);
88258@@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
88259 granted_mode >>= 6;
88260 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
88261 granted_mode >>= 3;
88262+
88263+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
88264+ return -1;
88265+
88266 /* is there some bit set in requested_mode but not in granted_mode? */
88267 if ((requested_mode & ~granted_mode & 0007) &&
88268 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
88269diff --git a/kernel/audit.c b/kernel/audit.c
88270index ba2ff5a..c6c0deb 100644
88271--- a/kernel/audit.c
88272+++ b/kernel/audit.c
88273@@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
88274 3) suppressed due to audit_rate_limit
88275 4) suppressed due to audit_backlog_limit
88276 */
88277-static atomic_t audit_lost = ATOMIC_INIT(0);
88278+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
88279
88280 /* The netlink socket. */
88281 static struct sock *audit_sock;
88282@@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
88283 unsigned long now;
88284 int print;
88285
88286- atomic_inc(&audit_lost);
88287+ atomic_inc_unchecked(&audit_lost);
88288
88289 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
88290
88291@@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
88292 if (print) {
88293 if (printk_ratelimit())
88294 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
88295- atomic_read(&audit_lost),
88296+ atomic_read_unchecked(&audit_lost),
88297 audit_rate_limit,
88298 audit_backlog_limit);
88299 audit_panic(message);
88300@@ -840,7 +840,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
88301 s.pid = audit_pid;
88302 s.rate_limit = audit_rate_limit;
88303 s.backlog_limit = audit_backlog_limit;
88304- s.lost = atomic_read(&audit_lost);
88305+ s.lost = atomic_read_unchecked(&audit_lost);
88306 s.backlog = skb_queue_len(&audit_skb_queue);
88307 s.version = AUDIT_VERSION_LATEST;
88308 s.backlog_wait_time = audit_backlog_wait_time;
88309diff --git a/kernel/auditsc.c b/kernel/auditsc.c
88310index 21eae3c..66db239 100644
88311--- a/kernel/auditsc.c
88312+++ b/kernel/auditsc.c
88313@@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
88314 }
88315
88316 /* global counter which is incremented every time something logs in */
88317-static atomic_t session_id = ATOMIC_INIT(0);
88318+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
88319
88320 static int audit_set_loginuid_perm(kuid_t loginuid)
88321 {
88322@@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
88323
88324 /* are we setting or clearing? */
88325 if (uid_valid(loginuid))
88326- sessionid = (unsigned int)atomic_inc_return(&session_id);
88327+ sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
88328
88329 task->sessionid = sessionid;
88330 task->loginuid = loginuid;
88331diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
88332index 7f0dbcb..b54bb2c 100644
88333--- a/kernel/bpf/core.c
88334+++ b/kernel/bpf/core.c
88335@@ -22,6 +22,7 @@
88336 */
88337 #include <linux/filter.h>
88338 #include <linux/skbuff.h>
88339+#include <linux/vmalloc.h>
88340 #include <asm/unaligned.h>
88341
88342 /* Registers */
88343@@ -63,6 +64,67 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns
88344 return NULL;
88345 }
88346
88347+struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags)
88348+{
88349+ gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
88350+ gfp_extra_flags;
88351+ struct bpf_work_struct *ws;
88352+ struct bpf_prog *fp;
88353+
88354+ size = round_up(size, PAGE_SIZE);
88355+ fp = __vmalloc(size, gfp_flags, PAGE_KERNEL);
88356+ if (fp == NULL)
88357+ return NULL;
88358+
88359+ ws = kmalloc(sizeof(*ws), GFP_KERNEL | gfp_extra_flags);
88360+ if (ws == NULL) {
88361+ vfree(fp);
88362+ return NULL;
88363+ }
88364+
88365+ fp->pages = size / PAGE_SIZE;
88366+ fp->work = ws;
88367+
88368+ return fp;
88369+}
88370+EXPORT_SYMBOL_GPL(bpf_prog_alloc);
88371+
88372+struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size,
88373+ gfp_t gfp_extra_flags)
88374+{
88375+ gfp_t gfp_flags = GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO |
88376+ gfp_extra_flags;
88377+ struct bpf_prog *fp;
88378+
88379+ BUG_ON(fp_old == NULL);
88380+
88381+ size = round_up(size, PAGE_SIZE);
88382+ if (size <= fp_old->pages * PAGE_SIZE)
88383+ return fp_old;
88384+
88385+ fp = __vmalloc(size, gfp_flags, PAGE_KERNEL);
88386+ if (fp != NULL) {
88387+ memcpy(fp, fp_old, fp_old->pages * PAGE_SIZE);
88388+ fp->pages = size / PAGE_SIZE;
88389+
88390+ /* We keep fp->work from fp_old around in the new
88391+ * reallocated structure.
88392+ */
88393+ fp_old->work = NULL;
88394+ __bpf_prog_free(fp_old);
88395+ }
88396+
88397+ return fp;
88398+}
88399+EXPORT_SYMBOL_GPL(bpf_prog_realloc);
88400+
88401+void __bpf_prog_free(struct bpf_prog *fp)
88402+{
88403+ kfree(fp->work);
88404+ vfree(fp);
88405+}
88406+EXPORT_SYMBOL_GPL(__bpf_prog_free);
88407+
88408 /* Base function for offset calculation. Needs to go into .text section,
88409 * therefore keeping it non-static as well; will also be used by JITs
88410 * anyway later on, so do not let the compiler omit it.
88411@@ -523,12 +585,26 @@ void bpf_prog_select_runtime(struct bpf_prog *fp)
88412
88413 /* Probe if internal BPF can be JITed */
88414 bpf_int_jit_compile(fp);
88415+ /* Lock whole bpf_prog as read-only */
88416+ bpf_prog_lock_ro(fp);
88417 }
88418 EXPORT_SYMBOL_GPL(bpf_prog_select_runtime);
88419
88420-/* free internal BPF program */
88421+static void bpf_prog_free_deferred(struct work_struct *work)
88422+{
88423+ struct bpf_work_struct *ws;
88424+
88425+ ws = container_of(work, struct bpf_work_struct, work);
88426+ bpf_jit_free(ws->prog);
88427+}
88428+
88429+/* Free internal BPF program */
88430 void bpf_prog_free(struct bpf_prog *fp)
88431 {
88432- bpf_jit_free(fp);
88433+ struct bpf_work_struct *ws = fp->work;
88434+
88435+ INIT_WORK(&ws->work, bpf_prog_free_deferred);
88436+ ws->prog = fp;
88437+ schedule_work(&ws->work);
88438 }
88439 EXPORT_SYMBOL_GPL(bpf_prog_free);
88440diff --git a/kernel/capability.c b/kernel/capability.c
88441index 989f5bf..d317ca0 100644
88442--- a/kernel/capability.c
88443+++ b/kernel/capability.c
88444@@ -192,6 +192,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
88445 * before modification is attempted and the application
88446 * fails.
88447 */
88448+ if (tocopy > ARRAY_SIZE(kdata))
88449+ return -EFAULT;
88450+
88451 if (copy_to_user(dataptr, kdata, tocopy
88452 * sizeof(struct __user_cap_data_struct))) {
88453 return -EFAULT;
88454@@ -297,10 +300,11 @@ bool has_ns_capability(struct task_struct *t,
88455 int ret;
88456
88457 rcu_read_lock();
88458- ret = security_capable(__task_cred(t), ns, cap);
88459+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
88460+ gr_task_is_capable(t, __task_cred(t), cap);
88461 rcu_read_unlock();
88462
88463- return (ret == 0);
88464+ return ret;
88465 }
88466
88467 /**
88468@@ -337,10 +341,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
88469 int ret;
88470
88471 rcu_read_lock();
88472- ret = security_capable_noaudit(__task_cred(t), ns, cap);
88473+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
88474 rcu_read_unlock();
88475
88476- return (ret == 0);
88477+ return ret;
88478 }
88479
88480 /**
88481@@ -378,7 +382,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
88482 BUG();
88483 }
88484
88485- if (security_capable(current_cred(), ns, cap) == 0) {
88486+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
88487 current->flags |= PF_SUPERPRIV;
88488 return true;
88489 }
88490@@ -386,6 +390,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
88491 }
88492 EXPORT_SYMBOL(ns_capable);
88493
88494+bool ns_capable_nolog(struct user_namespace *ns, int cap)
88495+{
88496+ if (unlikely(!cap_valid(cap))) {
88497+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
88498+ BUG();
88499+ }
88500+
88501+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
88502+ current->flags |= PF_SUPERPRIV;
88503+ return true;
88504+ }
88505+ return false;
88506+}
88507+EXPORT_SYMBOL(ns_capable_nolog);
88508+
88509 /**
88510 * file_ns_capable - Determine if the file's opener had a capability in effect
88511 * @file: The file we want to check
88512@@ -427,6 +446,12 @@ bool capable(int cap)
88513 }
88514 EXPORT_SYMBOL(capable);
88515
88516+bool capable_nolog(int cap)
88517+{
88518+ return ns_capable_nolog(&init_user_ns, cap);
88519+}
88520+EXPORT_SYMBOL(capable_nolog);
88521+
88522 /**
88523 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
88524 * @inode: The inode in question
88525@@ -444,3 +469,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
88526 kgid_has_mapping(ns, inode->i_gid);
88527 }
88528 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
88529+
88530+bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
88531+{
88532+ struct user_namespace *ns = current_user_ns();
88533+
88534+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
88535+ kgid_has_mapping(ns, inode->i_gid);
88536+}
88537+EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
88538diff --git a/kernel/cgroup.c b/kernel/cgroup.c
88539index 3a73f99..4f29fea 100644
88540--- a/kernel/cgroup.c
88541+++ b/kernel/cgroup.c
88542@@ -5341,6 +5341,14 @@ static void cgroup_release_agent(struct work_struct *work)
88543 release_list);
88544 list_del_init(&cgrp->release_list);
88545 raw_spin_unlock(&release_list_lock);
88546+
88547+ /*
88548+ * don't bother calling call_usermodehelper if we haven't
88549+ * configured a binary to execute
88550+ */
88551+ if (cgrp->root->release_agent_path[0] == '\0')
88552+ goto continue_free;
88553+
88554 pathbuf = kmalloc(PATH_MAX, GFP_KERNEL);
88555 if (!pathbuf)
88556 goto continue_free;
88557@@ -5539,7 +5547,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
88558 struct task_struct *task;
88559 int count = 0;
88560
88561- seq_printf(seq, "css_set %p\n", cset);
88562+ seq_printf(seq, "css_set %pK\n", cset);
88563
88564 list_for_each_entry(task, &cset->tasks, cg_list) {
88565 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
88566diff --git a/kernel/compat.c b/kernel/compat.c
88567index ebb3c36..1df606e 100644
88568--- a/kernel/compat.c
88569+++ b/kernel/compat.c
88570@@ -13,6 +13,7 @@
88571
88572 #include <linux/linkage.h>
88573 #include <linux/compat.h>
88574+#include <linux/module.h>
88575 #include <linux/errno.h>
88576 #include <linux/time.h>
88577 #include <linux/signal.h>
88578@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
88579 mm_segment_t oldfs;
88580 long ret;
88581
88582- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
88583+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
88584 oldfs = get_fs();
88585 set_fs(KERNEL_DS);
88586 ret = hrtimer_nanosleep_restart(restart);
88587@@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
88588 oldfs = get_fs();
88589 set_fs(KERNEL_DS);
88590 ret = hrtimer_nanosleep(&tu,
88591- rmtp ? (struct timespec __user *)&rmt : NULL,
88592+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
88593 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
88594 set_fs(oldfs);
88595
88596@@ -379,7 +380,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
88597 mm_segment_t old_fs = get_fs();
88598
88599 set_fs(KERNEL_DS);
88600- ret = sys_sigpending((old_sigset_t __user *) &s);
88601+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
88602 set_fs(old_fs);
88603 if (ret == 0)
88604 ret = put_user(s, set);
88605@@ -469,7 +470,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
88606 mm_segment_t old_fs = get_fs();
88607
88608 set_fs(KERNEL_DS);
88609- ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
88610+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
88611 set_fs(old_fs);
88612
88613 if (!ret) {
88614@@ -551,8 +552,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
88615 set_fs (KERNEL_DS);
88616 ret = sys_wait4(pid,
88617 (stat_addr ?
88618- (unsigned int __user *) &status : NULL),
88619- options, (struct rusage __user *) &r);
88620+ (unsigned int __force_user *) &status : NULL),
88621+ options, (struct rusage __force_user *) &r);
88622 set_fs (old_fs);
88623
88624 if (ret > 0) {
88625@@ -578,8 +579,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
88626 memset(&info, 0, sizeof(info));
88627
88628 set_fs(KERNEL_DS);
88629- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
88630- uru ? (struct rusage __user *)&ru : NULL);
88631+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
88632+ uru ? (struct rusage __force_user *)&ru : NULL);
88633 set_fs(old_fs);
88634
88635 if ((ret < 0) || (info.si_signo == 0))
88636@@ -713,8 +714,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
88637 oldfs = get_fs();
88638 set_fs(KERNEL_DS);
88639 err = sys_timer_settime(timer_id, flags,
88640- (struct itimerspec __user *) &newts,
88641- (struct itimerspec __user *) &oldts);
88642+ (struct itimerspec __force_user *) &newts,
88643+ (struct itimerspec __force_user *) &oldts);
88644 set_fs(oldfs);
88645 if (!err && old && put_compat_itimerspec(old, &oldts))
88646 return -EFAULT;
88647@@ -731,7 +732,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
88648 oldfs = get_fs();
88649 set_fs(KERNEL_DS);
88650 err = sys_timer_gettime(timer_id,
88651- (struct itimerspec __user *) &ts);
88652+ (struct itimerspec __force_user *) &ts);
88653 set_fs(oldfs);
88654 if (!err && put_compat_itimerspec(setting, &ts))
88655 return -EFAULT;
88656@@ -750,7 +751,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
88657 oldfs = get_fs();
88658 set_fs(KERNEL_DS);
88659 err = sys_clock_settime(which_clock,
88660- (struct timespec __user *) &ts);
88661+ (struct timespec __force_user *) &ts);
88662 set_fs(oldfs);
88663 return err;
88664 }
88665@@ -765,7 +766,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
88666 oldfs = get_fs();
88667 set_fs(KERNEL_DS);
88668 err = sys_clock_gettime(which_clock,
88669- (struct timespec __user *) &ts);
88670+ (struct timespec __force_user *) &ts);
88671 set_fs(oldfs);
88672 if (!err && compat_put_timespec(&ts, tp))
88673 return -EFAULT;
88674@@ -785,7 +786,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
88675
88676 oldfs = get_fs();
88677 set_fs(KERNEL_DS);
88678- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
88679+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
88680 set_fs(oldfs);
88681
88682 err = compat_put_timex(utp, &txc);
88683@@ -805,7 +806,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
88684 oldfs = get_fs();
88685 set_fs(KERNEL_DS);
88686 err = sys_clock_getres(which_clock,
88687- (struct timespec __user *) &ts);
88688+ (struct timespec __force_user *) &ts);
88689 set_fs(oldfs);
88690 if (!err && tp && compat_put_timespec(&ts, tp))
88691 return -EFAULT;
88692@@ -819,7 +820,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
88693 struct timespec tu;
88694 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
88695
88696- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
88697+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
88698 oldfs = get_fs();
88699 set_fs(KERNEL_DS);
88700 err = clock_nanosleep_restart(restart);
88701@@ -851,8 +852,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
88702 oldfs = get_fs();
88703 set_fs(KERNEL_DS);
88704 err = sys_clock_nanosleep(which_clock, flags,
88705- (struct timespec __user *) &in,
88706- (struct timespec __user *) &out);
88707+ (struct timespec __force_user *) &in,
88708+ (struct timespec __force_user *) &out);
88709 set_fs(oldfs);
88710
88711 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
88712@@ -1146,7 +1147,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
88713 mm_segment_t old_fs = get_fs();
88714
88715 set_fs(KERNEL_DS);
88716- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
88717+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
88718 set_fs(old_fs);
88719 if (compat_put_timespec(&t, interval))
88720 return -EFAULT;
88721diff --git a/kernel/configs.c b/kernel/configs.c
88722index c18b1f1..b9a0132 100644
88723--- a/kernel/configs.c
88724+++ b/kernel/configs.c
88725@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
88726 struct proc_dir_entry *entry;
88727
88728 /* create the current config file */
88729+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
88730+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
88731+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
88732+ &ikconfig_file_ops);
88733+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88734+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
88735+ &ikconfig_file_ops);
88736+#endif
88737+#else
88738 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
88739 &ikconfig_file_ops);
88740+#endif
88741+
88742 if (!entry)
88743 return -ENOMEM;
88744
88745diff --git a/kernel/cred.c b/kernel/cred.c
88746index e0573a4..26c0fd3 100644
88747--- a/kernel/cred.c
88748+++ b/kernel/cred.c
88749@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
88750 validate_creds(cred);
88751 alter_cred_subscribers(cred, -1);
88752 put_cred(cred);
88753+
88754+#ifdef CONFIG_GRKERNSEC_SETXID
88755+ cred = (struct cred *) tsk->delayed_cred;
88756+ if (cred != NULL) {
88757+ tsk->delayed_cred = NULL;
88758+ validate_creds(cred);
88759+ alter_cred_subscribers(cred, -1);
88760+ put_cred(cred);
88761+ }
88762+#endif
88763 }
88764
88765 /**
88766@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
88767 * Always returns 0 thus allowing this function to be tail-called at the end
88768 * of, say, sys_setgid().
88769 */
88770-int commit_creds(struct cred *new)
88771+static int __commit_creds(struct cred *new)
88772 {
88773 struct task_struct *task = current;
88774 const struct cred *old = task->real_cred;
88775@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
88776
88777 get_cred(new); /* we will require a ref for the subj creds too */
88778
88779+ gr_set_role_label(task, new->uid, new->gid);
88780+
88781 /* dumpability changes */
88782 if (!uid_eq(old->euid, new->euid) ||
88783 !gid_eq(old->egid, new->egid) ||
88784@@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
88785 put_cred(old);
88786 return 0;
88787 }
88788+#ifdef CONFIG_GRKERNSEC_SETXID
88789+extern int set_user(struct cred *new);
88790+
88791+void gr_delayed_cred_worker(void)
88792+{
88793+ const struct cred *new = current->delayed_cred;
88794+ struct cred *ncred;
88795+
88796+ current->delayed_cred = NULL;
88797+
88798+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
88799+ // from doing get_cred on it when queueing this
88800+ put_cred(new);
88801+ return;
88802+ } else if (new == NULL)
88803+ return;
88804+
88805+ ncred = prepare_creds();
88806+ if (!ncred)
88807+ goto die;
88808+ // uids
88809+ ncred->uid = new->uid;
88810+ ncred->euid = new->euid;
88811+ ncred->suid = new->suid;
88812+ ncred->fsuid = new->fsuid;
88813+ // gids
88814+ ncred->gid = new->gid;
88815+ ncred->egid = new->egid;
88816+ ncred->sgid = new->sgid;
88817+ ncred->fsgid = new->fsgid;
88818+ // groups
88819+ set_groups(ncred, new->group_info);
88820+ // caps
88821+ ncred->securebits = new->securebits;
88822+ ncred->cap_inheritable = new->cap_inheritable;
88823+ ncred->cap_permitted = new->cap_permitted;
88824+ ncred->cap_effective = new->cap_effective;
88825+ ncred->cap_bset = new->cap_bset;
88826+
88827+ if (set_user(ncred)) {
88828+ abort_creds(ncred);
88829+ goto die;
88830+ }
88831+
88832+ // from doing get_cred on it when queueing this
88833+ put_cred(new);
88834+
88835+ __commit_creds(ncred);
88836+ return;
88837+die:
88838+ // from doing get_cred on it when queueing this
88839+ put_cred(new);
88840+ do_group_exit(SIGKILL);
88841+}
88842+#endif
88843+
88844+int commit_creds(struct cred *new)
88845+{
88846+#ifdef CONFIG_GRKERNSEC_SETXID
88847+ int ret;
88848+ int schedule_it = 0;
88849+ struct task_struct *t;
88850+ unsigned oldsecurebits = current_cred()->securebits;
88851+
88852+ /* we won't get called with tasklist_lock held for writing
88853+ and interrupts disabled as the cred struct in that case is
88854+ init_cred
88855+ */
88856+ if (grsec_enable_setxid && !current_is_single_threaded() &&
88857+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
88858+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
88859+ schedule_it = 1;
88860+ }
88861+ ret = __commit_creds(new);
88862+ if (schedule_it) {
88863+ rcu_read_lock();
88864+ read_lock(&tasklist_lock);
88865+ for (t = next_thread(current); t != current;
88866+ t = next_thread(t)) {
88867+ /* we'll check if the thread has uid 0 in
88868+ * the delayed worker routine
88869+ */
88870+ if (task_securebits(t) == oldsecurebits &&
88871+ t->delayed_cred == NULL) {
88872+ t->delayed_cred = get_cred(new);
88873+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
88874+ set_tsk_need_resched(t);
88875+ }
88876+ }
88877+ read_unlock(&tasklist_lock);
88878+ rcu_read_unlock();
88879+ }
88880+
88881+ return ret;
88882+#else
88883+ return __commit_creds(new);
88884+#endif
88885+}
88886+
88887 EXPORT_SYMBOL(commit_creds);
88888
88889 /**
88890diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
88891index 1adf62b..7736e06 100644
88892--- a/kernel/debug/debug_core.c
88893+++ b/kernel/debug/debug_core.c
88894@@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
88895 */
88896 static atomic_t masters_in_kgdb;
88897 static atomic_t slaves_in_kgdb;
88898-static atomic_t kgdb_break_tasklet_var;
88899+static atomic_unchecked_t kgdb_break_tasklet_var;
88900 atomic_t kgdb_setting_breakpoint;
88901
88902 struct task_struct *kgdb_usethread;
88903@@ -134,7 +134,7 @@ int kgdb_single_step;
88904 static pid_t kgdb_sstep_pid;
88905
88906 /* to keep track of the CPU which is doing the single stepping*/
88907-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88908+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
88909
88910 /*
88911 * If you are debugging a problem where roundup (the collection of
88912@@ -549,7 +549,7 @@ return_normal:
88913 * kernel will only try for the value of sstep_tries before
88914 * giving up and continuing on.
88915 */
88916- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
88917+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
88918 (kgdb_info[cpu].task &&
88919 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
88920 atomic_set(&kgdb_active, -1);
88921@@ -647,8 +647,8 @@ cpu_master_loop:
88922 }
88923
88924 kgdb_restore:
88925- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
88926- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
88927+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
88928+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
88929 if (kgdb_info[sstep_cpu].task)
88930 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
88931 else
88932@@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
88933 static void kgdb_tasklet_bpt(unsigned long ing)
88934 {
88935 kgdb_breakpoint();
88936- atomic_set(&kgdb_break_tasklet_var, 0);
88937+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
88938 }
88939
88940 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
88941
88942 void kgdb_schedule_breakpoint(void)
88943 {
88944- if (atomic_read(&kgdb_break_tasklet_var) ||
88945+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
88946 atomic_read(&kgdb_active) != -1 ||
88947 atomic_read(&kgdb_setting_breakpoint))
88948 return;
88949- atomic_inc(&kgdb_break_tasklet_var);
88950+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
88951 tasklet_schedule(&kgdb_tasklet_breakpoint);
88952 }
88953 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
88954diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
88955index 379650b..30c5180 100644
88956--- a/kernel/debug/kdb/kdb_main.c
88957+++ b/kernel/debug/kdb/kdb_main.c
88958@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
88959 continue;
88960
88961 kdb_printf("%-20s%8u 0x%p ", mod->name,
88962- mod->core_size, (void *)mod);
88963+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
88964 #ifdef CONFIG_MODULE_UNLOAD
88965 kdb_printf("%4ld ", module_refcount(mod));
88966 #endif
88967@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
88968 kdb_printf(" (Loading)");
88969 else
88970 kdb_printf(" (Live)");
88971- kdb_printf(" 0x%p", mod->module_core);
88972+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
88973
88974 #ifdef CONFIG_MODULE_UNLOAD
88975 {
88976diff --git a/kernel/events/core.c b/kernel/events/core.c
88977index 658f232..32e9595 100644
88978--- a/kernel/events/core.c
88979+++ b/kernel/events/core.c
88980@@ -161,8 +161,15 @@ static struct srcu_struct pmus_srcu;
88981 * 0 - disallow raw tracepoint access for unpriv
88982 * 1 - disallow cpu events for unpriv
88983 * 2 - disallow kernel profiling for unpriv
88984+ * 3 - disallow all unpriv perf event use
88985 */
88986-int sysctl_perf_event_paranoid __read_mostly = 1;
88987+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88988+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
88989+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
88990+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
88991+#else
88992+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
88993+#endif
88994
88995 /* Minimum for 512 kiB + 1 user control page */
88996 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
88997@@ -188,7 +195,7 @@ void update_perf_cpu_limits(void)
88998
88999 tmp *= sysctl_perf_cpu_time_max_percent;
89000 do_div(tmp, 100);
89001- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
89002+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
89003 }
89004
89005 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
89006@@ -294,7 +301,7 @@ void perf_sample_event_took(u64 sample_len_ns)
89007 }
89008 }
89009
89010-static atomic64_t perf_event_id;
89011+static atomic64_unchecked_t perf_event_id;
89012
89013 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
89014 enum event_type_t event_type);
89015@@ -3051,7 +3058,7 @@ static void __perf_event_read(void *info)
89016
89017 static inline u64 perf_event_count(struct perf_event *event)
89018 {
89019- return local64_read(&event->count) + atomic64_read(&event->child_count);
89020+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
89021 }
89022
89023 static u64 perf_event_read(struct perf_event *event)
89024@@ -3430,9 +3437,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
89025 mutex_lock(&event->child_mutex);
89026 total += perf_event_read(event);
89027 *enabled += event->total_time_enabled +
89028- atomic64_read(&event->child_total_time_enabled);
89029+ atomic64_read_unchecked(&event->child_total_time_enabled);
89030 *running += event->total_time_running +
89031- atomic64_read(&event->child_total_time_running);
89032+ atomic64_read_unchecked(&event->child_total_time_running);
89033
89034 list_for_each_entry(child, &event->child_list, child_list) {
89035 total += perf_event_read(child);
89036@@ -3881,10 +3888,10 @@ void perf_event_update_userpage(struct perf_event *event)
89037 userpg->offset -= local64_read(&event->hw.prev_count);
89038
89039 userpg->time_enabled = enabled +
89040- atomic64_read(&event->child_total_time_enabled);
89041+ atomic64_read_unchecked(&event->child_total_time_enabled);
89042
89043 userpg->time_running = running +
89044- atomic64_read(&event->child_total_time_running);
89045+ atomic64_read_unchecked(&event->child_total_time_running);
89046
89047 arch_perf_update_userpage(userpg, now);
89048
89049@@ -4448,7 +4455,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
89050
89051 /* Data. */
89052 sp = perf_user_stack_pointer(regs);
89053- rem = __output_copy_user(handle, (void *) sp, dump_size);
89054+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
89055 dyn_size = dump_size - rem;
89056
89057 perf_output_skip(handle, rem);
89058@@ -4539,11 +4546,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
89059 values[n++] = perf_event_count(event);
89060 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
89061 values[n++] = enabled +
89062- atomic64_read(&event->child_total_time_enabled);
89063+ atomic64_read_unchecked(&event->child_total_time_enabled);
89064 }
89065 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
89066 values[n++] = running +
89067- atomic64_read(&event->child_total_time_running);
89068+ atomic64_read_unchecked(&event->child_total_time_running);
89069 }
89070 if (read_format & PERF_FORMAT_ID)
89071 values[n++] = primary_event_id(event);
89072@@ -6858,7 +6865,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
89073 event->parent = parent_event;
89074
89075 event->ns = get_pid_ns(task_active_pid_ns(current));
89076- event->id = atomic64_inc_return(&perf_event_id);
89077+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
89078
89079 event->state = PERF_EVENT_STATE_INACTIVE;
89080
89081@@ -7137,6 +7144,11 @@ SYSCALL_DEFINE5(perf_event_open,
89082 if (flags & ~PERF_FLAG_ALL)
89083 return -EINVAL;
89084
89085+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89086+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
89087+ return -EACCES;
89088+#endif
89089+
89090 err = perf_copy_attr(attr_uptr, &attr);
89091 if (err)
89092 return err;
89093@@ -7489,10 +7501,10 @@ static void sync_child_event(struct perf_event *child_event,
89094 /*
89095 * Add back the child's count to the parent's count:
89096 */
89097- atomic64_add(child_val, &parent_event->child_count);
89098- atomic64_add(child_event->total_time_enabled,
89099+ atomic64_add_unchecked(child_val, &parent_event->child_count);
89100+ atomic64_add_unchecked(child_event->total_time_enabled,
89101 &parent_event->child_total_time_enabled);
89102- atomic64_add(child_event->total_time_running,
89103+ atomic64_add_unchecked(child_event->total_time_running,
89104 &parent_event->child_total_time_running);
89105
89106 /*
89107diff --git a/kernel/events/internal.h b/kernel/events/internal.h
89108index 569b2187..19940d9 100644
89109--- a/kernel/events/internal.h
89110+++ b/kernel/events/internal.h
89111@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
89112 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
89113 }
89114
89115-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
89116+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
89117 static inline unsigned long \
89118 func_name(struct perf_output_handle *handle, \
89119- const void *buf, unsigned long len) \
89120+ const void user *buf, unsigned long len) \
89121 { \
89122 unsigned long size, written; \
89123 \
89124@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
89125 return 0;
89126 }
89127
89128-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
89129+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
89130
89131 static inline unsigned long
89132 memcpy_skip(void *dst, const void *src, unsigned long n)
89133@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
89134 return 0;
89135 }
89136
89137-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
89138+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
89139
89140 #ifndef arch_perf_out_copy_user
89141 #define arch_perf_out_copy_user arch_perf_out_copy_user
89142@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
89143 }
89144 #endif
89145
89146-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
89147+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
89148
89149 /* Callchain handling */
89150 extern struct perf_callchain_entry *
89151diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
89152index 1d0af8a..9913530 100644
89153--- a/kernel/events/uprobes.c
89154+++ b/kernel/events/uprobes.c
89155@@ -1671,7 +1671,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
89156 {
89157 struct page *page;
89158 uprobe_opcode_t opcode;
89159- int result;
89160+ long result;
89161
89162 pagefault_disable();
89163 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
89164diff --git a/kernel/exit.c b/kernel/exit.c
89165index 32c58f7..9eb6907 100644
89166--- a/kernel/exit.c
89167+++ b/kernel/exit.c
89168@@ -173,6 +173,10 @@ void release_task(struct task_struct *p)
89169 struct task_struct *leader;
89170 int zap_leader;
89171 repeat:
89172+#ifdef CONFIG_NET
89173+ gr_del_task_from_ip_table(p);
89174+#endif
89175+
89176 /* don't need to get the RCU readlock here - the process is dead and
89177 * can't be modifying its own credentials. But shut RCU-lockdep up */
89178 rcu_read_lock();
89179@@ -668,6 +672,8 @@ void do_exit(long code)
89180 struct task_struct *tsk = current;
89181 int group_dead;
89182
89183+ set_fs(USER_DS);
89184+
89185 profile_task_exit(tsk);
89186
89187 WARN_ON(blk_needs_flush_plug(tsk));
89188@@ -684,7 +690,6 @@ void do_exit(long code)
89189 * mm_release()->clear_child_tid() from writing to a user-controlled
89190 * kernel address.
89191 */
89192- set_fs(USER_DS);
89193
89194 ptrace_event(PTRACE_EVENT_EXIT, code);
89195
89196@@ -742,6 +747,9 @@ void do_exit(long code)
89197 tsk->exit_code = code;
89198 taskstats_exit(tsk, group_dead);
89199
89200+ gr_acl_handle_psacct(tsk, code);
89201+ gr_acl_handle_exit();
89202+
89203 exit_mm(tsk);
89204
89205 if (group_dead)
89206@@ -859,7 +867,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
89207 * Take down every thread in the group. This is called by fatal signals
89208 * as well as by sys_exit_group (below).
89209 */
89210-void
89211+__noreturn void
89212 do_group_exit(int exit_code)
89213 {
89214 struct signal_struct *sig = current->signal;
89215diff --git a/kernel/fork.c b/kernel/fork.c
89216index a91e47d..71c9064 100644
89217--- a/kernel/fork.c
89218+++ b/kernel/fork.c
89219@@ -183,6 +183,48 @@ void thread_info_cache_init(void)
89220 # endif
89221 #endif
89222
89223+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89224+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89225+ int node, void **lowmem_stack)
89226+{
89227+ struct page *pages[THREAD_SIZE / PAGE_SIZE];
89228+ void *ret = NULL;
89229+ unsigned int i;
89230+
89231+ *lowmem_stack = alloc_thread_info_node(tsk, node);
89232+ if (*lowmem_stack == NULL)
89233+ goto out;
89234+
89235+ for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
89236+ pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
89237+
89238+ /* use VM_IOREMAP to gain THREAD_SIZE alignment */
89239+ ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
89240+ if (ret == NULL) {
89241+ free_thread_info(*lowmem_stack);
89242+ *lowmem_stack = NULL;
89243+ }
89244+
89245+out:
89246+ return ret;
89247+}
89248+
89249+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89250+{
89251+ unmap_process_stacks(tsk);
89252+}
89253+#else
89254+static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
89255+ int node, void **lowmem_stack)
89256+{
89257+ return alloc_thread_info_node(tsk, node);
89258+}
89259+static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
89260+{
89261+ free_thread_info(ti);
89262+}
89263+#endif
89264+
89265 /* SLAB cache for signal_struct structures (tsk->signal) */
89266 static struct kmem_cache *signal_cachep;
89267
89268@@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
89269 /* SLAB cache for mm_struct structures (tsk->mm) */
89270 static struct kmem_cache *mm_cachep;
89271
89272-static void account_kernel_stack(struct thread_info *ti, int account)
89273+static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
89274 {
89275+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89276+ struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
89277+#else
89278 struct zone *zone = page_zone(virt_to_page(ti));
89279+#endif
89280
89281 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
89282 }
89283
89284 void free_task(struct task_struct *tsk)
89285 {
89286- account_kernel_stack(tsk->stack, -1);
89287+ account_kernel_stack(tsk, tsk->stack, -1);
89288 arch_release_thread_info(tsk->stack);
89289- free_thread_info(tsk->stack);
89290+ gr_free_thread_info(tsk, tsk->stack);
89291 rt_mutex_debug_task_free(tsk);
89292 ftrace_graph_exit_task(tsk);
89293 put_seccomp_filter(tsk);
89294@@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89295 struct task_struct *tsk;
89296 struct thread_info *ti;
89297 unsigned long *stackend;
89298+ void *lowmem_stack;
89299 int node = tsk_fork_get_node(orig);
89300 int err;
89301
89302@@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89303 if (!tsk)
89304 return NULL;
89305
89306- ti = alloc_thread_info_node(tsk, node);
89307+ ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
89308 if (!ti)
89309 goto free_tsk;
89310
89311@@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89312 goto free_ti;
89313
89314 tsk->stack = ti;
89315+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
89316+ tsk->lowmem_stack = lowmem_stack;
89317+#endif
89318 #ifdef CONFIG_SECCOMP
89319 /*
89320 * We must handle setting up seccomp filters once we're under
89321@@ -332,7 +382,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89322 *stackend = STACK_END_MAGIC; /* for overflow detection */
89323
89324 #ifdef CONFIG_CC_STACKPROTECTOR
89325- tsk->stack_canary = get_random_int();
89326+ tsk->stack_canary = pax_get_random_long();
89327 #endif
89328
89329 /*
89330@@ -346,24 +396,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
89331 tsk->splice_pipe = NULL;
89332 tsk->task_frag.page = NULL;
89333
89334- account_kernel_stack(ti, 1);
89335+ account_kernel_stack(tsk, ti, 1);
89336
89337 return tsk;
89338
89339 free_ti:
89340- free_thread_info(ti);
89341+ gr_free_thread_info(tsk, ti);
89342 free_tsk:
89343 free_task_struct(tsk);
89344 return NULL;
89345 }
89346
89347 #ifdef CONFIG_MMU
89348-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89349+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
89350+{
89351+ struct vm_area_struct *tmp;
89352+ unsigned long charge;
89353+ struct file *file;
89354+ int retval;
89355+
89356+ charge = 0;
89357+ if (mpnt->vm_flags & VM_ACCOUNT) {
89358+ unsigned long len = vma_pages(mpnt);
89359+
89360+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89361+ goto fail_nomem;
89362+ charge = len;
89363+ }
89364+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89365+ if (!tmp)
89366+ goto fail_nomem;
89367+ *tmp = *mpnt;
89368+ tmp->vm_mm = mm;
89369+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
89370+ retval = vma_dup_policy(mpnt, tmp);
89371+ if (retval)
89372+ goto fail_nomem_policy;
89373+ if (anon_vma_fork(tmp, mpnt))
89374+ goto fail_nomem_anon_vma_fork;
89375+ tmp->vm_flags &= ~VM_LOCKED;
89376+ tmp->vm_next = tmp->vm_prev = NULL;
89377+ tmp->vm_mirror = NULL;
89378+ file = tmp->vm_file;
89379+ if (file) {
89380+ struct inode *inode = file_inode(file);
89381+ struct address_space *mapping = file->f_mapping;
89382+
89383+ get_file(file);
89384+ if (tmp->vm_flags & VM_DENYWRITE)
89385+ atomic_dec(&inode->i_writecount);
89386+ mutex_lock(&mapping->i_mmap_mutex);
89387+ if (tmp->vm_flags & VM_SHARED)
89388+ atomic_inc(&mapping->i_mmap_writable);
89389+ flush_dcache_mmap_lock(mapping);
89390+ /* insert tmp into the share list, just after mpnt */
89391+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89392+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
89393+ else
89394+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
89395+ flush_dcache_mmap_unlock(mapping);
89396+ mutex_unlock(&mapping->i_mmap_mutex);
89397+ }
89398+
89399+ /*
89400+ * Clear hugetlb-related page reserves for children. This only
89401+ * affects MAP_PRIVATE mappings. Faults generated by the child
89402+ * are not guaranteed to succeed, even if read-only
89403+ */
89404+ if (is_vm_hugetlb_page(tmp))
89405+ reset_vma_resv_huge_pages(tmp);
89406+
89407+ return tmp;
89408+
89409+fail_nomem_anon_vma_fork:
89410+ mpol_put(vma_policy(tmp));
89411+fail_nomem_policy:
89412+ kmem_cache_free(vm_area_cachep, tmp);
89413+fail_nomem:
89414+ vm_unacct_memory(charge);
89415+ return NULL;
89416+}
89417+
89418+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89419 {
89420 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
89421 struct rb_node **rb_link, *rb_parent;
89422 int retval;
89423- unsigned long charge;
89424
89425 uprobe_start_dup_mmap();
89426 down_write(&oldmm->mmap_sem);
89427@@ -391,55 +509,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89428
89429 prev = NULL;
89430 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
89431- struct file *file;
89432-
89433 if (mpnt->vm_flags & VM_DONTCOPY) {
89434 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
89435 -vma_pages(mpnt));
89436 continue;
89437 }
89438- charge = 0;
89439- if (mpnt->vm_flags & VM_ACCOUNT) {
89440- unsigned long len = vma_pages(mpnt);
89441-
89442- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
89443- goto fail_nomem;
89444- charge = len;
89445- }
89446- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
89447- if (!tmp)
89448- goto fail_nomem;
89449- *tmp = *mpnt;
89450- INIT_LIST_HEAD(&tmp->anon_vma_chain);
89451- retval = vma_dup_policy(mpnt, tmp);
89452- if (retval)
89453- goto fail_nomem_policy;
89454- tmp->vm_mm = mm;
89455- if (anon_vma_fork(tmp, mpnt))
89456- goto fail_nomem_anon_vma_fork;
89457- tmp->vm_flags &= ~VM_LOCKED;
89458- tmp->vm_next = tmp->vm_prev = NULL;
89459- file = tmp->vm_file;
89460- if (file) {
89461- struct inode *inode = file_inode(file);
89462- struct address_space *mapping = file->f_mapping;
89463-
89464- get_file(file);
89465- if (tmp->vm_flags & VM_DENYWRITE)
89466- atomic_dec(&inode->i_writecount);
89467- mutex_lock(&mapping->i_mmap_mutex);
89468- if (tmp->vm_flags & VM_SHARED)
89469- atomic_inc(&mapping->i_mmap_writable);
89470- flush_dcache_mmap_lock(mapping);
89471- /* insert tmp into the share list, just after mpnt */
89472- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
89473- vma_nonlinear_insert(tmp,
89474- &mapping->i_mmap_nonlinear);
89475- else
89476- vma_interval_tree_insert_after(tmp, mpnt,
89477- &mapping->i_mmap);
89478- flush_dcache_mmap_unlock(mapping);
89479- mutex_unlock(&mapping->i_mmap_mutex);
89480+ tmp = dup_vma(mm, oldmm, mpnt);
89481+ if (!tmp) {
89482+ retval = -ENOMEM;
89483+ goto out;
89484 }
89485
89486 /*
89487@@ -471,6 +549,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
89488 if (retval)
89489 goto out;
89490 }
89491+
89492+#ifdef CONFIG_PAX_SEGMEXEC
89493+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
89494+ struct vm_area_struct *mpnt_m;
89495+
89496+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
89497+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
89498+
89499+ if (!mpnt->vm_mirror)
89500+ continue;
89501+
89502+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
89503+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
89504+ mpnt->vm_mirror = mpnt_m;
89505+ } else {
89506+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
89507+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
89508+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
89509+ mpnt->vm_mirror->vm_mirror = mpnt;
89510+ }
89511+ }
89512+ BUG_ON(mpnt_m);
89513+ }
89514+#endif
89515+
89516 /* a new mm has just been created */
89517 arch_dup_mmap(oldmm, mm);
89518 retval = 0;
89519@@ -480,14 +583,6 @@ out:
89520 up_write(&oldmm->mmap_sem);
89521 uprobe_end_dup_mmap();
89522 return retval;
89523-fail_nomem_anon_vma_fork:
89524- mpol_put(vma_policy(tmp));
89525-fail_nomem_policy:
89526- kmem_cache_free(vm_area_cachep, tmp);
89527-fail_nomem:
89528- retval = -ENOMEM;
89529- vm_unacct_memory(charge);
89530- goto out;
89531 }
89532
89533 static inline int mm_alloc_pgd(struct mm_struct *mm)
89534@@ -729,8 +824,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
89535 return ERR_PTR(err);
89536
89537 mm = get_task_mm(task);
89538- if (mm && mm != current->mm &&
89539- !ptrace_may_access(task, mode)) {
89540+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
89541+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
89542 mmput(mm);
89543 mm = ERR_PTR(-EACCES);
89544 }
89545@@ -933,13 +1028,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
89546 spin_unlock(&fs->lock);
89547 return -EAGAIN;
89548 }
89549- fs->users++;
89550+ atomic_inc(&fs->users);
89551 spin_unlock(&fs->lock);
89552 return 0;
89553 }
89554 tsk->fs = copy_fs_struct(fs);
89555 if (!tsk->fs)
89556 return -ENOMEM;
89557+ /* Carry through gr_chroot_dentry and is_chrooted instead
89558+ of recomputing it here. Already copied when the task struct
89559+ is duplicated. This allows pivot_root to not be treated as
89560+ a chroot
89561+ */
89562+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
89563+
89564 return 0;
89565 }
89566
89567@@ -1173,7 +1275,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
89568 * parts of the process environment (as per the clone
89569 * flags). The actual kick-off is left to the caller.
89570 */
89571-static struct task_struct *copy_process(unsigned long clone_flags,
89572+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
89573 unsigned long stack_start,
89574 unsigned long stack_size,
89575 int __user *child_tidptr,
89576@@ -1244,6 +1346,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89577 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
89578 #endif
89579 retval = -EAGAIN;
89580+
89581+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
89582+
89583 if (atomic_read(&p->real_cred->user->processes) >=
89584 task_rlimit(p, RLIMIT_NPROC)) {
89585 if (p->real_cred->user != INIT_USER &&
89586@@ -1493,6 +1598,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
89587 goto bad_fork_free_pid;
89588 }
89589
89590+ /* synchronizes with gr_set_acls()
89591+ we need to call this past the point of no return for fork()
89592+ */
89593+ gr_copy_label(p);
89594+
89595 if (likely(p->pid)) {
89596 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
89597
89598@@ -1583,6 +1693,8 @@ bad_fork_cleanup_count:
89599 bad_fork_free:
89600 free_task(p);
89601 fork_out:
89602+ gr_log_forkfail(retval);
89603+
89604 return ERR_PTR(retval);
89605 }
89606
89607@@ -1644,6 +1756,7 @@ long do_fork(unsigned long clone_flags,
89608
89609 p = copy_process(clone_flags, stack_start, stack_size,
89610 child_tidptr, NULL, trace);
89611+ add_latent_entropy();
89612 /*
89613 * Do this prior waking up the new thread - the thread pointer
89614 * might get invalid after that point, if the thread exits quickly.
89615@@ -1660,6 +1773,8 @@ long do_fork(unsigned long clone_flags,
89616 if (clone_flags & CLONE_PARENT_SETTID)
89617 put_user(nr, parent_tidptr);
89618
89619+ gr_handle_brute_check();
89620+
89621 if (clone_flags & CLONE_VFORK) {
89622 p->vfork_done = &vfork;
89623 init_completion(&vfork);
89624@@ -1778,7 +1893,7 @@ void __init proc_caches_init(void)
89625 mm_cachep = kmem_cache_create("mm_struct",
89626 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
89627 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
89628- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
89629+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
89630 mmap_init();
89631 nsproxy_cache_init();
89632 }
89633@@ -1818,7 +1933,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
89634 return 0;
89635
89636 /* don't need lock here; in the worst case we'll do useless copy */
89637- if (fs->users == 1)
89638+ if (atomic_read(&fs->users) == 1)
89639 return 0;
89640
89641 *new_fsp = copy_fs_struct(fs);
89642@@ -1930,7 +2045,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
89643 fs = current->fs;
89644 spin_lock(&fs->lock);
89645 current->fs = new_fs;
89646- if (--fs->users)
89647+ gr_set_chroot_entries(current, &current->fs->root);
89648+ if (atomic_dec_return(&fs->users))
89649 new_fs = NULL;
89650 else
89651 new_fs = fs;
89652diff --git a/kernel/futex.c b/kernel/futex.c
89653index 22b3f1b..6820bc0 100644
89654--- a/kernel/futex.c
89655+++ b/kernel/futex.c
89656@@ -202,7 +202,7 @@ struct futex_pi_state {
89657 atomic_t refcount;
89658
89659 union futex_key key;
89660-};
89661+} __randomize_layout;
89662
89663 /**
89664 * struct futex_q - The hashed futex queue entry, one per waiting task
89665@@ -236,7 +236,7 @@ struct futex_q {
89666 struct rt_mutex_waiter *rt_waiter;
89667 union futex_key *requeue_pi_key;
89668 u32 bitset;
89669-};
89670+} __randomize_layout;
89671
89672 static const struct futex_q futex_q_init = {
89673 /* list gets initialized in queue_me()*/
89674@@ -396,6 +396,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
89675 struct page *page, *page_head;
89676 int err, ro = 0;
89677
89678+#ifdef CONFIG_PAX_SEGMEXEC
89679+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
89680+ return -EFAULT;
89681+#endif
89682+
89683 /*
89684 * The futex address must be "naturally" aligned.
89685 */
89686@@ -595,7 +600,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
89687
89688 static int get_futex_value_locked(u32 *dest, u32 __user *from)
89689 {
89690- int ret;
89691+ unsigned long ret;
89692
89693 pagefault_disable();
89694 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
89695@@ -3000,6 +3005,7 @@ static void __init futex_detect_cmpxchg(void)
89696 {
89697 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
89698 u32 curval;
89699+ mm_segment_t oldfs;
89700
89701 /*
89702 * This will fail and we want it. Some arch implementations do
89703@@ -3011,8 +3017,11 @@ static void __init futex_detect_cmpxchg(void)
89704 * implementation, the non-functional ones will return
89705 * -ENOSYS.
89706 */
89707+ oldfs = get_fs();
89708+ set_fs(USER_DS);
89709 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
89710 futex_cmpxchg_enabled = 1;
89711+ set_fs(oldfs);
89712 #endif
89713 }
89714
89715diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
89716index 55c8c93..9ba7ad6 100644
89717--- a/kernel/futex_compat.c
89718+++ b/kernel/futex_compat.c
89719@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
89720 return 0;
89721 }
89722
89723-static void __user *futex_uaddr(struct robust_list __user *entry,
89724+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
89725 compat_long_t futex_offset)
89726 {
89727 compat_uptr_t base = ptr_to_compat(entry);
89728diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
89729index b358a80..fc25240 100644
89730--- a/kernel/gcov/base.c
89731+++ b/kernel/gcov/base.c
89732@@ -114,11 +114,6 @@ void gcov_enable_events(void)
89733 }
89734
89735 #ifdef CONFIG_MODULES
89736-static inline int within(void *addr, void *start, unsigned long size)
89737-{
89738- return ((addr >= start) && (addr < start + size));
89739-}
89740-
89741 /* Update list and generate events when modules are unloaded. */
89742 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89743 void *data)
89744@@ -133,7 +128,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
89745
89746 /* Remove entries located in module from linked list. */
89747 while ((info = gcov_info_next(info))) {
89748- if (within(info, mod->module_core, mod->core_size)) {
89749+ if (within_module_core_rw((unsigned long)info, mod)) {
89750 gcov_info_unlink(prev, info);
89751 if (gcov_events_enabled)
89752 gcov_event(GCOV_REMOVE, info);
89753diff --git a/kernel/jump_label.c b/kernel/jump_label.c
89754index 9019f15..9a3c42e 100644
89755--- a/kernel/jump_label.c
89756+++ b/kernel/jump_label.c
89757@@ -14,6 +14,7 @@
89758 #include <linux/err.h>
89759 #include <linux/static_key.h>
89760 #include <linux/jump_label_ratelimit.h>
89761+#include <linux/mm.h>
89762
89763 #ifdef HAVE_JUMP_LABEL
89764
89765@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
89766
89767 size = (((unsigned long)stop - (unsigned long)start)
89768 / sizeof(struct jump_entry));
89769+ pax_open_kernel();
89770 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
89771+ pax_close_kernel();
89772 }
89773
89774 static void jump_label_update(struct static_key *key, int enable);
89775@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
89776 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
89777 struct jump_entry *iter;
89778
89779+ pax_open_kernel();
89780 for (iter = iter_start; iter < iter_stop; iter++) {
89781 if (within_module_init(iter->code, mod))
89782 iter->code = 0;
89783 }
89784+ pax_close_kernel();
89785 }
89786
89787 static int
89788diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
89789index ae51670..c1a9796 100644
89790--- a/kernel/kallsyms.c
89791+++ b/kernel/kallsyms.c
89792@@ -11,6 +11,9 @@
89793 * Changed the compression method from stem compression to "table lookup"
89794 * compression (see scripts/kallsyms.c for a more complete description)
89795 */
89796+#ifdef CONFIG_GRKERNSEC_HIDESYM
89797+#define __INCLUDED_BY_HIDESYM 1
89798+#endif
89799 #include <linux/kallsyms.h>
89800 #include <linux/module.h>
89801 #include <linux/init.h>
89802@@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
89803
89804 static inline int is_kernel_inittext(unsigned long addr)
89805 {
89806+ if (system_state != SYSTEM_BOOTING)
89807+ return 0;
89808+
89809 if (addr >= (unsigned long)_sinittext
89810 && addr <= (unsigned long)_einittext)
89811 return 1;
89812 return 0;
89813 }
89814
89815+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89816+#ifdef CONFIG_MODULES
89817+static inline int is_module_text(unsigned long addr)
89818+{
89819+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
89820+ return 1;
89821+
89822+ addr = ktla_ktva(addr);
89823+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
89824+}
89825+#else
89826+static inline int is_module_text(unsigned long addr)
89827+{
89828+ return 0;
89829+}
89830+#endif
89831+#endif
89832+
89833 static inline int is_kernel_text(unsigned long addr)
89834 {
89835 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
89836@@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
89837
89838 static inline int is_kernel(unsigned long addr)
89839 {
89840+
89841+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89842+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
89843+ return 1;
89844+
89845+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
89846+#else
89847 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
89848+#endif
89849+
89850 return 1;
89851 return in_gate_area_no_mm(addr);
89852 }
89853
89854 static int is_ksym_addr(unsigned long addr)
89855 {
89856+
89857+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
89858+ if (is_module_text(addr))
89859+ return 0;
89860+#endif
89861+
89862 if (all_var)
89863 return is_kernel(addr);
89864
89865@@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
89866
89867 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
89868 {
89869- iter->name[0] = '\0';
89870 iter->nameoff = get_symbol_offset(new_pos);
89871 iter->pos = new_pos;
89872 }
89873@@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
89874 {
89875 struct kallsym_iter *iter = m->private;
89876
89877+#ifdef CONFIG_GRKERNSEC_HIDESYM
89878+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
89879+ return 0;
89880+#endif
89881+
89882 /* Some debugging symbols have no name. Ignore them. */
89883 if (!iter->name[0])
89884 return 0;
89885@@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
89886 */
89887 type = iter->exported ? toupper(iter->type) :
89888 tolower(iter->type);
89889+
89890 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
89891 type, iter->name, iter->module_name);
89892 } else
89893@@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
89894 struct kallsym_iter *iter;
89895 int ret;
89896
89897- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
89898+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
89899 if (!iter)
89900 return -ENOMEM;
89901 reset_iter(iter, 0);
89902diff --git a/kernel/kcmp.c b/kernel/kcmp.c
89903index 0aa69ea..a7fcafb 100644
89904--- a/kernel/kcmp.c
89905+++ b/kernel/kcmp.c
89906@@ -100,6 +100,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
89907 struct task_struct *task1, *task2;
89908 int ret;
89909
89910+#ifdef CONFIG_GRKERNSEC
89911+ return -ENOSYS;
89912+#endif
89913+
89914 rcu_read_lock();
89915
89916 /*
89917diff --git a/kernel/kexec.c b/kernel/kexec.c
89918index 2bee072..8979af8 100644
89919--- a/kernel/kexec.c
89920+++ b/kernel/kexec.c
89921@@ -1349,7 +1349,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
89922 compat_ulong_t, flags)
89923 {
89924 struct compat_kexec_segment in;
89925- struct kexec_segment out, __user *ksegments;
89926+ struct kexec_segment out;
89927+ struct kexec_segment __user *ksegments;
89928 unsigned long i, result;
89929
89930 /* Don't allow clients that don't understand the native
89931diff --git a/kernel/kmod.c b/kernel/kmod.c
89932index 8637e04..8b1d0d8 100644
89933--- a/kernel/kmod.c
89934+++ b/kernel/kmod.c
89935@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
89936 kfree(info->argv);
89937 }
89938
89939-static int call_modprobe(char *module_name, int wait)
89940+static int call_modprobe(char *module_name, char *module_param, int wait)
89941 {
89942 struct subprocess_info *info;
89943 static char *envp[] = {
89944@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
89945 NULL
89946 };
89947
89948- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
89949+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
89950 if (!argv)
89951 goto out;
89952
89953@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
89954 argv[1] = "-q";
89955 argv[2] = "--";
89956 argv[3] = module_name; /* check free_modprobe_argv() */
89957- argv[4] = NULL;
89958+ argv[4] = module_param;
89959+ argv[5] = NULL;
89960
89961 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
89962 NULL, free_modprobe_argv, NULL);
89963@@ -129,9 +130,8 @@ out:
89964 * If module auto-loading support is disabled then this function
89965 * becomes a no-operation.
89966 */
89967-int __request_module(bool wait, const char *fmt, ...)
89968+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
89969 {
89970- va_list args;
89971 char module_name[MODULE_NAME_LEN];
89972 unsigned int max_modprobes;
89973 int ret;
89974@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
89975 if (!modprobe_path[0])
89976 return 0;
89977
89978- va_start(args, fmt);
89979- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
89980- va_end(args);
89981+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
89982 if (ret >= MODULE_NAME_LEN)
89983 return -ENAMETOOLONG;
89984
89985@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
89986 if (ret)
89987 return ret;
89988
89989+#ifdef CONFIG_GRKERNSEC_MODHARDEN
89990+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
89991+ /* hack to workaround consolekit/udisks stupidity */
89992+ read_lock(&tasklist_lock);
89993+ if (!strcmp(current->comm, "mount") &&
89994+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
89995+ read_unlock(&tasklist_lock);
89996+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
89997+ return -EPERM;
89998+ }
89999+ read_unlock(&tasklist_lock);
90000+ }
90001+#endif
90002+
90003 /* If modprobe needs a service that is in a module, we get a recursive
90004 * loop. Limit the number of running kmod threads to max_threads/2 or
90005 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
90006@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
90007
90008 trace_module_request(module_name, wait, _RET_IP_);
90009
90010- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
90011+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
90012
90013 atomic_dec(&kmod_concurrent);
90014 return ret;
90015 }
90016+
90017+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
90018+{
90019+ va_list args;
90020+ int ret;
90021+
90022+ va_start(args, fmt);
90023+ ret = ____request_module(wait, module_param, fmt, args);
90024+ va_end(args);
90025+
90026+ return ret;
90027+}
90028+
90029+int __request_module(bool wait, const char *fmt, ...)
90030+{
90031+ va_list args;
90032+ int ret;
90033+
90034+#ifdef CONFIG_GRKERNSEC_MODHARDEN
90035+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
90036+ char module_param[MODULE_NAME_LEN];
90037+
90038+ memset(module_param, 0, sizeof(module_param));
90039+
90040+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
90041+
90042+ va_start(args, fmt);
90043+ ret = ____request_module(wait, module_param, fmt, args);
90044+ va_end(args);
90045+
90046+ return ret;
90047+ }
90048+#endif
90049+
90050+ va_start(args, fmt);
90051+ ret = ____request_module(wait, NULL, fmt, args);
90052+ va_end(args);
90053+
90054+ return ret;
90055+}
90056+
90057 EXPORT_SYMBOL(__request_module);
90058 #endif /* CONFIG_MODULES */
90059
90060@@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
90061 */
90062 set_user_nice(current, 0);
90063
90064+#ifdef CONFIG_GRKERNSEC
90065+ /* this is race-free as far as userland is concerned as we copied
90066+ out the path to be used prior to this point and are now operating
90067+ on that copy
90068+ */
90069+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
90070+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
90071+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
90072+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
90073+ retval = -EPERM;
90074+ goto fail;
90075+ }
90076+#endif
90077+
90078 retval = -ENOMEM;
90079 new = prepare_kernel_cred(current);
90080 if (!new)
90081@@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
90082 commit_creds(new);
90083
90084 retval = do_execve(getname_kernel(sub_info->path),
90085- (const char __user *const __user *)sub_info->argv,
90086- (const char __user *const __user *)sub_info->envp);
90087+ (const char __user *const __force_user *)sub_info->argv,
90088+ (const char __user *const __force_user *)sub_info->envp);
90089 if (!retval)
90090 return 0;
90091
90092@@ -260,6 +327,10 @@ static int call_helper(void *data)
90093
90094 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
90095 {
90096+#ifdef CONFIG_GRKERNSEC
90097+ kfree(info->path);
90098+ info->path = info->origpath;
90099+#endif
90100 if (info->cleanup)
90101 (*info->cleanup)(info);
90102 kfree(info);
90103@@ -300,7 +371,7 @@ static int wait_for_helper(void *data)
90104 *
90105 * Thus the __user pointer cast is valid here.
90106 */
90107- sys_wait4(pid, (int __user *)&ret, 0, NULL);
90108+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
90109
90110 /*
90111 * If ret is 0, either ____call_usermodehelper failed and the
90112@@ -539,7 +610,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
90113 goto out;
90114
90115 INIT_WORK(&sub_info->work, __call_usermodehelper);
90116+#ifdef CONFIG_GRKERNSEC
90117+ sub_info->origpath = path;
90118+ sub_info->path = kstrdup(path, gfp_mask);
90119+#else
90120 sub_info->path = path;
90121+#endif
90122 sub_info->argv = argv;
90123 sub_info->envp = envp;
90124
90125@@ -647,7 +723,7 @@ EXPORT_SYMBOL(call_usermodehelper);
90126 static int proc_cap_handler(struct ctl_table *table, int write,
90127 void __user *buffer, size_t *lenp, loff_t *ppos)
90128 {
90129- struct ctl_table t;
90130+ ctl_table_no_const t;
90131 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
90132 kernel_cap_t new_cap;
90133 int err, i;
90134diff --git a/kernel/kprobes.c b/kernel/kprobes.c
90135index 3995f54..e247879 100644
90136--- a/kernel/kprobes.c
90137+++ b/kernel/kprobes.c
90138@@ -31,6 +31,9 @@
90139 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
90140 * <prasanna@in.ibm.com> added function-return probes.
90141 */
90142+#ifdef CONFIG_GRKERNSEC_HIDESYM
90143+#define __INCLUDED_BY_HIDESYM 1
90144+#endif
90145 #include <linux/kprobes.h>
90146 #include <linux/hash.h>
90147 #include <linux/init.h>
90148@@ -122,12 +125,12 @@ enum kprobe_slot_state {
90149
90150 static void *alloc_insn_page(void)
90151 {
90152- return module_alloc(PAGE_SIZE);
90153+ return module_alloc_exec(PAGE_SIZE);
90154 }
90155
90156 static void free_insn_page(void *page)
90157 {
90158- module_free(NULL, page);
90159+ module_free_exec(NULL, page);
90160 }
90161
90162 struct kprobe_insn_cache kprobe_insn_slots = {
90163@@ -2187,11 +2190,11 @@ static void report_probe(struct seq_file *pi, struct kprobe *p,
90164 kprobe_type = "k";
90165
90166 if (sym)
90167- seq_printf(pi, "%p %s %s+0x%x %s ",
90168+ seq_printf(pi, "%pK %s %s+0x%x %s ",
90169 p->addr, kprobe_type, sym, offset,
90170 (modname ? modname : " "));
90171 else
90172- seq_printf(pi, "%p %s %p ",
90173+ seq_printf(pi, "%pK %s %pK ",
90174 p->addr, kprobe_type, p->addr);
90175
90176 if (!pp)
90177diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
90178index 6683cce..daf8999 100644
90179--- a/kernel/ksysfs.c
90180+++ b/kernel/ksysfs.c
90181@@ -50,6 +50,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
90182 {
90183 if (count+1 > UEVENT_HELPER_PATH_LEN)
90184 return -ENOENT;
90185+ if (!capable(CAP_SYS_ADMIN))
90186+ return -EPERM;
90187 memcpy(uevent_helper, buf, count);
90188 uevent_helper[count] = '\0';
90189 if (count && uevent_helper[count-1] == '\n')
90190@@ -176,7 +178,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
90191 return count;
90192 }
90193
90194-static struct bin_attribute notes_attr = {
90195+static bin_attribute_no_const notes_attr __read_only = {
90196 .attr = {
90197 .name = "notes",
90198 .mode = S_IRUGO,
90199diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
90200index 88d0d44..e9ce0ee 100644
90201--- a/kernel/locking/lockdep.c
90202+++ b/kernel/locking/lockdep.c
90203@@ -599,6 +599,10 @@ static int static_obj(void *obj)
90204 end = (unsigned long) &_end,
90205 addr = (unsigned long) obj;
90206
90207+#ifdef CONFIG_PAX_KERNEXEC
90208+ start = ktla_ktva(start);
90209+#endif
90210+
90211 /*
90212 * static variable?
90213 */
90214@@ -740,6 +744,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
90215 if (!static_obj(lock->key)) {
90216 debug_locks_off();
90217 printk("INFO: trying to register non-static key.\n");
90218+ printk("lock:%pS key:%pS.\n", lock, lock->key);
90219 printk("the code is fine but needs lockdep annotation.\n");
90220 printk("turning off the locking correctness validator.\n");
90221 dump_stack();
90222@@ -3081,7 +3086,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
90223 if (!class)
90224 return 0;
90225 }
90226- atomic_inc((atomic_t *)&class->ops);
90227+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
90228 if (very_verbose(class)) {
90229 printk("\nacquire class [%p] %s", class->key, class->name);
90230 if (class->name_version > 1)
90231diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
90232index ef43ac4..2720dfa 100644
90233--- a/kernel/locking/lockdep_proc.c
90234+++ b/kernel/locking/lockdep_proc.c
90235@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
90236 return 0;
90237 }
90238
90239- seq_printf(m, "%p", class->key);
90240+ seq_printf(m, "%pK", class->key);
90241 #ifdef CONFIG_DEBUG_LOCKDEP
90242 seq_printf(m, " OPS:%8ld", class->ops);
90243 #endif
90244@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
90245
90246 list_for_each_entry(entry, &class->locks_after, entry) {
90247 if (entry->distance == 1) {
90248- seq_printf(m, " -> [%p] ", entry->class->key);
90249+ seq_printf(m, " -> [%pK] ", entry->class->key);
90250 print_name(m, entry->class);
90251 seq_puts(m, "\n");
90252 }
90253@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
90254 if (!class->key)
90255 continue;
90256
90257- seq_printf(m, "[%p] ", class->key);
90258+ seq_printf(m, "[%pK] ", class->key);
90259 print_name(m, class);
90260 seq_puts(m, "\n");
90261 }
90262@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90263 if (!i)
90264 seq_line(m, '-', 40-namelen, namelen);
90265
90266- snprintf(ip, sizeof(ip), "[<%p>]",
90267+ snprintf(ip, sizeof(ip), "[<%pK>]",
90268 (void *)class->contention_point[i]);
90269 seq_printf(m, "%40s %14lu %29s %pS\n",
90270 name, stats->contention_point[i],
90271@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
90272 if (!i)
90273 seq_line(m, '-', 40-namelen, namelen);
90274
90275- snprintf(ip, sizeof(ip), "[<%p>]",
90276+ snprintf(ip, sizeof(ip), "[<%pK>]",
90277 (void *)class->contending_point[i]);
90278 seq_printf(m, "%40s %14lu %29s %pS\n",
90279 name, stats->contending_point[i],
90280diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
90281index 9887a90..0cd2b1d 100644
90282--- a/kernel/locking/mcs_spinlock.c
90283+++ b/kernel/locking/mcs_spinlock.c
90284@@ -100,7 +100,7 @@ bool osq_lock(struct optimistic_spin_queue *lock)
90285
90286 prev = decode_cpu(old);
90287 node->prev = prev;
90288- ACCESS_ONCE(prev->next) = node;
90289+ ACCESS_ONCE_RW(prev->next) = node;
90290
90291 /*
90292 * Normally @prev is untouchable after the above store; because at that
90293@@ -172,8 +172,8 @@ unqueue:
90294 * it will wait in Step-A.
90295 */
90296
90297- ACCESS_ONCE(next->prev) = prev;
90298- ACCESS_ONCE(prev->next) = next;
90299+ ACCESS_ONCE_RW(next->prev) = prev;
90300+ ACCESS_ONCE_RW(prev->next) = next;
90301
90302 return false;
90303 }
90304@@ -195,13 +195,13 @@ void osq_unlock(struct optimistic_spin_queue *lock)
90305 node = this_cpu_ptr(&osq_node);
90306 next = xchg(&node->next, NULL);
90307 if (next) {
90308- ACCESS_ONCE(next->locked) = 1;
90309+ ACCESS_ONCE_RW(next->locked) = 1;
90310 return;
90311 }
90312
90313 next = osq_wait_next(lock, node, NULL);
90314 if (next)
90315- ACCESS_ONCE(next->locked) = 1;
90316+ ACCESS_ONCE_RW(next->locked) = 1;
90317 }
90318
90319 #endif
90320diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
90321index 23e89c5..8558eac 100644
90322--- a/kernel/locking/mcs_spinlock.h
90323+++ b/kernel/locking/mcs_spinlock.h
90324@@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
90325 */
90326 return;
90327 }
90328- ACCESS_ONCE(prev->next) = node;
90329+ ACCESS_ONCE_RW(prev->next) = node;
90330
90331 /* Wait until the lock holder passes the lock down. */
90332 arch_mcs_spin_lock_contended(&node->locked);
90333diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
90334index 5cf6731..ce3bc5a 100644
90335--- a/kernel/locking/mutex-debug.c
90336+++ b/kernel/locking/mutex-debug.c
90337@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
90338 }
90339
90340 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90341- struct thread_info *ti)
90342+ struct task_struct *task)
90343 {
90344 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
90345
90346 /* Mark the current thread as blocked on the lock: */
90347- ti->task->blocked_on = waiter;
90348+ task->blocked_on = waiter;
90349 }
90350
90351 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90352- struct thread_info *ti)
90353+ struct task_struct *task)
90354 {
90355 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
90356- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
90357- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
90358- ti->task->blocked_on = NULL;
90359+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
90360+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
90361+ task->blocked_on = NULL;
90362
90363 list_del_init(&waiter->list);
90364 waiter->task = NULL;
90365diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
90366index 0799fd3..d06ae3b 100644
90367--- a/kernel/locking/mutex-debug.h
90368+++ b/kernel/locking/mutex-debug.h
90369@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
90370 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
90371 extern void debug_mutex_add_waiter(struct mutex *lock,
90372 struct mutex_waiter *waiter,
90373- struct thread_info *ti);
90374+ struct task_struct *task);
90375 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
90376- struct thread_info *ti);
90377+ struct task_struct *task);
90378 extern void debug_mutex_unlock(struct mutex *lock);
90379 extern void debug_mutex_init(struct mutex *lock, const char *name,
90380 struct lock_class_key *key);
90381diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
90382index ae712b2..d0d4a41 100644
90383--- a/kernel/locking/mutex.c
90384+++ b/kernel/locking/mutex.c
90385@@ -486,7 +486,7 @@ slowpath:
90386 goto skip_wait;
90387
90388 debug_mutex_lock_common(lock, &waiter);
90389- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
90390+ debug_mutex_add_waiter(lock, &waiter, task);
90391
90392 /* add waiting tasks to the end of the waitqueue (FIFO): */
90393 list_add_tail(&waiter.list, &lock->wait_list);
90394@@ -531,7 +531,7 @@ slowpath:
90395 schedule_preempt_disabled();
90396 spin_lock_mutex(&lock->wait_lock, flags);
90397 }
90398- mutex_remove_waiter(lock, &waiter, current_thread_info());
90399+ mutex_remove_waiter(lock, &waiter, task);
90400 /* set it to 0 if there are no waiters left: */
90401 if (likely(list_empty(&lock->wait_list)))
90402 atomic_set(&lock->count, 0);
90403@@ -568,7 +568,7 @@ skip_wait:
90404 return 0;
90405
90406 err:
90407- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
90408+ mutex_remove_waiter(lock, &waiter, task);
90409 spin_unlock_mutex(&lock->wait_lock, flags);
90410 debug_mutex_free_waiter(&waiter);
90411 mutex_release(&lock->dep_map, 1, ip);
90412diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
90413index 1d96dd0..994ff19 100644
90414--- a/kernel/locking/rtmutex-tester.c
90415+++ b/kernel/locking/rtmutex-tester.c
90416@@ -22,7 +22,7 @@
90417 #define MAX_RT_TEST_MUTEXES 8
90418
90419 static spinlock_t rttest_lock;
90420-static atomic_t rttest_event;
90421+static atomic_unchecked_t rttest_event;
90422
90423 struct test_thread_data {
90424 int opcode;
90425@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90426
90427 case RTTEST_LOCKCONT:
90428 td->mutexes[td->opdata] = 1;
90429- td->event = atomic_add_return(1, &rttest_event);
90430+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90431 return 0;
90432
90433 case RTTEST_RESET:
90434@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90435 return 0;
90436
90437 case RTTEST_RESETEVENT:
90438- atomic_set(&rttest_event, 0);
90439+ atomic_set_unchecked(&rttest_event, 0);
90440 return 0;
90441
90442 default:
90443@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90444 return ret;
90445
90446 td->mutexes[id] = 1;
90447- td->event = atomic_add_return(1, &rttest_event);
90448+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90449 rt_mutex_lock(&mutexes[id]);
90450- td->event = atomic_add_return(1, &rttest_event);
90451+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90452 td->mutexes[id] = 4;
90453 return 0;
90454
90455@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90456 return ret;
90457
90458 td->mutexes[id] = 1;
90459- td->event = atomic_add_return(1, &rttest_event);
90460+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90461 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
90462- td->event = atomic_add_return(1, &rttest_event);
90463+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90464 td->mutexes[id] = ret ? 0 : 4;
90465 return ret ? -EINTR : 0;
90466
90467@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
90468 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
90469 return ret;
90470
90471- td->event = atomic_add_return(1, &rttest_event);
90472+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90473 rt_mutex_unlock(&mutexes[id]);
90474- td->event = atomic_add_return(1, &rttest_event);
90475+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90476 td->mutexes[id] = 0;
90477 return 0;
90478
90479@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90480 break;
90481
90482 td->mutexes[dat] = 2;
90483- td->event = atomic_add_return(1, &rttest_event);
90484+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90485 break;
90486
90487 default:
90488@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90489 return;
90490
90491 td->mutexes[dat] = 3;
90492- td->event = atomic_add_return(1, &rttest_event);
90493+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90494 break;
90495
90496 case RTTEST_LOCKNOWAIT:
90497@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
90498 return;
90499
90500 td->mutexes[dat] = 1;
90501- td->event = atomic_add_return(1, &rttest_event);
90502+ td->event = atomic_add_return_unchecked(1, &rttest_event);
90503 return;
90504
90505 default:
90506diff --git a/kernel/module.c b/kernel/module.c
90507index 1c47139..6242887 100644
90508--- a/kernel/module.c
90509+++ b/kernel/module.c
90510@@ -60,6 +60,7 @@
90511 #include <linux/jump_label.h>
90512 #include <linux/pfn.h>
90513 #include <linux/bsearch.h>
90514+#include <linux/grsecurity.h>
90515 #include <uapi/linux/module.h>
90516 #include "module-internal.h"
90517
90518@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
90519
90520 /* Bounds of module allocation, for speeding __module_address.
90521 * Protected by module_mutex. */
90522-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
90523+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
90524+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
90525
90526 int register_module_notifier(struct notifier_block * nb)
90527 {
90528@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90529 return true;
90530
90531 list_for_each_entry_rcu(mod, &modules, list) {
90532- struct symsearch arr[] = {
90533+ struct symsearch modarr[] = {
90534 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
90535 NOT_GPL_ONLY, false },
90536 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
90537@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
90538 if (mod->state == MODULE_STATE_UNFORMED)
90539 continue;
90540
90541- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
90542+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
90543 return true;
90544 }
90545 return false;
90546@@ -488,7 +490,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
90547 if (!pcpusec->sh_size)
90548 return 0;
90549
90550- if (align > PAGE_SIZE) {
90551+ if (align-1 >= PAGE_SIZE) {
90552 pr_warn("%s: per-cpu alignment %li > %li\n",
90553 mod->name, align, PAGE_SIZE);
90554 align = PAGE_SIZE;
90555@@ -1060,7 +1062,7 @@ struct module_attribute module_uevent =
90556 static ssize_t show_coresize(struct module_attribute *mattr,
90557 struct module_kobject *mk, char *buffer)
90558 {
90559- return sprintf(buffer, "%u\n", mk->mod->core_size);
90560+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
90561 }
90562
90563 static struct module_attribute modinfo_coresize =
90564@@ -1069,7 +1071,7 @@ static struct module_attribute modinfo_coresize =
90565 static ssize_t show_initsize(struct module_attribute *mattr,
90566 struct module_kobject *mk, char *buffer)
90567 {
90568- return sprintf(buffer, "%u\n", mk->mod->init_size);
90569+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
90570 }
90571
90572 static struct module_attribute modinfo_initsize =
90573@@ -1161,12 +1163,29 @@ static int check_version(Elf_Shdr *sechdrs,
90574 goto bad_version;
90575 }
90576
90577+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90578+ /*
90579+ * avoid potentially printing jibberish on attempted load
90580+ * of a module randomized with a different seed
90581+ */
90582+ pr_warn("no symbol version for %s\n", symname);
90583+#else
90584 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
90585+#endif
90586 return 0;
90587
90588 bad_version:
90589+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90590+ /*
90591+ * avoid potentially printing jibberish on attempted load
90592+ * of a module randomized with a different seed
90593+ */
90594+ printk("attempted module disagrees about version of symbol %s\n",
90595+ symname);
90596+#else
90597 printk("%s: disagrees about version of symbol %s\n",
90598 mod->name, symname);
90599+#endif
90600 return 0;
90601 }
90602
90603@@ -1282,7 +1301,7 @@ resolve_symbol_wait(struct module *mod,
90604 */
90605 #ifdef CONFIG_SYSFS
90606
90607-#ifdef CONFIG_KALLSYMS
90608+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
90609 static inline bool sect_empty(const Elf_Shdr *sect)
90610 {
90611 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
90612@@ -1422,7 +1441,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
90613 {
90614 unsigned int notes, loaded, i;
90615 struct module_notes_attrs *notes_attrs;
90616- struct bin_attribute *nattr;
90617+ bin_attribute_no_const *nattr;
90618
90619 /* failed to create section attributes, so can't create notes */
90620 if (!mod->sect_attrs)
90621@@ -1534,7 +1553,7 @@ static void del_usage_links(struct module *mod)
90622 static int module_add_modinfo_attrs(struct module *mod)
90623 {
90624 struct module_attribute *attr;
90625- struct module_attribute *temp_attr;
90626+ module_attribute_no_const *temp_attr;
90627 int error = 0;
90628 int i;
90629
90630@@ -1755,21 +1774,21 @@ static void set_section_ro_nx(void *base,
90631
90632 static void unset_module_core_ro_nx(struct module *mod)
90633 {
90634- set_page_attributes(mod->module_core + mod->core_text_size,
90635- mod->module_core + mod->core_size,
90636+ set_page_attributes(mod->module_core_rw,
90637+ mod->module_core_rw + mod->core_size_rw,
90638 set_memory_x);
90639- set_page_attributes(mod->module_core,
90640- mod->module_core + mod->core_ro_size,
90641+ set_page_attributes(mod->module_core_rx,
90642+ mod->module_core_rx + mod->core_size_rx,
90643 set_memory_rw);
90644 }
90645
90646 static void unset_module_init_ro_nx(struct module *mod)
90647 {
90648- set_page_attributes(mod->module_init + mod->init_text_size,
90649- mod->module_init + mod->init_size,
90650+ set_page_attributes(mod->module_init_rw,
90651+ mod->module_init_rw + mod->init_size_rw,
90652 set_memory_x);
90653- set_page_attributes(mod->module_init,
90654- mod->module_init + mod->init_ro_size,
90655+ set_page_attributes(mod->module_init_rx,
90656+ mod->module_init_rx + mod->init_size_rx,
90657 set_memory_rw);
90658 }
90659
90660@@ -1782,14 +1801,14 @@ void set_all_modules_text_rw(void)
90661 list_for_each_entry_rcu(mod, &modules, list) {
90662 if (mod->state == MODULE_STATE_UNFORMED)
90663 continue;
90664- if ((mod->module_core) && (mod->core_text_size)) {
90665- set_page_attributes(mod->module_core,
90666- mod->module_core + mod->core_text_size,
90667+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
90668+ set_page_attributes(mod->module_core_rx,
90669+ mod->module_core_rx + mod->core_size_rx,
90670 set_memory_rw);
90671 }
90672- if ((mod->module_init) && (mod->init_text_size)) {
90673- set_page_attributes(mod->module_init,
90674- mod->module_init + mod->init_text_size,
90675+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
90676+ set_page_attributes(mod->module_init_rx,
90677+ mod->module_init_rx + mod->init_size_rx,
90678 set_memory_rw);
90679 }
90680 }
90681@@ -1805,14 +1824,14 @@ void set_all_modules_text_ro(void)
90682 list_for_each_entry_rcu(mod, &modules, list) {
90683 if (mod->state == MODULE_STATE_UNFORMED)
90684 continue;
90685- if ((mod->module_core) && (mod->core_text_size)) {
90686- set_page_attributes(mod->module_core,
90687- mod->module_core + mod->core_text_size,
90688+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
90689+ set_page_attributes(mod->module_core_rx,
90690+ mod->module_core_rx + mod->core_size_rx,
90691 set_memory_ro);
90692 }
90693- if ((mod->module_init) && (mod->init_text_size)) {
90694- set_page_attributes(mod->module_init,
90695- mod->module_init + mod->init_text_size,
90696+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
90697+ set_page_attributes(mod->module_init_rx,
90698+ mod->module_init_rx + mod->init_size_rx,
90699 set_memory_ro);
90700 }
90701 }
90702@@ -1865,16 +1884,19 @@ static void free_module(struct module *mod)
90703
90704 /* This may be NULL, but that's OK */
90705 unset_module_init_ro_nx(mod);
90706- module_free(mod, mod->module_init);
90707+ module_free(mod, mod->module_init_rw);
90708+ module_free_exec(mod, mod->module_init_rx);
90709 kfree(mod->args);
90710 percpu_modfree(mod);
90711
90712 /* Free lock-classes: */
90713- lockdep_free_key_range(mod->module_core, mod->core_size);
90714+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
90715+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
90716
90717 /* Finally, free the core (containing the module structure) */
90718 unset_module_core_ro_nx(mod);
90719- module_free(mod, mod->module_core);
90720+ module_free_exec(mod, mod->module_core_rx);
90721+ module_free(mod, mod->module_core_rw);
90722
90723 #ifdef CONFIG_MPU
90724 update_protections(current->mm);
90725@@ -1943,9 +1965,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90726 int ret = 0;
90727 const struct kernel_symbol *ksym;
90728
90729+#ifdef CONFIG_GRKERNSEC_MODHARDEN
90730+ int is_fs_load = 0;
90731+ int register_filesystem_found = 0;
90732+ char *p;
90733+
90734+ p = strstr(mod->args, "grsec_modharden_fs");
90735+ if (p) {
90736+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
90737+ /* copy \0 as well */
90738+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
90739+ is_fs_load = 1;
90740+ }
90741+#endif
90742+
90743 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
90744 const char *name = info->strtab + sym[i].st_name;
90745
90746+#ifdef CONFIG_GRKERNSEC_MODHARDEN
90747+ /* it's a real shame this will never get ripped and copied
90748+ upstream! ;(
90749+ */
90750+ if (is_fs_load && !strcmp(name, "register_filesystem"))
90751+ register_filesystem_found = 1;
90752+#endif
90753+
90754 switch (sym[i].st_shndx) {
90755 case SHN_COMMON:
90756 /* Ignore common symbols */
90757@@ -1970,7 +2014,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90758 ksym = resolve_symbol_wait(mod, info, name);
90759 /* Ok if resolved. */
90760 if (ksym && !IS_ERR(ksym)) {
90761+ pax_open_kernel();
90762 sym[i].st_value = ksym->value;
90763+ pax_close_kernel();
90764 break;
90765 }
90766
90767@@ -1989,11 +2035,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
90768 secbase = (unsigned long)mod_percpu(mod);
90769 else
90770 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
90771+ pax_open_kernel();
90772 sym[i].st_value += secbase;
90773+ pax_close_kernel();
90774 break;
90775 }
90776 }
90777
90778+#ifdef CONFIG_GRKERNSEC_MODHARDEN
90779+ if (is_fs_load && !register_filesystem_found) {
90780+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
90781+ ret = -EPERM;
90782+ }
90783+#endif
90784+
90785 return ret;
90786 }
90787
90788@@ -2077,22 +2132,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
90789 || s->sh_entsize != ~0UL
90790 || strstarts(sname, ".init"))
90791 continue;
90792- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
90793+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90794+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
90795+ else
90796+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
90797 pr_debug("\t%s\n", sname);
90798 }
90799- switch (m) {
90800- case 0: /* executable */
90801- mod->core_size = debug_align(mod->core_size);
90802- mod->core_text_size = mod->core_size;
90803- break;
90804- case 1: /* RO: text and ro-data */
90805- mod->core_size = debug_align(mod->core_size);
90806- mod->core_ro_size = mod->core_size;
90807- break;
90808- case 3: /* whole core */
90809- mod->core_size = debug_align(mod->core_size);
90810- break;
90811- }
90812 }
90813
90814 pr_debug("Init section allocation order:\n");
90815@@ -2106,23 +2151,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
90816 || s->sh_entsize != ~0UL
90817 || !strstarts(sname, ".init"))
90818 continue;
90819- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
90820- | INIT_OFFSET_MASK);
90821+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
90822+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
90823+ else
90824+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
90825+ s->sh_entsize |= INIT_OFFSET_MASK;
90826 pr_debug("\t%s\n", sname);
90827 }
90828- switch (m) {
90829- case 0: /* executable */
90830- mod->init_size = debug_align(mod->init_size);
90831- mod->init_text_size = mod->init_size;
90832- break;
90833- case 1: /* RO: text and ro-data */
90834- mod->init_size = debug_align(mod->init_size);
90835- mod->init_ro_size = mod->init_size;
90836- break;
90837- case 3: /* whole init */
90838- mod->init_size = debug_align(mod->init_size);
90839- break;
90840- }
90841 }
90842 }
90843
90844@@ -2295,7 +2330,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90845
90846 /* Put symbol section at end of init part of module. */
90847 symsect->sh_flags |= SHF_ALLOC;
90848- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
90849+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
90850 info->index.sym) | INIT_OFFSET_MASK;
90851 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
90852
90853@@ -2312,13 +2347,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
90854 }
90855
90856 /* Append room for core symbols at end of core part. */
90857- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
90858- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
90859- mod->core_size += strtab_size;
90860+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
90861+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
90862+ mod->core_size_rx += strtab_size;
90863
90864 /* Put string table section at end of init part of module. */
90865 strsect->sh_flags |= SHF_ALLOC;
90866- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
90867+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
90868 info->index.str) | INIT_OFFSET_MASK;
90869 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
90870 }
90871@@ -2336,12 +2371,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90872 /* Make sure we get permanent strtab: don't use info->strtab. */
90873 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
90874
90875+ pax_open_kernel();
90876+
90877 /* Set types up while we still have access to sections. */
90878 for (i = 0; i < mod->num_symtab; i++)
90879 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
90880
90881- mod->core_symtab = dst = mod->module_core + info->symoffs;
90882- mod->core_strtab = s = mod->module_core + info->stroffs;
90883+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
90884+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
90885 src = mod->symtab;
90886 for (ndst = i = 0; i < mod->num_symtab; i++) {
90887 if (i == 0 ||
90888@@ -2353,6 +2390,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
90889 }
90890 }
90891 mod->core_num_syms = ndst;
90892+
90893+ pax_close_kernel();
90894 }
90895 #else
90896 static inline void layout_symtab(struct module *mod, struct load_info *info)
90897@@ -2386,17 +2425,33 @@ void * __weak module_alloc(unsigned long size)
90898 return vmalloc_exec(size);
90899 }
90900
90901-static void *module_alloc_update_bounds(unsigned long size)
90902+static void *module_alloc_update_bounds_rw(unsigned long size)
90903 {
90904 void *ret = module_alloc(size);
90905
90906 if (ret) {
90907 mutex_lock(&module_mutex);
90908 /* Update module bounds. */
90909- if ((unsigned long)ret < module_addr_min)
90910- module_addr_min = (unsigned long)ret;
90911- if ((unsigned long)ret + size > module_addr_max)
90912- module_addr_max = (unsigned long)ret + size;
90913+ if ((unsigned long)ret < module_addr_min_rw)
90914+ module_addr_min_rw = (unsigned long)ret;
90915+ if ((unsigned long)ret + size > module_addr_max_rw)
90916+ module_addr_max_rw = (unsigned long)ret + size;
90917+ mutex_unlock(&module_mutex);
90918+ }
90919+ return ret;
90920+}
90921+
90922+static void *module_alloc_update_bounds_rx(unsigned long size)
90923+{
90924+ void *ret = module_alloc_exec(size);
90925+
90926+ if (ret) {
90927+ mutex_lock(&module_mutex);
90928+ /* Update module bounds. */
90929+ if ((unsigned long)ret < module_addr_min_rx)
90930+ module_addr_min_rx = (unsigned long)ret;
90931+ if ((unsigned long)ret + size > module_addr_max_rx)
90932+ module_addr_max_rx = (unsigned long)ret + size;
90933 mutex_unlock(&module_mutex);
90934 }
90935 return ret;
90936@@ -2650,7 +2705,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90937 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
90938
90939 if (info->index.sym == 0) {
90940+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
90941+ /*
90942+ * avoid potentially printing jibberish on attempted load
90943+ * of a module randomized with a different seed
90944+ */
90945+ pr_warn("module has no symbols (stripped?)\n");
90946+#else
90947 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
90948+#endif
90949 return ERR_PTR(-ENOEXEC);
90950 }
90951
90952@@ -2666,8 +2729,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
90953 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90954 {
90955 const char *modmagic = get_modinfo(info, "vermagic");
90956+ const char *license = get_modinfo(info, "license");
90957 int err;
90958
90959+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
90960+ if (!license || !license_is_gpl_compatible(license))
90961+ return -ENOEXEC;
90962+#endif
90963+
90964 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
90965 modmagic = NULL;
90966
90967@@ -2692,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
90968 }
90969
90970 /* Set up license info based on the info section */
90971- set_license(mod, get_modinfo(info, "license"));
90972+ set_license(mod, license);
90973
90974 return 0;
90975 }
90976@@ -2786,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
90977 void *ptr;
90978
90979 /* Do the allocs. */
90980- ptr = module_alloc_update_bounds(mod->core_size);
90981+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
90982 /*
90983 * The pointer to this block is stored in the module structure
90984 * which is inside the block. Just mark it as not being a
90985@@ -2796,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
90986 if (!ptr)
90987 return -ENOMEM;
90988
90989- memset(ptr, 0, mod->core_size);
90990- mod->module_core = ptr;
90991+ memset(ptr, 0, mod->core_size_rw);
90992+ mod->module_core_rw = ptr;
90993
90994- if (mod->init_size) {
90995- ptr = module_alloc_update_bounds(mod->init_size);
90996+ if (mod->init_size_rw) {
90997+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
90998 /*
90999 * The pointer to this block is stored in the module structure
91000 * which is inside the block. This block doesn't need to be
91001@@ -2809,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
91002 */
91003 kmemleak_ignore(ptr);
91004 if (!ptr) {
91005- module_free(mod, mod->module_core);
91006+ module_free(mod, mod->module_core_rw);
91007 return -ENOMEM;
91008 }
91009- memset(ptr, 0, mod->init_size);
91010- mod->module_init = ptr;
91011+ memset(ptr, 0, mod->init_size_rw);
91012+ mod->module_init_rw = ptr;
91013 } else
91014- mod->module_init = NULL;
91015+ mod->module_init_rw = NULL;
91016+
91017+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
91018+ kmemleak_not_leak(ptr);
91019+ if (!ptr) {
91020+ if (mod->module_init_rw)
91021+ module_free(mod, mod->module_init_rw);
91022+ module_free(mod, mod->module_core_rw);
91023+ return -ENOMEM;
91024+ }
91025+
91026+ pax_open_kernel();
91027+ memset(ptr, 0, mod->core_size_rx);
91028+ pax_close_kernel();
91029+ mod->module_core_rx = ptr;
91030+
91031+ if (mod->init_size_rx) {
91032+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
91033+ kmemleak_ignore(ptr);
91034+ if (!ptr && mod->init_size_rx) {
91035+ module_free_exec(mod, mod->module_core_rx);
91036+ if (mod->module_init_rw)
91037+ module_free(mod, mod->module_init_rw);
91038+ module_free(mod, mod->module_core_rw);
91039+ return -ENOMEM;
91040+ }
91041+
91042+ pax_open_kernel();
91043+ memset(ptr, 0, mod->init_size_rx);
91044+ pax_close_kernel();
91045+ mod->module_init_rx = ptr;
91046+ } else
91047+ mod->module_init_rx = NULL;
91048
91049 /* Transfer each section which specifies SHF_ALLOC */
91050 pr_debug("final section addresses:\n");
91051@@ -2826,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
91052 if (!(shdr->sh_flags & SHF_ALLOC))
91053 continue;
91054
91055- if (shdr->sh_entsize & INIT_OFFSET_MASK)
91056- dest = mod->module_init
91057- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91058- else
91059- dest = mod->module_core + shdr->sh_entsize;
91060+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
91061+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
91062+ dest = mod->module_init_rw
91063+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91064+ else
91065+ dest = mod->module_init_rx
91066+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
91067+ } else {
91068+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
91069+ dest = mod->module_core_rw + shdr->sh_entsize;
91070+ else
91071+ dest = mod->module_core_rx + shdr->sh_entsize;
91072+ }
91073+
91074+ if (shdr->sh_type != SHT_NOBITS) {
91075+
91076+#ifdef CONFIG_PAX_KERNEXEC
91077+#ifdef CONFIG_X86_64
91078+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
91079+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
91080+#endif
91081+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
91082+ pax_open_kernel();
91083+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91084+ pax_close_kernel();
91085+ } else
91086+#endif
91087
91088- if (shdr->sh_type != SHT_NOBITS)
91089 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
91090+ }
91091 /* Update sh_addr to point to copy in image. */
91092- shdr->sh_addr = (unsigned long)dest;
91093+
91094+#ifdef CONFIG_PAX_KERNEXEC
91095+ if (shdr->sh_flags & SHF_EXECINSTR)
91096+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
91097+ else
91098+#endif
91099+
91100+ shdr->sh_addr = (unsigned long)dest;
91101 pr_debug("\t0x%lx %s\n",
91102 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
91103 }
91104@@ -2892,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
91105 * Do it before processing of module parameters, so the module
91106 * can provide parameter accessor functions of its own.
91107 */
91108- if (mod->module_init)
91109- flush_icache_range((unsigned long)mod->module_init,
91110- (unsigned long)mod->module_init
91111- + mod->init_size);
91112- flush_icache_range((unsigned long)mod->module_core,
91113- (unsigned long)mod->module_core + mod->core_size);
91114+ if (mod->module_init_rx)
91115+ flush_icache_range((unsigned long)mod->module_init_rx,
91116+ (unsigned long)mod->module_init_rx
91117+ + mod->init_size_rx);
91118+ flush_icache_range((unsigned long)mod->module_core_rx,
91119+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
91120
91121 set_fs(old_fs);
91122 }
91123@@ -2954,8 +3084,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
91124 static void module_deallocate(struct module *mod, struct load_info *info)
91125 {
91126 percpu_modfree(mod);
91127- module_free(mod, mod->module_init);
91128- module_free(mod, mod->module_core);
91129+ module_free_exec(mod, mod->module_init_rx);
91130+ module_free_exec(mod, mod->module_core_rx);
91131+ module_free(mod, mod->module_init_rw);
91132+ module_free(mod, mod->module_core_rw);
91133 }
91134
91135 int __weak module_finalize(const Elf_Ehdr *hdr,
91136@@ -2968,7 +3100,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
91137 static int post_relocation(struct module *mod, const struct load_info *info)
91138 {
91139 /* Sort exception table now relocations are done. */
91140+ pax_open_kernel();
91141 sort_extable(mod->extable, mod->extable + mod->num_exentries);
91142+ pax_close_kernel();
91143
91144 /* Copy relocated percpu area over. */
91145 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
91146@@ -3077,11 +3211,12 @@ static int do_init_module(struct module *mod)
91147 mod->strtab = mod->core_strtab;
91148 #endif
91149 unset_module_init_ro_nx(mod);
91150- module_free(mod, mod->module_init);
91151- mod->module_init = NULL;
91152- mod->init_size = 0;
91153- mod->init_ro_size = 0;
91154- mod->init_text_size = 0;
91155+ module_free(mod, mod->module_init_rw);
91156+ module_free_exec(mod, mod->module_init_rx);
91157+ mod->module_init_rw = NULL;
91158+ mod->module_init_rx = NULL;
91159+ mod->init_size_rw = 0;
91160+ mod->init_size_rx = 0;
91161 mutex_unlock(&module_mutex);
91162 wake_up_all(&module_wq);
91163
91164@@ -3149,16 +3284,16 @@ static int complete_formation(struct module *mod, struct load_info *info)
91165 module_bug_finalize(info->hdr, info->sechdrs, mod);
91166
91167 /* Set RO and NX regions for core */
91168- set_section_ro_nx(mod->module_core,
91169- mod->core_text_size,
91170- mod->core_ro_size,
91171- mod->core_size);
91172+ set_section_ro_nx(mod->module_core_rx,
91173+ mod->core_size_rx,
91174+ mod->core_size_rx,
91175+ mod->core_size_rx);
91176
91177 /* Set RO and NX regions for init */
91178- set_section_ro_nx(mod->module_init,
91179- mod->init_text_size,
91180- mod->init_ro_size,
91181- mod->init_size);
91182+ set_section_ro_nx(mod->module_init_rx,
91183+ mod->init_size_rx,
91184+ mod->init_size_rx,
91185+ mod->init_size_rx);
91186
91187 /* Mark state as coming so strong_try_module_get() ignores us,
91188 * but kallsyms etc. can see us. */
91189@@ -3242,9 +3377,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
91190 if (err)
91191 goto free_unload;
91192
91193+ /* Now copy in args */
91194+ mod->args = strndup_user(uargs, ~0UL >> 1);
91195+ if (IS_ERR(mod->args)) {
91196+ err = PTR_ERR(mod->args);
91197+ goto free_unload;
91198+ }
91199+
91200 /* Set up MODINFO_ATTR fields */
91201 setup_modinfo(mod, info);
91202
91203+#ifdef CONFIG_GRKERNSEC_MODHARDEN
91204+ {
91205+ char *p, *p2;
91206+
91207+ if (strstr(mod->args, "grsec_modharden_netdev")) {
91208+ 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);
91209+ err = -EPERM;
91210+ goto free_modinfo;
91211+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
91212+ p += sizeof("grsec_modharden_normal") - 1;
91213+ p2 = strstr(p, "_");
91214+ if (p2) {
91215+ *p2 = '\0';
91216+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
91217+ *p2 = '_';
91218+ }
91219+ err = -EPERM;
91220+ goto free_modinfo;
91221+ }
91222+ }
91223+#endif
91224+
91225 /* Fix up syms, so that st_value is a pointer to location. */
91226 err = simplify_symbols(mod, info);
91227 if (err < 0)
91228@@ -3260,13 +3424,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
91229
91230 flush_module_icache(mod);
91231
91232- /* Now copy in args */
91233- mod->args = strndup_user(uargs, ~0UL >> 1);
91234- if (IS_ERR(mod->args)) {
91235- err = PTR_ERR(mod->args);
91236- goto free_arch_cleanup;
91237- }
91238-
91239 dynamic_debug_setup(info->debug, info->num_debug);
91240
91241 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
91242@@ -3314,11 +3471,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
91243 ddebug_cleanup:
91244 dynamic_debug_remove(info->debug);
91245 synchronize_sched();
91246- kfree(mod->args);
91247- free_arch_cleanup:
91248 module_arch_cleanup(mod);
91249 free_modinfo:
91250 free_modinfo(mod);
91251+ kfree(mod->args);
91252 free_unload:
91253 module_unload_free(mod);
91254 unlink_mod:
91255@@ -3403,10 +3559,16 @@ static const char *get_ksymbol(struct module *mod,
91256 unsigned long nextval;
91257
91258 /* At worse, next value is at end of module */
91259- if (within_module_init(addr, mod))
91260- nextval = (unsigned long)mod->module_init+mod->init_text_size;
91261+ if (within_module_init_rx(addr, mod))
91262+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
91263+ else if (within_module_init_rw(addr, mod))
91264+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
91265+ else if (within_module_core_rx(addr, mod))
91266+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
91267+ else if (within_module_core_rw(addr, mod))
91268+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
91269 else
91270- nextval = (unsigned long)mod->module_core+mod->core_text_size;
91271+ return NULL;
91272
91273 /* Scan for closest preceding symbol, and next symbol. (ELF
91274 starts real symbols at 1). */
91275@@ -3654,7 +3816,7 @@ static int m_show(struct seq_file *m, void *p)
91276 return 0;
91277
91278 seq_printf(m, "%s %u",
91279- mod->name, mod->init_size + mod->core_size);
91280+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
91281 print_unload_info(m, mod);
91282
91283 /* Informative for users. */
91284@@ -3663,7 +3825,7 @@ static int m_show(struct seq_file *m, void *p)
91285 mod->state == MODULE_STATE_COMING ? "Loading":
91286 "Live");
91287 /* Used by oprofile and other similar tools. */
91288- seq_printf(m, " 0x%pK", mod->module_core);
91289+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
91290
91291 /* Taints info */
91292 if (mod->taints)
91293@@ -3699,7 +3861,17 @@ static const struct file_operations proc_modules_operations = {
91294
91295 static int __init proc_modules_init(void)
91296 {
91297+#ifndef CONFIG_GRKERNSEC_HIDESYM
91298+#ifdef CONFIG_GRKERNSEC_PROC_USER
91299+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91300+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
91301+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
91302+#else
91303 proc_create("modules", 0, NULL, &proc_modules_operations);
91304+#endif
91305+#else
91306+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
91307+#endif
91308 return 0;
91309 }
91310 module_init(proc_modules_init);
91311@@ -3760,7 +3932,8 @@ struct module *__module_address(unsigned long addr)
91312 {
91313 struct module *mod;
91314
91315- if (addr < module_addr_min || addr > module_addr_max)
91316+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
91317+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
91318 return NULL;
91319
91320 list_for_each_entry_rcu(mod, &modules, list) {
91321@@ -3801,11 +3974,20 @@ bool is_module_text_address(unsigned long addr)
91322 */
91323 struct module *__module_text_address(unsigned long addr)
91324 {
91325- struct module *mod = __module_address(addr);
91326+ struct module *mod;
91327+
91328+#ifdef CONFIG_X86_32
91329+ addr = ktla_ktva(addr);
91330+#endif
91331+
91332+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
91333+ return NULL;
91334+
91335+ mod = __module_address(addr);
91336+
91337 if (mod) {
91338 /* Make sure it's within the text section. */
91339- if (!within(addr, mod->module_init, mod->init_text_size)
91340- && !within(addr, mod->module_core, mod->core_text_size))
91341+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
91342 mod = NULL;
91343 }
91344 return mod;
91345diff --git a/kernel/notifier.c b/kernel/notifier.c
91346index 4803da6..1c5eea6 100644
91347--- a/kernel/notifier.c
91348+++ b/kernel/notifier.c
91349@@ -5,6 +5,7 @@
91350 #include <linux/rcupdate.h>
91351 #include <linux/vmalloc.h>
91352 #include <linux/reboot.h>
91353+#include <linux/mm.h>
91354
91355 /*
91356 * Notifier list for kernel code which wants to be called
91357@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
91358 while ((*nl) != NULL) {
91359 if (n->priority > (*nl)->priority)
91360 break;
91361- nl = &((*nl)->next);
91362+ nl = (struct notifier_block **)&((*nl)->next);
91363 }
91364- n->next = *nl;
91365+ pax_open_kernel();
91366+ *(const void **)&n->next = *nl;
91367 rcu_assign_pointer(*nl, n);
91368+ pax_close_kernel();
91369 return 0;
91370 }
91371
91372@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
91373 return 0;
91374 if (n->priority > (*nl)->priority)
91375 break;
91376- nl = &((*nl)->next);
91377+ nl = (struct notifier_block **)&((*nl)->next);
91378 }
91379- n->next = *nl;
91380+ pax_open_kernel();
91381+ *(const void **)&n->next = *nl;
91382 rcu_assign_pointer(*nl, n);
91383+ pax_close_kernel();
91384 return 0;
91385 }
91386
91387@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
91388 {
91389 while ((*nl) != NULL) {
91390 if ((*nl) == n) {
91391+ pax_open_kernel();
91392 rcu_assign_pointer(*nl, n->next);
91393+ pax_close_kernel();
91394 return 0;
91395 }
91396- nl = &((*nl)->next);
91397+ nl = (struct notifier_block **)&((*nl)->next);
91398 }
91399 return -ENOENT;
91400 }
91401diff --git a/kernel/padata.c b/kernel/padata.c
91402index 161402f..598814c 100644
91403--- a/kernel/padata.c
91404+++ b/kernel/padata.c
91405@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
91406 * seq_nr mod. number of cpus in use.
91407 */
91408
91409- seq_nr = atomic_inc_return(&pd->seq_nr);
91410+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
91411 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
91412
91413 return padata_index_to_cpu(pd, cpu_index);
91414@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
91415 padata_init_pqueues(pd);
91416 padata_init_squeues(pd);
91417 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
91418- atomic_set(&pd->seq_nr, -1);
91419+ atomic_set_unchecked(&pd->seq_nr, -1);
91420 atomic_set(&pd->reorder_objects, 0);
91421 atomic_set(&pd->refcnt, 0);
91422 pd->pinst = pinst;
91423diff --git a/kernel/panic.c b/kernel/panic.c
91424index d09dc5c..9abbdff 100644
91425--- a/kernel/panic.c
91426+++ b/kernel/panic.c
91427@@ -53,7 +53,7 @@ EXPORT_SYMBOL(panic_blink);
91428 /*
91429 * Stop ourself in panic -- architecture code may override this
91430 */
91431-void __weak panic_smp_self_stop(void)
91432+void __weak __noreturn panic_smp_self_stop(void)
91433 {
91434 while (1)
91435 cpu_relax();
91436@@ -421,7 +421,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
91437 disable_trace_on_warning();
91438
91439 pr_warn("------------[ cut here ]------------\n");
91440- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
91441+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
91442 raw_smp_processor_id(), current->pid, file, line, caller);
91443
91444 if (args)
91445@@ -475,7 +475,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
91446 */
91447 __visible void __stack_chk_fail(void)
91448 {
91449- panic("stack-protector: Kernel stack is corrupted in: %p\n",
91450+ dump_stack();
91451+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
91452 __builtin_return_address(0));
91453 }
91454 EXPORT_SYMBOL(__stack_chk_fail);
91455diff --git a/kernel/pid.c b/kernel/pid.c
91456index 9b9a266..c20ef80 100644
91457--- a/kernel/pid.c
91458+++ b/kernel/pid.c
91459@@ -33,6 +33,7 @@
91460 #include <linux/rculist.h>
91461 #include <linux/bootmem.h>
91462 #include <linux/hash.h>
91463+#include <linux/security.h>
91464 #include <linux/pid_namespace.h>
91465 #include <linux/init_task.h>
91466 #include <linux/syscalls.h>
91467@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
91468
91469 int pid_max = PID_MAX_DEFAULT;
91470
91471-#define RESERVED_PIDS 300
91472+#define RESERVED_PIDS 500
91473
91474 int pid_max_min = RESERVED_PIDS + 1;
91475 int pid_max_max = PID_MAX_LIMIT;
91476@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
91477 */
91478 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
91479 {
91480+ struct task_struct *task;
91481+
91482 rcu_lockdep_assert(rcu_read_lock_held(),
91483 "find_task_by_pid_ns() needs rcu_read_lock()"
91484 " protection");
91485- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91486+
91487+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
91488+
91489+ if (gr_pid_is_chrooted(task))
91490+ return NULL;
91491+
91492+ return task;
91493 }
91494
91495 struct task_struct *find_task_by_vpid(pid_t vnr)
91496@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
91497 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
91498 }
91499
91500+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
91501+{
91502+ rcu_lockdep_assert(rcu_read_lock_held(),
91503+ "find_task_by_pid_ns() needs rcu_read_lock()"
91504+ " protection");
91505+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
91506+}
91507+
91508 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
91509 {
91510 struct pid *pid;
91511diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
91512index db95d8e..a0ca23f 100644
91513--- a/kernel/pid_namespace.c
91514+++ b/kernel/pid_namespace.c
91515@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
91516 void __user *buffer, size_t *lenp, loff_t *ppos)
91517 {
91518 struct pid_namespace *pid_ns = task_active_pid_ns(current);
91519- struct ctl_table tmp = *table;
91520+ ctl_table_no_const tmp = *table;
91521
91522 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
91523 return -EPERM;
91524diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
91525index e4e4121..71faf14 100644
91526--- a/kernel/power/Kconfig
91527+++ b/kernel/power/Kconfig
91528@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
91529 config HIBERNATION
91530 bool "Hibernation (aka 'suspend to disk')"
91531 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
91532+ depends on !GRKERNSEC_KMEM
91533+ depends on !PAX_MEMORY_SANITIZE
91534 select HIBERNATE_CALLBACKS
91535 select LZO_COMPRESS
91536 select LZO_DECOMPRESS
91537diff --git a/kernel/power/process.c b/kernel/power/process.c
91538index 7a37cf3..3e4c1c8 100644
91539--- a/kernel/power/process.c
91540+++ b/kernel/power/process.c
91541@@ -35,6 +35,7 @@ static int try_to_freeze_tasks(bool user_only)
91542 unsigned int elapsed_msecs;
91543 bool wakeup = false;
91544 int sleep_usecs = USEC_PER_MSEC;
91545+ bool timedout = false;
91546
91547 do_gettimeofday(&start);
91548
91549@@ -45,13 +46,20 @@ static int try_to_freeze_tasks(bool user_only)
91550
91551 while (true) {
91552 todo = 0;
91553+ if (time_after(jiffies, end_time))
91554+ timedout = true;
91555 read_lock(&tasklist_lock);
91556 do_each_thread(g, p) {
91557 if (p == current || !freeze_task(p))
91558 continue;
91559
91560- if (!freezer_should_skip(p))
91561+ if (!freezer_should_skip(p)) {
91562 todo++;
91563+ if (timedout) {
91564+ printk(KERN_ERR "Task refusing to freeze:\n");
91565+ sched_show_task(p);
91566+ }
91567+ }
91568 } while_each_thread(g, p);
91569 read_unlock(&tasklist_lock);
91570
91571@@ -60,7 +68,7 @@ static int try_to_freeze_tasks(bool user_only)
91572 todo += wq_busy;
91573 }
91574
91575- if (!todo || time_after(jiffies, end_time))
91576+ if (!todo || timedout)
91577 break;
91578
91579 if (pm_wakeup_pending()) {
91580diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
91581index 1ce7706..3b07c49 100644
91582--- a/kernel/printk/printk.c
91583+++ b/kernel/printk/printk.c
91584@@ -490,6 +490,11 @@ static int check_syslog_permissions(int type, bool from_file)
91585 if (from_file && type != SYSLOG_ACTION_OPEN)
91586 return 0;
91587
91588+#ifdef CONFIG_GRKERNSEC_DMESG
91589+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
91590+ return -EPERM;
91591+#endif
91592+
91593 if (syslog_action_restricted(type)) {
91594 if (capable(CAP_SYSLOG))
91595 return 0;
91596diff --git a/kernel/profile.c b/kernel/profile.c
91597index 54bf5ba..df6e0a2 100644
91598--- a/kernel/profile.c
91599+++ b/kernel/profile.c
91600@@ -37,7 +37,7 @@ struct profile_hit {
91601 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
91602 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
91603
91604-static atomic_t *prof_buffer;
91605+static atomic_unchecked_t *prof_buffer;
91606 static unsigned long prof_len, prof_shift;
91607
91608 int prof_on __read_mostly;
91609@@ -256,7 +256,7 @@ static void profile_flip_buffers(void)
91610 hits[i].pc = 0;
91611 continue;
91612 }
91613- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91614+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91615 hits[i].hits = hits[i].pc = 0;
91616 }
91617 }
91618@@ -317,9 +317,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91619 * Add the current hit(s) and flush the write-queue out
91620 * to the global buffer:
91621 */
91622- atomic_add(nr_hits, &prof_buffer[pc]);
91623+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
91624 for (i = 0; i < NR_PROFILE_HIT; ++i) {
91625- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
91626+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
91627 hits[i].pc = hits[i].hits = 0;
91628 }
91629 out:
91630@@ -394,7 +394,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
91631 {
91632 unsigned long pc;
91633 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
91634- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91635+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
91636 }
91637 #endif /* !CONFIG_SMP */
91638
91639@@ -490,7 +490,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
91640 return -EFAULT;
91641 buf++; p++; count--; read++;
91642 }
91643- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
91644+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
91645 if (copy_to_user(buf, (void *)pnt, count))
91646 return -EFAULT;
91647 read += count;
91648@@ -521,7 +521,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
91649 }
91650 #endif
91651 profile_discard_flip_buffers();
91652- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
91653+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
91654 return count;
91655 }
91656
91657diff --git a/kernel/ptrace.c b/kernel/ptrace.c
91658index 54e7522..5b82dd6 100644
91659--- a/kernel/ptrace.c
91660+++ b/kernel/ptrace.c
91661@@ -321,7 +321,7 @@ static int ptrace_attach(struct task_struct *task, long request,
91662 if (seize)
91663 flags |= PT_SEIZED;
91664 rcu_read_lock();
91665- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91666+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
91667 flags |= PT_PTRACE_CAP;
91668 rcu_read_unlock();
91669 task->ptrace = flags;
91670@@ -532,7 +532,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
91671 break;
91672 return -EIO;
91673 }
91674- if (copy_to_user(dst, buf, retval))
91675+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
91676 return -EFAULT;
91677 copied += retval;
91678 src += retval;
91679@@ -800,7 +800,7 @@ int ptrace_request(struct task_struct *child, long request,
91680 bool seized = child->ptrace & PT_SEIZED;
91681 int ret = -EIO;
91682 siginfo_t siginfo, *si;
91683- void __user *datavp = (void __user *) data;
91684+ void __user *datavp = (__force void __user *) data;
91685 unsigned long __user *datalp = datavp;
91686 unsigned long flags;
91687
91688@@ -1046,14 +1046,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
91689 goto out;
91690 }
91691
91692+ if (gr_handle_ptrace(child, request)) {
91693+ ret = -EPERM;
91694+ goto out_put_task_struct;
91695+ }
91696+
91697 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91698 ret = ptrace_attach(child, request, addr, data);
91699 /*
91700 * Some architectures need to do book-keeping after
91701 * a ptrace attach.
91702 */
91703- if (!ret)
91704+ if (!ret) {
91705 arch_ptrace_attach(child);
91706+ gr_audit_ptrace(child);
91707+ }
91708 goto out_put_task_struct;
91709 }
91710
91711@@ -1081,7 +1088,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
91712 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
91713 if (copied != sizeof(tmp))
91714 return -EIO;
91715- return put_user(tmp, (unsigned long __user *)data);
91716+ return put_user(tmp, (__force unsigned long __user *)data);
91717 }
91718
91719 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
91720@@ -1175,7 +1182,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
91721 }
91722
91723 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91724- compat_long_t, addr, compat_long_t, data)
91725+ compat_ulong_t, addr, compat_ulong_t, data)
91726 {
91727 struct task_struct *child;
91728 long ret;
91729@@ -1191,14 +1198,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
91730 goto out;
91731 }
91732
91733+ if (gr_handle_ptrace(child, request)) {
91734+ ret = -EPERM;
91735+ goto out_put_task_struct;
91736+ }
91737+
91738 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
91739 ret = ptrace_attach(child, request, addr, data);
91740 /*
91741 * Some architectures need to do book-keeping after
91742 * a ptrace attach.
91743 */
91744- if (!ret)
91745+ if (!ret) {
91746 arch_ptrace_attach(child);
91747+ gr_audit_ptrace(child);
91748+ }
91749 goto out_put_task_struct;
91750 }
91751
91752diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
91753index 948a769..5ca842b 100644
91754--- a/kernel/rcu/rcutorture.c
91755+++ b/kernel/rcu/rcutorture.c
91756@@ -124,12 +124,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91757 rcu_torture_count) = { 0 };
91758 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
91759 rcu_torture_batch) = { 0 };
91760-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91761-static atomic_t n_rcu_torture_alloc;
91762-static atomic_t n_rcu_torture_alloc_fail;
91763-static atomic_t n_rcu_torture_free;
91764-static atomic_t n_rcu_torture_mberror;
91765-static atomic_t n_rcu_torture_error;
91766+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
91767+static atomic_unchecked_t n_rcu_torture_alloc;
91768+static atomic_unchecked_t n_rcu_torture_alloc_fail;
91769+static atomic_unchecked_t n_rcu_torture_free;
91770+static atomic_unchecked_t n_rcu_torture_mberror;
91771+static atomic_unchecked_t n_rcu_torture_error;
91772 static long n_rcu_torture_barrier_error;
91773 static long n_rcu_torture_boost_ktrerror;
91774 static long n_rcu_torture_boost_rterror;
91775@@ -200,11 +200,11 @@ rcu_torture_alloc(void)
91776
91777 spin_lock_bh(&rcu_torture_lock);
91778 if (list_empty(&rcu_torture_freelist)) {
91779- atomic_inc(&n_rcu_torture_alloc_fail);
91780+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
91781 spin_unlock_bh(&rcu_torture_lock);
91782 return NULL;
91783 }
91784- atomic_inc(&n_rcu_torture_alloc);
91785+ atomic_inc_unchecked(&n_rcu_torture_alloc);
91786 p = rcu_torture_freelist.next;
91787 list_del_init(p);
91788 spin_unlock_bh(&rcu_torture_lock);
91789@@ -217,7 +217,7 @@ rcu_torture_alloc(void)
91790 static void
91791 rcu_torture_free(struct rcu_torture *p)
91792 {
91793- atomic_inc(&n_rcu_torture_free);
91794+ atomic_inc_unchecked(&n_rcu_torture_free);
91795 spin_lock_bh(&rcu_torture_lock);
91796 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
91797 spin_unlock_bh(&rcu_torture_lock);
91798@@ -301,7 +301,7 @@ rcu_torture_pipe_update_one(struct rcu_torture *rp)
91799 i = rp->rtort_pipe_count;
91800 if (i > RCU_TORTURE_PIPE_LEN)
91801 i = RCU_TORTURE_PIPE_LEN;
91802- atomic_inc(&rcu_torture_wcount[i]);
91803+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
91804 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
91805 rp->rtort_mbtest = 0;
91806 return true;
91807@@ -808,7 +808,7 @@ rcu_torture_writer(void *arg)
91808 i = old_rp->rtort_pipe_count;
91809 if (i > RCU_TORTURE_PIPE_LEN)
91810 i = RCU_TORTURE_PIPE_LEN;
91811- atomic_inc(&rcu_torture_wcount[i]);
91812+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
91813 old_rp->rtort_pipe_count++;
91814 switch (synctype[torture_random(&rand) % nsynctypes]) {
91815 case RTWS_DEF_FREE:
91816@@ -926,7 +926,7 @@ static void rcu_torture_timer(unsigned long unused)
91817 return;
91818 }
91819 if (p->rtort_mbtest == 0)
91820- atomic_inc(&n_rcu_torture_mberror);
91821+ atomic_inc_unchecked(&n_rcu_torture_mberror);
91822 spin_lock(&rand_lock);
91823 cur_ops->read_delay(&rand);
91824 n_rcu_torture_timers++;
91825@@ -996,7 +996,7 @@ rcu_torture_reader(void *arg)
91826 continue;
91827 }
91828 if (p->rtort_mbtest == 0)
91829- atomic_inc(&n_rcu_torture_mberror);
91830+ atomic_inc_unchecked(&n_rcu_torture_mberror);
91831 cur_ops->read_delay(&rand);
91832 preempt_disable();
91833 pipe_count = p->rtort_pipe_count;
91834@@ -1054,15 +1054,15 @@ rcu_torture_printk(char *page)
91835 }
91836 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
91837 page += sprintf(page,
91838- "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
91839+ "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
91840 rcu_torture_current,
91841 rcu_torture_current_version,
91842 list_empty(&rcu_torture_freelist),
91843- atomic_read(&n_rcu_torture_alloc),
91844- atomic_read(&n_rcu_torture_alloc_fail),
91845- atomic_read(&n_rcu_torture_free));
91846+ atomic_read_unchecked(&n_rcu_torture_alloc),
91847+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
91848+ atomic_read_unchecked(&n_rcu_torture_free));
91849 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
91850- atomic_read(&n_rcu_torture_mberror),
91851+ atomic_read_unchecked(&n_rcu_torture_mberror),
91852 n_rcu_torture_boost_ktrerror,
91853 n_rcu_torture_boost_rterror);
91854 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
91855@@ -1075,14 +1075,14 @@ rcu_torture_printk(char *page)
91856 n_barrier_attempts,
91857 n_rcu_torture_barrier_error);
91858 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
91859- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
91860+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
91861 n_rcu_torture_barrier_error != 0 ||
91862 n_rcu_torture_boost_ktrerror != 0 ||
91863 n_rcu_torture_boost_rterror != 0 ||
91864 n_rcu_torture_boost_failure != 0 ||
91865 i > 1) {
91866 page += sprintf(page, "!!! ");
91867- atomic_inc(&n_rcu_torture_error);
91868+ atomic_inc_unchecked(&n_rcu_torture_error);
91869 WARN_ON_ONCE(1);
91870 }
91871 page += sprintf(page, "Reader Pipe: ");
91872@@ -1096,7 +1096,7 @@ rcu_torture_printk(char *page)
91873 page += sprintf(page, "Free-Block Circulation: ");
91874 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91875 page += sprintf(page, " %d",
91876- atomic_read(&rcu_torture_wcount[i]));
91877+ atomic_read_unchecked(&rcu_torture_wcount[i]));
91878 }
91879 page += sprintf(page, "\n");
91880 if (cur_ops->stats)
91881@@ -1461,7 +1461,7 @@ rcu_torture_cleanup(void)
91882
91883 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
91884
91885- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91886+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
91887 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
91888 else if (torture_onoff_failures())
91889 rcu_torture_print_module_parms(cur_ops,
91890@@ -1584,18 +1584,18 @@ rcu_torture_init(void)
91891
91892 rcu_torture_current = NULL;
91893 rcu_torture_current_version = 0;
91894- atomic_set(&n_rcu_torture_alloc, 0);
91895- atomic_set(&n_rcu_torture_alloc_fail, 0);
91896- atomic_set(&n_rcu_torture_free, 0);
91897- atomic_set(&n_rcu_torture_mberror, 0);
91898- atomic_set(&n_rcu_torture_error, 0);
91899+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
91900+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
91901+ atomic_set_unchecked(&n_rcu_torture_free, 0);
91902+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
91903+ atomic_set_unchecked(&n_rcu_torture_error, 0);
91904 n_rcu_torture_barrier_error = 0;
91905 n_rcu_torture_boost_ktrerror = 0;
91906 n_rcu_torture_boost_rterror = 0;
91907 n_rcu_torture_boost_failure = 0;
91908 n_rcu_torture_boosts = 0;
91909 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
91910- atomic_set(&rcu_torture_wcount[i], 0);
91911+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
91912 for_each_possible_cpu(cpu) {
91913 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
91914 per_cpu(rcu_torture_count, cpu)[i] = 0;
91915diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
91916index d9efcc1..ea543e9 100644
91917--- a/kernel/rcu/tiny.c
91918+++ b/kernel/rcu/tiny.c
91919@@ -42,7 +42,7 @@
91920 /* Forward declarations for tiny_plugin.h. */
91921 struct rcu_ctrlblk;
91922 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
91923-static void rcu_process_callbacks(struct softirq_action *unused);
91924+static void rcu_process_callbacks(void);
91925 static void __call_rcu(struct rcu_head *head,
91926 void (*func)(struct rcu_head *rcu),
91927 struct rcu_ctrlblk *rcp);
91928@@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
91929 false));
91930 }
91931
91932-static void rcu_process_callbacks(struct softirq_action *unused)
91933+static __latent_entropy void rcu_process_callbacks(void)
91934 {
91935 __rcu_process_callbacks(&rcu_sched_ctrlblk);
91936 __rcu_process_callbacks(&rcu_bh_ctrlblk);
91937diff --git a/kernel/rcu/tiny_plugin.h b/kernel/rcu/tiny_plugin.h
91938index 858c565..7efd915 100644
91939--- a/kernel/rcu/tiny_plugin.h
91940+++ b/kernel/rcu/tiny_plugin.h
91941@@ -152,17 +152,17 @@ static void check_cpu_stall(struct rcu_ctrlblk *rcp)
91942 dump_stack();
91943 }
91944 if (*rcp->curtail && ULONG_CMP_GE(j, js))
91945- ACCESS_ONCE(rcp->jiffies_stall) = jiffies +
91946+ ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies +
91947 3 * rcu_jiffies_till_stall_check() + 3;
91948 else if (ULONG_CMP_GE(j, js))
91949- ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91950+ ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91951 }
91952
91953 static void reset_cpu_stall_ticks(struct rcu_ctrlblk *rcp)
91954 {
91955 rcp->ticks_this_gp = 0;
91956 rcp->gp_start = jiffies;
91957- ACCESS_ONCE(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91958+ ACCESS_ONCE_RW(rcp->jiffies_stall) = jiffies + rcu_jiffies_till_stall_check();
91959 }
91960
91961 static void check_cpu_stalls(void)
91962diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
91963index 1b70cb6..ea62b0a 100644
91964--- a/kernel/rcu/tree.c
91965+++ b/kernel/rcu/tree.c
91966@@ -263,7 +263,7 @@ static void rcu_momentary_dyntick_idle(void)
91967 */
91968 rdtp = this_cpu_ptr(&rcu_dynticks);
91969 smp_mb__before_atomic(); /* Earlier stuff before QS. */
91970- atomic_add(2, &rdtp->dynticks); /* QS. */
91971+ atomic_add_unchecked(2, &rdtp->dynticks); /* QS. */
91972 smp_mb__after_atomic(); /* Later stuff after QS. */
91973 break;
91974 }
91975@@ -523,9 +523,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
91976 rcu_prepare_for_idle(smp_processor_id());
91977 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
91978 smp_mb__before_atomic(); /* See above. */
91979- atomic_inc(&rdtp->dynticks);
91980+ atomic_inc_unchecked(&rdtp->dynticks);
91981 smp_mb__after_atomic(); /* Force ordering with next sojourn. */
91982- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
91983+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
91984
91985 /*
91986 * It is illegal to enter an extended quiescent state while
91987@@ -643,10 +643,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
91988 int user)
91989 {
91990 smp_mb__before_atomic(); /* Force ordering w/previous sojourn. */
91991- atomic_inc(&rdtp->dynticks);
91992+ atomic_inc_unchecked(&rdtp->dynticks);
91993 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
91994 smp_mb__after_atomic(); /* See above. */
91995- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
91996+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
91997 rcu_cleanup_after_idle(smp_processor_id());
91998 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
91999 if (!user && !is_idle_task(current)) {
92000@@ -767,14 +767,14 @@ void rcu_nmi_enter(void)
92001 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
92002
92003 if (rdtp->dynticks_nmi_nesting == 0 &&
92004- (atomic_read(&rdtp->dynticks) & 0x1))
92005+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
92006 return;
92007 rdtp->dynticks_nmi_nesting++;
92008 smp_mb__before_atomic(); /* Force delay from prior write. */
92009- atomic_inc(&rdtp->dynticks);
92010+ atomic_inc_unchecked(&rdtp->dynticks);
92011 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
92012 smp_mb__after_atomic(); /* See above. */
92013- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
92014+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
92015 }
92016
92017 /**
92018@@ -793,9 +793,9 @@ void rcu_nmi_exit(void)
92019 return;
92020 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
92021 smp_mb__before_atomic(); /* See above. */
92022- atomic_inc(&rdtp->dynticks);
92023+ atomic_inc_unchecked(&rdtp->dynticks);
92024 smp_mb__after_atomic(); /* Force delay to next write. */
92025- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
92026+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
92027 }
92028
92029 /**
92030@@ -808,7 +808,7 @@ void rcu_nmi_exit(void)
92031 */
92032 bool notrace __rcu_is_watching(void)
92033 {
92034- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
92035+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
92036 }
92037
92038 /**
92039@@ -891,7 +891,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
92040 static int dyntick_save_progress_counter(struct rcu_data *rdp,
92041 bool *isidle, unsigned long *maxj)
92042 {
92043- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
92044+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
92045 rcu_sysidle_check_cpu(rdp, isidle, maxj);
92046 if ((rdp->dynticks_snap & 0x1) == 0) {
92047 trace_rcu_fqs(rdp->rsp->name, rdp->gpnum, rdp->cpu, TPS("dti"));
92048@@ -920,7 +920,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
92049 int *rcrmp;
92050 unsigned int snap;
92051
92052- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
92053+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
92054 snap = (unsigned int)rdp->dynticks_snap;
92055
92056 /*
92057@@ -983,10 +983,10 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
92058 rdp->rsp->gp_start + jiffies_till_sched_qs) ||
92059 ULONG_CMP_GE(jiffies, rdp->rsp->jiffies_resched)) {
92060 if (!(ACCESS_ONCE(*rcrmp) & rdp->rsp->flavor_mask)) {
92061- ACCESS_ONCE(rdp->cond_resched_completed) =
92062+ ACCESS_ONCE_RW(rdp->cond_resched_completed) =
92063 ACCESS_ONCE(rdp->mynode->completed);
92064 smp_mb(); /* ->cond_resched_completed before *rcrmp. */
92065- ACCESS_ONCE(*rcrmp) =
92066+ ACCESS_ONCE_RW(*rcrmp) =
92067 ACCESS_ONCE(*rcrmp) + rdp->rsp->flavor_mask;
92068 resched_cpu(rdp->cpu); /* Force CPU into scheduler. */
92069 rdp->rsp->jiffies_resched += 5; /* Enable beating. */
92070@@ -1008,7 +1008,7 @@ static void record_gp_stall_check_time(struct rcu_state *rsp)
92071 rsp->gp_start = j;
92072 smp_wmb(); /* Record start time before stall time. */
92073 j1 = rcu_jiffies_till_stall_check();
92074- ACCESS_ONCE(rsp->jiffies_stall) = j + j1;
92075+ ACCESS_ONCE_RW(rsp->jiffies_stall) = j + j1;
92076 rsp->jiffies_resched = j + j1 / 2;
92077 }
92078
92079@@ -1049,7 +1049,7 @@ static void print_other_cpu_stall(struct rcu_state *rsp)
92080 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92081 return;
92082 }
92083- ACCESS_ONCE(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92084+ ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
92085 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92086
92087 /*
92088@@ -1126,7 +1126,7 @@ static void print_cpu_stall(struct rcu_state *rsp)
92089
92090 raw_spin_lock_irqsave(&rnp->lock, flags);
92091 if (ULONG_CMP_GE(jiffies, ACCESS_ONCE(rsp->jiffies_stall)))
92092- ACCESS_ONCE(rsp->jiffies_stall) = jiffies +
92093+ ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies +
92094 3 * rcu_jiffies_till_stall_check() + 3;
92095 raw_spin_unlock_irqrestore(&rnp->lock, flags);
92096
92097@@ -1210,7 +1210,7 @@ void rcu_cpu_stall_reset(void)
92098 struct rcu_state *rsp;
92099
92100 for_each_rcu_flavor(rsp)
92101- ACCESS_ONCE(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92102+ ACCESS_ONCE_RW(rsp->jiffies_stall) = jiffies + ULONG_MAX / 2;
92103 }
92104
92105 /*
92106@@ -1596,7 +1596,7 @@ static int rcu_gp_init(struct rcu_state *rsp)
92107 raw_spin_unlock_irq(&rnp->lock);
92108 return 0;
92109 }
92110- ACCESS_ONCE(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92111+ ACCESS_ONCE_RW(rsp->gp_flags) = 0; /* Clear all flags: New grace period. */
92112
92113 if (WARN_ON_ONCE(rcu_gp_in_progress(rsp))) {
92114 /*
92115@@ -1637,9 +1637,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
92116 rdp = this_cpu_ptr(rsp->rda);
92117 rcu_preempt_check_blocked_tasks(rnp);
92118 rnp->qsmask = rnp->qsmaskinit;
92119- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
92120+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
92121 WARN_ON_ONCE(rnp->completed != rsp->completed);
92122- ACCESS_ONCE(rnp->completed) = rsp->completed;
92123+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
92124 if (rnp == rdp->mynode)
92125 (void)__note_gp_changes(rsp, rnp, rdp);
92126 rcu_preempt_boost_start_gp(rnp);
92127@@ -1684,7 +1684,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
92128 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
92129 raw_spin_lock_irq(&rnp->lock);
92130 smp_mb__after_unlock_lock();
92131- ACCESS_ONCE(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
92132+ ACCESS_ONCE_RW(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS;
92133 raw_spin_unlock_irq(&rnp->lock);
92134 }
92135 return fqs_state;
92136@@ -1729,7 +1729,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92137 rcu_for_each_node_breadth_first(rsp, rnp) {
92138 raw_spin_lock_irq(&rnp->lock);
92139 smp_mb__after_unlock_lock();
92140- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
92141+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
92142 rdp = this_cpu_ptr(rsp->rda);
92143 if (rnp == rdp->mynode)
92144 needgp = __note_gp_changes(rsp, rnp, rdp) || needgp;
92145@@ -1744,14 +1744,14 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
92146 rcu_nocb_gp_set(rnp, nocb);
92147
92148 /* Declare grace period done. */
92149- ACCESS_ONCE(rsp->completed) = rsp->gpnum;
92150+ ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
92151 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
92152 rsp->fqs_state = RCU_GP_IDLE;
92153 rdp = this_cpu_ptr(rsp->rda);
92154 /* Advance CBs to reduce false positives below. */
92155 needgp = rcu_advance_cbs(rsp, rnp, rdp) || needgp;
92156 if (needgp || cpu_needs_another_gp(rsp, rdp)) {
92157- ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92158+ ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92159 trace_rcu_grace_period(rsp->name,
92160 ACCESS_ONCE(rsp->gpnum),
92161 TPS("newreq"));
92162@@ -1876,7 +1876,7 @@ rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
92163 */
92164 return false;
92165 }
92166- ACCESS_ONCE(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92167+ ACCESS_ONCE_RW(rsp->gp_flags) = RCU_GP_FLAG_INIT;
92168 trace_rcu_grace_period(rsp->name, ACCESS_ONCE(rsp->gpnum),
92169 TPS("newreq"));
92170
92171@@ -2097,7 +2097,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
92172 rsp->qlen += rdp->qlen;
92173 rdp->n_cbs_orphaned += rdp->qlen;
92174 rdp->qlen_lazy = 0;
92175- ACCESS_ONCE(rdp->qlen) = 0;
92176+ ACCESS_ONCE_RW(rdp->qlen) = 0;
92177 }
92178
92179 /*
92180@@ -2344,7 +2344,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
92181 }
92182 smp_mb(); /* List handling before counting for rcu_barrier(). */
92183 rdp->qlen_lazy -= count_lazy;
92184- ACCESS_ONCE(rdp->qlen) = rdp->qlen - count;
92185+ ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen - count;
92186 rdp->n_cbs_invoked += count;
92187
92188 /* Reinstate batch limit if we have worked down the excess. */
92189@@ -2505,7 +2505,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
92190 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
92191 return; /* Someone beat us to it. */
92192 }
92193- ACCESS_ONCE(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
92194+ ACCESS_ONCE_RW(rsp->gp_flags) |= RCU_GP_FLAG_FQS;
92195 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
92196 wake_up(&rsp->gp_wq); /* Memory barrier implied by wake_up() path. */
92197 }
92198@@ -2550,7 +2550,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
92199 /*
92200 * Do RCU core processing for the current CPU.
92201 */
92202-static void rcu_process_callbacks(struct softirq_action *unused)
92203+static void rcu_process_callbacks(void)
92204 {
92205 struct rcu_state *rsp;
92206
92207@@ -2662,7 +2662,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92208 WARN_ON_ONCE((unsigned long)head & 0x1); /* Misaligned rcu_head! */
92209 if (debug_rcu_head_queue(head)) {
92210 /* Probable double call_rcu(), so leak the callback. */
92211- ACCESS_ONCE(head->func) = rcu_leak_callback;
92212+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
92213 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
92214 return;
92215 }
92216@@ -2690,7 +2690,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
92217 local_irq_restore(flags);
92218 return;
92219 }
92220- ACCESS_ONCE(rdp->qlen) = rdp->qlen + 1;
92221+ ACCESS_ONCE_RW(rdp->qlen) = rdp->qlen + 1;
92222 if (lazy)
92223 rdp->qlen_lazy++;
92224 else
92225@@ -2965,11 +2965,11 @@ void synchronize_sched_expedited(void)
92226 * counter wrap on a 32-bit system. Quite a few more CPUs would of
92227 * course be required on a 64-bit system.
92228 */
92229- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
92230+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
92231 (ulong)atomic_long_read(&rsp->expedited_done) +
92232 ULONG_MAX / 8)) {
92233 synchronize_sched();
92234- atomic_long_inc(&rsp->expedited_wrap);
92235+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
92236 return;
92237 }
92238
92239@@ -2977,7 +2977,7 @@ void synchronize_sched_expedited(void)
92240 * Take a ticket. Note that atomic_inc_return() implies a
92241 * full memory barrier.
92242 */
92243- snap = atomic_long_inc_return(&rsp->expedited_start);
92244+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
92245 firstsnap = snap;
92246 get_online_cpus();
92247 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
92248@@ -2990,14 +2990,14 @@ void synchronize_sched_expedited(void)
92249 synchronize_sched_expedited_cpu_stop,
92250 NULL) == -EAGAIN) {
92251 put_online_cpus();
92252- atomic_long_inc(&rsp->expedited_tryfail);
92253+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
92254
92255 /* Check to see if someone else did our work for us. */
92256 s = atomic_long_read(&rsp->expedited_done);
92257 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92258 /* ensure test happens before caller kfree */
92259 smp_mb__before_atomic(); /* ^^^ */
92260- atomic_long_inc(&rsp->expedited_workdone1);
92261+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
92262 return;
92263 }
92264
92265@@ -3006,7 +3006,7 @@ void synchronize_sched_expedited(void)
92266 udelay(trycount * num_online_cpus());
92267 } else {
92268 wait_rcu_gp(call_rcu_sched);
92269- atomic_long_inc(&rsp->expedited_normal);
92270+ atomic_long_inc_unchecked(&rsp->expedited_normal);
92271 return;
92272 }
92273
92274@@ -3015,7 +3015,7 @@ void synchronize_sched_expedited(void)
92275 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
92276 /* ensure test happens before caller kfree */
92277 smp_mb__before_atomic(); /* ^^^ */
92278- atomic_long_inc(&rsp->expedited_workdone2);
92279+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
92280 return;
92281 }
92282
92283@@ -3027,10 +3027,10 @@ void synchronize_sched_expedited(void)
92284 * period works for us.
92285 */
92286 get_online_cpus();
92287- snap = atomic_long_read(&rsp->expedited_start);
92288+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
92289 smp_mb(); /* ensure read is before try_stop_cpus(). */
92290 }
92291- atomic_long_inc(&rsp->expedited_stoppedcpus);
92292+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
92293
92294 /*
92295 * Everyone up to our most recent fetch is covered by our grace
92296@@ -3039,16 +3039,16 @@ void synchronize_sched_expedited(void)
92297 * than we did already did their update.
92298 */
92299 do {
92300- atomic_long_inc(&rsp->expedited_done_tries);
92301+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
92302 s = atomic_long_read(&rsp->expedited_done);
92303 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
92304 /* ensure test happens before caller kfree */
92305 smp_mb__before_atomic(); /* ^^^ */
92306- atomic_long_inc(&rsp->expedited_done_lost);
92307+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
92308 break;
92309 }
92310 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
92311- atomic_long_inc(&rsp->expedited_done_exit);
92312+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
92313
92314 put_online_cpus();
92315 }
92316@@ -3254,7 +3254,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92317 * ACCESS_ONCE() to prevent the compiler from speculating
92318 * the increment to precede the early-exit check.
92319 */
92320- ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92321+ ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92322 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
92323 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
92324 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
92325@@ -3304,7 +3304,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
92326
92327 /* Increment ->n_barrier_done to prevent duplicate work. */
92328 smp_mb(); /* Keep increment after above mechanism. */
92329- ACCESS_ONCE(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92330+ ACCESS_ONCE_RW(rsp->n_barrier_done) = rsp->n_barrier_done + 1;
92331 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
92332 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
92333 smp_mb(); /* Keep increment before caller's subsequent code. */
92334@@ -3349,10 +3349,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
92335 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
92336 init_callback_list(rdp);
92337 rdp->qlen_lazy = 0;
92338- ACCESS_ONCE(rdp->qlen) = 0;
92339+ ACCESS_ONCE_RW(rdp->qlen) = 0;
92340 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
92341 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
92342- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
92343+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
92344 rdp->cpu = cpu;
92345 rdp->rsp = rsp;
92346 rcu_boot_init_nocb_percpu_data(rdp);
92347@@ -3385,8 +3385,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp)
92348 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
92349 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
92350 rcu_sysidle_init_percpu_data(rdp->dynticks);
92351- atomic_set(&rdp->dynticks->dynticks,
92352- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
92353+ atomic_set_unchecked(&rdp->dynticks->dynticks,
92354+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
92355 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
92356
92357 /* Add CPU to rcu_node bitmasks. */
92358diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
92359index 6a86eb7..022b506 100644
92360--- a/kernel/rcu/tree.h
92361+++ b/kernel/rcu/tree.h
92362@@ -87,11 +87,11 @@ struct rcu_dynticks {
92363 long long dynticks_nesting; /* Track irq/process nesting level. */
92364 /* Process level is worth LLONG_MAX/2. */
92365 int dynticks_nmi_nesting; /* Track NMI nesting level. */
92366- atomic_t dynticks; /* Even value for idle, else odd. */
92367+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
92368 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
92369 long long dynticks_idle_nesting;
92370 /* irq/process nesting level from idle. */
92371- atomic_t dynticks_idle; /* Even value for idle, else odd. */
92372+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
92373 /* "Idle" excludes userspace execution. */
92374 unsigned long dynticks_idle_jiffies;
92375 /* End of last non-NMI non-idle period. */
92376@@ -461,17 +461,17 @@ struct rcu_state {
92377 /* _rcu_barrier(). */
92378 /* End of fields guarded by barrier_mutex. */
92379
92380- atomic_long_t expedited_start; /* Starting ticket. */
92381- atomic_long_t expedited_done; /* Done ticket. */
92382- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
92383- atomic_long_t expedited_tryfail; /* # acquisition failures. */
92384- atomic_long_t expedited_workdone1; /* # done by others #1. */
92385- atomic_long_t expedited_workdone2; /* # done by others #2. */
92386- atomic_long_t expedited_normal; /* # fallbacks to normal. */
92387- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
92388- atomic_long_t expedited_done_tries; /* # tries to update _done. */
92389- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
92390- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
92391+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
92392+ atomic_long_t expedited_done; /* Done ticket. */
92393+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
92394+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
92395+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
92396+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
92397+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
92398+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
92399+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
92400+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
92401+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
92402
92403 unsigned long jiffies_force_qs; /* Time at which to invoke */
92404 /* force_quiescent_state(). */
92405diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
92406index a7997e2..9787c9e 100644
92407--- a/kernel/rcu/tree_plugin.h
92408+++ b/kernel/rcu/tree_plugin.h
92409@@ -735,7 +735,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
92410 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
92411 {
92412 return !rcu_preempted_readers_exp(rnp) &&
92413- ACCESS_ONCE(rnp->expmask) == 0;
92414+ ACCESS_ONCE_RW(rnp->expmask) == 0;
92415 }
92416
92417 /*
92418@@ -897,7 +897,7 @@ void synchronize_rcu_expedited(void)
92419
92420 /* Clean up and exit. */
92421 smp_mb(); /* ensure expedited GP seen before counter increment. */
92422- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
92423+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
92424 unlock_mb_ret:
92425 mutex_unlock(&sync_rcu_preempt_exp_mutex);
92426 mb_ret:
92427@@ -1452,7 +1452,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
92428 free_cpumask_var(cm);
92429 }
92430
92431-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
92432+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
92433 .store = &rcu_cpu_kthread_task,
92434 .thread_should_run = rcu_cpu_kthread_should_run,
92435 .thread_fn = rcu_cpu_kthread,
92436@@ -1932,7 +1932,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
92437 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
92438 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
92439 cpu, ticks_value, ticks_title,
92440- atomic_read(&rdtp->dynticks) & 0xfff,
92441+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
92442 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
92443 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
92444 fast_no_hz);
92445@@ -2076,7 +2076,7 @@ static void wake_nocb_leader(struct rcu_data *rdp, bool force)
92446 return;
92447 if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) {
92448 /* Prior xchg orders against prior callback enqueue. */
92449- ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false;
92450+ ACCESS_ONCE_RW(rdp_leader->nocb_leader_sleep) = false;
92451 wake_up(&rdp_leader->nocb_wq);
92452 }
92453 }
92454@@ -2101,7 +2101,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
92455
92456 /* Enqueue the callback on the nocb list and update counts. */
92457 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
92458- ACCESS_ONCE(*old_rhpp) = rhp;
92459+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
92460 atomic_long_add(rhcount, &rdp->nocb_q_count);
92461 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
92462
92463@@ -2272,7 +2272,7 @@ wait_again:
92464 continue; /* No CBs here, try next follower. */
92465
92466 /* Move callbacks to wait-for-GP list, which is empty. */
92467- ACCESS_ONCE(rdp->nocb_head) = NULL;
92468+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
92469 rdp->nocb_gp_tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
92470 rdp->nocb_gp_count = atomic_long_xchg(&rdp->nocb_q_count, 0);
92471 rdp->nocb_gp_count_lazy =
92472@@ -2398,7 +2398,7 @@ static int rcu_nocb_kthread(void *arg)
92473 list = ACCESS_ONCE(rdp->nocb_follower_head);
92474 BUG_ON(!list);
92475 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "WokeNonEmpty");
92476- ACCESS_ONCE(rdp->nocb_follower_head) = NULL;
92477+ ACCESS_ONCE_RW(rdp->nocb_follower_head) = NULL;
92478 tail = xchg(&rdp->nocb_follower_tail, &rdp->nocb_follower_head);
92479 c = atomic_long_xchg(&rdp->nocb_follower_count, 0);
92480 cl = atomic_long_xchg(&rdp->nocb_follower_count_lazy, 0);
92481@@ -2428,8 +2428,8 @@ static int rcu_nocb_kthread(void *arg)
92482 list = next;
92483 }
92484 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
92485- ACCESS_ONCE(rdp->nocb_p_count) -= c;
92486- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
92487+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
92488+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
92489 rdp->n_nocbs_invoked += c;
92490 }
92491 return 0;
92492@@ -2446,7 +2446,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
92493 {
92494 if (!rcu_nocb_need_deferred_wakeup(rdp))
92495 return;
92496- ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
92497+ ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
92498 wake_nocb_leader(rdp, false);
92499 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
92500 }
92501@@ -2510,7 +2510,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
92502 t = kthread_run(rcu_nocb_kthread, rdp,
92503 "rcuo%c/%d", rsp->abbr, cpu);
92504 BUG_ON(IS_ERR(t));
92505- ACCESS_ONCE(rdp->nocb_kthread) = t;
92506+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
92507 }
92508 }
92509
92510@@ -2641,11 +2641,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
92511
92512 /* Record start of fully idle period. */
92513 j = jiffies;
92514- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
92515+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
92516 smp_mb__before_atomic();
92517- atomic_inc(&rdtp->dynticks_idle);
92518+ atomic_inc_unchecked(&rdtp->dynticks_idle);
92519 smp_mb__after_atomic();
92520- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
92521+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
92522 }
92523
92524 /*
92525@@ -2710,9 +2710,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
92526
92527 /* Record end of idle period. */
92528 smp_mb__before_atomic();
92529- atomic_inc(&rdtp->dynticks_idle);
92530+ atomic_inc_unchecked(&rdtp->dynticks_idle);
92531 smp_mb__after_atomic();
92532- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
92533+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
92534
92535 /*
92536 * If we are the timekeeping CPU, we are permitted to be non-idle
92537@@ -2753,7 +2753,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
92538 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
92539
92540 /* Pick up current idle and NMI-nesting counter and check. */
92541- cur = atomic_read(&rdtp->dynticks_idle);
92542+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
92543 if (cur & 0x1) {
92544 *isidle = false; /* We are not idle! */
92545 return;
92546@@ -2802,7 +2802,7 @@ static void rcu_sysidle(unsigned long j)
92547 case RCU_SYSIDLE_NOT:
92548
92549 /* First time all are idle, so note a short idle period. */
92550- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92551+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
92552 break;
92553
92554 case RCU_SYSIDLE_SHORT:
92555@@ -2840,7 +2840,7 @@ static void rcu_sysidle_cancel(void)
92556 {
92557 smp_mb();
92558 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
92559- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
92560+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
92561 }
92562
92563 /*
92564@@ -2888,7 +2888,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
92565 smp_mb(); /* grace period precedes setting inuse. */
92566
92567 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
92568- ACCESS_ONCE(rshp->inuse) = 0;
92569+ ACCESS_ONCE_RW(rshp->inuse) = 0;
92570 }
92571
92572 /*
92573diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
92574index 5cdc62e..cc52e88 100644
92575--- a/kernel/rcu/tree_trace.c
92576+++ b/kernel/rcu/tree_trace.c
92577@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
92578 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
92579 rdp->passed_quiesce, rdp->qs_pending);
92580 seq_printf(m, " dt=%d/%llx/%d df=%lu",
92581- atomic_read(&rdp->dynticks->dynticks),
92582+ atomic_read_unchecked(&rdp->dynticks->dynticks),
92583 rdp->dynticks->dynticks_nesting,
92584 rdp->dynticks->dynticks_nmi_nesting,
92585 rdp->dynticks_fqs);
92586@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
92587 struct rcu_state *rsp = (struct rcu_state *)m->private;
92588
92589 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",
92590- atomic_long_read(&rsp->expedited_start),
92591+ atomic_long_read_unchecked(&rsp->expedited_start),
92592 atomic_long_read(&rsp->expedited_done),
92593- atomic_long_read(&rsp->expedited_wrap),
92594- atomic_long_read(&rsp->expedited_tryfail),
92595- atomic_long_read(&rsp->expedited_workdone1),
92596- atomic_long_read(&rsp->expedited_workdone2),
92597- atomic_long_read(&rsp->expedited_normal),
92598- atomic_long_read(&rsp->expedited_stoppedcpus),
92599- atomic_long_read(&rsp->expedited_done_tries),
92600- atomic_long_read(&rsp->expedited_done_lost),
92601- atomic_long_read(&rsp->expedited_done_exit));
92602+ atomic_long_read_unchecked(&rsp->expedited_wrap),
92603+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
92604+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
92605+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
92606+ atomic_long_read_unchecked(&rsp->expedited_normal),
92607+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
92608+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
92609+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
92610+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
92611 return 0;
92612 }
92613
92614diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
92615index 4056d79..c11741a 100644
92616--- a/kernel/rcu/update.c
92617+++ b/kernel/rcu/update.c
92618@@ -308,10 +308,10 @@ int rcu_jiffies_till_stall_check(void)
92619 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
92620 */
92621 if (till_stall_check < 3) {
92622- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
92623+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
92624 till_stall_check = 3;
92625 } else if (till_stall_check > 300) {
92626- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
92627+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
92628 till_stall_check = 300;
92629 }
92630 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
92631diff --git a/kernel/resource.c b/kernel/resource.c
92632index 60c5a38..ed77193 100644
92633--- a/kernel/resource.c
92634+++ b/kernel/resource.c
92635@@ -161,8 +161,18 @@ static const struct file_operations proc_iomem_operations = {
92636
92637 static int __init ioresources_init(void)
92638 {
92639+#ifdef CONFIG_GRKERNSEC_PROC_ADD
92640+#ifdef CONFIG_GRKERNSEC_PROC_USER
92641+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
92642+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
92643+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
92644+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
92645+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
92646+#endif
92647+#else
92648 proc_create("ioports", 0, NULL, &proc_ioports_operations);
92649 proc_create("iomem", 0, NULL, &proc_iomem_operations);
92650+#endif
92651 return 0;
92652 }
92653 __initcall(ioresources_init);
92654diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
92655index e73efba..c9bfbd4 100644
92656--- a/kernel/sched/auto_group.c
92657+++ b/kernel/sched/auto_group.c
92658@@ -11,7 +11,7 @@
92659
92660 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
92661 static struct autogroup autogroup_default;
92662-static atomic_t autogroup_seq_nr;
92663+static atomic_unchecked_t autogroup_seq_nr;
92664
92665 void __init autogroup_init(struct task_struct *init_task)
92666 {
92667@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
92668
92669 kref_init(&ag->kref);
92670 init_rwsem(&ag->lock);
92671- ag->id = atomic_inc_return(&autogroup_seq_nr);
92672+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
92673 ag->tg = tg;
92674 #ifdef CONFIG_RT_GROUP_SCHED
92675 /*
92676diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
92677index a63f4dc..349bbb0 100644
92678--- a/kernel/sched/completion.c
92679+++ b/kernel/sched/completion.c
92680@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
92681 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92682 * or number of jiffies left till timeout) if completed.
92683 */
92684-long __sched
92685+long __sched __intentional_overflow(-1)
92686 wait_for_completion_interruptible_timeout(struct completion *x,
92687 unsigned long timeout)
92688 {
92689@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
92690 *
92691 * Return: -ERESTARTSYS if interrupted, 0 if completed.
92692 */
92693-int __sched wait_for_completion_killable(struct completion *x)
92694+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
92695 {
92696 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
92697 if (t == -ERESTARTSYS)
92698@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
92699 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
92700 * or number of jiffies left till timeout) if completed.
92701 */
92702-long __sched
92703+long __sched __intentional_overflow(-1)
92704 wait_for_completion_killable_timeout(struct completion *x,
92705 unsigned long timeout)
92706 {
92707diff --git a/kernel/sched/core.c b/kernel/sched/core.c
92708index 6d7cb91..420f2d2 100644
92709--- a/kernel/sched/core.c
92710+++ b/kernel/sched/core.c
92711@@ -1857,7 +1857,7 @@ void set_numabalancing_state(bool enabled)
92712 int sysctl_numa_balancing(struct ctl_table *table, int write,
92713 void __user *buffer, size_t *lenp, loff_t *ppos)
92714 {
92715- struct ctl_table t;
92716+ ctl_table_no_const t;
92717 int err;
92718 int state = numabalancing_enabled;
92719
92720@@ -2324,8 +2324,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
92721 next->active_mm = oldmm;
92722 atomic_inc(&oldmm->mm_count);
92723 enter_lazy_tlb(oldmm, next);
92724- } else
92725+ } else {
92726 switch_mm(oldmm, mm, next);
92727+ populate_stack();
92728+ }
92729
92730 if (!prev->mm) {
92731 prev->active_mm = NULL;
92732@@ -3107,6 +3109,8 @@ int can_nice(const struct task_struct *p, const int nice)
92733 /* convert nice value [19,-20] to rlimit style value [1,40] */
92734 int nice_rlim = nice_to_rlimit(nice);
92735
92736+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
92737+
92738 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
92739 capable(CAP_SYS_NICE));
92740 }
92741@@ -3133,7 +3137,8 @@ SYSCALL_DEFINE1(nice, int, increment)
92742 nice = task_nice(current) + increment;
92743
92744 nice = clamp_val(nice, MIN_NICE, MAX_NICE);
92745- if (increment < 0 && !can_nice(current, nice))
92746+ if (increment < 0 && (!can_nice(current, nice) ||
92747+ gr_handle_chroot_nice()))
92748 return -EPERM;
92749
92750 retval = security_task_setnice(current, nice);
92751@@ -3412,6 +3417,7 @@ recheck:
92752 if (policy != p->policy && !rlim_rtprio)
92753 return -EPERM;
92754
92755+ gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
92756 /* can't increase priority */
92757 if (attr->sched_priority > p->rt_priority &&
92758 attr->sched_priority > rlim_rtprio)
92759@@ -4802,6 +4808,7 @@ void idle_task_exit(void)
92760
92761 if (mm != &init_mm) {
92762 switch_mm(mm, &init_mm, current);
92763+ populate_stack();
92764 finish_arch_post_lock_switch();
92765 }
92766 mmdrop(mm);
92767@@ -4897,7 +4904,7 @@ static void migrate_tasks(unsigned int dead_cpu)
92768
92769 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
92770
92771-static struct ctl_table sd_ctl_dir[] = {
92772+static ctl_table_no_const sd_ctl_dir[] __read_only = {
92773 {
92774 .procname = "sched_domain",
92775 .mode = 0555,
92776@@ -4914,17 +4921,17 @@ static struct ctl_table sd_ctl_root[] = {
92777 {}
92778 };
92779
92780-static struct ctl_table *sd_alloc_ctl_entry(int n)
92781+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
92782 {
92783- struct ctl_table *entry =
92784+ ctl_table_no_const *entry =
92785 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
92786
92787 return entry;
92788 }
92789
92790-static void sd_free_ctl_entry(struct ctl_table **tablep)
92791+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
92792 {
92793- struct ctl_table *entry;
92794+ ctl_table_no_const *entry;
92795
92796 /*
92797 * In the intermediate directories, both the child directory and
92798@@ -4932,22 +4939,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
92799 * will always be set. In the lowest directory the names are
92800 * static strings and all have proc handlers.
92801 */
92802- for (entry = *tablep; entry->mode; entry++) {
92803- if (entry->child)
92804- sd_free_ctl_entry(&entry->child);
92805+ for (entry = tablep; entry->mode; entry++) {
92806+ if (entry->child) {
92807+ sd_free_ctl_entry(entry->child);
92808+ pax_open_kernel();
92809+ entry->child = NULL;
92810+ pax_close_kernel();
92811+ }
92812 if (entry->proc_handler == NULL)
92813 kfree(entry->procname);
92814 }
92815
92816- kfree(*tablep);
92817- *tablep = NULL;
92818+ kfree(tablep);
92819 }
92820
92821 static int min_load_idx = 0;
92822 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
92823
92824 static void
92825-set_table_entry(struct ctl_table *entry,
92826+set_table_entry(ctl_table_no_const *entry,
92827 const char *procname, void *data, int maxlen,
92828 umode_t mode, proc_handler *proc_handler,
92829 bool load_idx)
92830@@ -4967,7 +4977,7 @@ set_table_entry(struct ctl_table *entry,
92831 static struct ctl_table *
92832 sd_alloc_ctl_domain_table(struct sched_domain *sd)
92833 {
92834- struct ctl_table *table = sd_alloc_ctl_entry(14);
92835+ ctl_table_no_const *table = sd_alloc_ctl_entry(14);
92836
92837 if (table == NULL)
92838 return NULL;
92839@@ -5005,9 +5015,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
92840 return table;
92841 }
92842
92843-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
92844+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
92845 {
92846- struct ctl_table *entry, *table;
92847+ ctl_table_no_const *entry, *table;
92848 struct sched_domain *sd;
92849 int domain_num = 0, i;
92850 char buf[32];
92851@@ -5034,11 +5044,13 @@ static struct ctl_table_header *sd_sysctl_header;
92852 static void register_sched_domain_sysctl(void)
92853 {
92854 int i, cpu_num = num_possible_cpus();
92855- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
92856+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
92857 char buf[32];
92858
92859 WARN_ON(sd_ctl_dir[0].child);
92860+ pax_open_kernel();
92861 sd_ctl_dir[0].child = entry;
92862+ pax_close_kernel();
92863
92864 if (entry == NULL)
92865 return;
92866@@ -5061,8 +5073,12 @@ static void unregister_sched_domain_sysctl(void)
92867 if (sd_sysctl_header)
92868 unregister_sysctl_table(sd_sysctl_header);
92869 sd_sysctl_header = NULL;
92870- if (sd_ctl_dir[0].child)
92871- sd_free_ctl_entry(&sd_ctl_dir[0].child);
92872+ if (sd_ctl_dir[0].child) {
92873+ sd_free_ctl_entry(sd_ctl_dir[0].child);
92874+ pax_open_kernel();
92875+ sd_ctl_dir[0].child = NULL;
92876+ pax_close_kernel();
92877+ }
92878 }
92879 #else
92880 static void register_sched_domain_sysctl(void)
92881diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
92882index bfa3c86..e58767c 100644
92883--- a/kernel/sched/fair.c
92884+++ b/kernel/sched/fair.c
92885@@ -1873,7 +1873,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
92886
92887 static void reset_ptenuma_scan(struct task_struct *p)
92888 {
92889- ACCESS_ONCE(p->mm->numa_scan_seq)++;
92890+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
92891 p->mm->numa_scan_offset = 0;
92892 }
92893
92894@@ -7339,7 +7339,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
92895 * run_rebalance_domains is triggered when needed from the scheduler tick.
92896 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
92897 */
92898-static void run_rebalance_domains(struct softirq_action *h)
92899+static __latent_entropy void run_rebalance_domains(void)
92900 {
92901 struct rq *this_rq = this_rq();
92902 enum cpu_idle_type idle = this_rq->idle_balance ?
92903diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
92904index 579712f..a338a9d 100644
92905--- a/kernel/sched/sched.h
92906+++ b/kernel/sched/sched.h
92907@@ -1146,7 +1146,7 @@ struct sched_class {
92908 #ifdef CONFIG_FAIR_GROUP_SCHED
92909 void (*task_move_group) (struct task_struct *p, int on_rq);
92910 #endif
92911-};
92912+} __do_const;
92913
92914 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
92915 {
92916diff --git a/kernel/seccomp.c b/kernel/seccomp.c
92917index 44eb005..84922be 100644
92918--- a/kernel/seccomp.c
92919+++ b/kernel/seccomp.c
92920@@ -395,16 +395,15 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
92921 if (!filter)
92922 goto free_prog;
92923
92924- filter->prog = kzalloc(bpf_prog_size(new_len),
92925- GFP_KERNEL|__GFP_NOWARN);
92926+ filter->prog = bpf_prog_alloc(bpf_prog_size(new_len), __GFP_NOWARN);
92927 if (!filter->prog)
92928 goto free_filter;
92929
92930 ret = bpf_convert_filter(fp, fprog->len, filter->prog->insnsi, &new_len);
92931 if (ret)
92932 goto free_filter_prog;
92933- kfree(fp);
92934
92935+ kfree(fp);
92936 atomic_set(&filter->usage, 1);
92937 filter->prog->len = new_len;
92938
92939@@ -413,7 +412,7 @@ static struct seccomp_filter *seccomp_prepare_filter(struct sock_fprog *fprog)
92940 return filter;
92941
92942 free_filter_prog:
92943- kfree(filter->prog);
92944+ __bpf_prog_free(filter->prog);
92945 free_filter:
92946 kfree(filter);
92947 free_prog:
92948diff --git a/kernel/signal.c b/kernel/signal.c
92949index 8f0876f..1153a5a 100644
92950--- a/kernel/signal.c
92951+++ b/kernel/signal.c
92952@@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
92953
92954 int print_fatal_signals __read_mostly;
92955
92956-static void __user *sig_handler(struct task_struct *t, int sig)
92957+static __sighandler_t sig_handler(struct task_struct *t, int sig)
92958 {
92959 return t->sighand->action[sig - 1].sa.sa_handler;
92960 }
92961
92962-static int sig_handler_ignored(void __user *handler, int sig)
92963+static int sig_handler_ignored(__sighandler_t handler, int sig)
92964 {
92965 /* Is it explicitly or implicitly ignored? */
92966 return handler == SIG_IGN ||
92967@@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
92968
92969 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
92970 {
92971- void __user *handler;
92972+ __sighandler_t handler;
92973
92974 handler = sig_handler(t, sig);
92975
92976@@ -372,6 +372,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
92977 atomic_inc(&user->sigpending);
92978 rcu_read_unlock();
92979
92980+ if (!override_rlimit)
92981+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
92982+
92983 if (override_rlimit ||
92984 atomic_read(&user->sigpending) <=
92985 task_rlimit(t, RLIMIT_SIGPENDING)) {
92986@@ -499,7 +502,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
92987
92988 int unhandled_signal(struct task_struct *tsk, int sig)
92989 {
92990- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
92991+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
92992 if (is_global_init(tsk))
92993 return 1;
92994 if (handler != SIG_IGN && handler != SIG_DFL)
92995@@ -793,6 +796,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
92996 }
92997 }
92998
92999+ /* allow glibc communication via tgkill to other threads in our
93000+ thread group */
93001+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
93002+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
93003+ && gr_handle_signal(t, sig))
93004+ return -EPERM;
93005+
93006 return security_task_kill(t, info, sig, 0);
93007 }
93008
93009@@ -1176,7 +1186,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
93010 return send_signal(sig, info, p, 1);
93011 }
93012
93013-static int
93014+int
93015 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93016 {
93017 return send_signal(sig, info, t, 0);
93018@@ -1213,6 +1223,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93019 unsigned long int flags;
93020 int ret, blocked, ignored;
93021 struct k_sigaction *action;
93022+ int is_unhandled = 0;
93023
93024 spin_lock_irqsave(&t->sighand->siglock, flags);
93025 action = &t->sighand->action[sig-1];
93026@@ -1227,9 +1238,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
93027 }
93028 if (action->sa.sa_handler == SIG_DFL)
93029 t->signal->flags &= ~SIGNAL_UNKILLABLE;
93030+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
93031+ is_unhandled = 1;
93032 ret = specific_send_sig_info(sig, info, t);
93033 spin_unlock_irqrestore(&t->sighand->siglock, flags);
93034
93035+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
93036+ normal operation */
93037+ if (is_unhandled) {
93038+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
93039+ gr_handle_crash(t, sig);
93040+ }
93041+
93042 return ret;
93043 }
93044
93045@@ -1300,8 +1320,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
93046 ret = check_kill_permission(sig, info, p);
93047 rcu_read_unlock();
93048
93049- if (!ret && sig)
93050+ if (!ret && sig) {
93051 ret = do_send_sig_info(sig, info, p, true);
93052+ if (!ret)
93053+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
93054+ }
93055
93056 return ret;
93057 }
93058@@ -2903,7 +2926,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
93059 int error = -ESRCH;
93060
93061 rcu_read_lock();
93062- p = find_task_by_vpid(pid);
93063+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
93064+ /* allow glibc communication via tgkill to other threads in our
93065+ thread group */
93066+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
93067+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
93068+ p = find_task_by_vpid_unrestricted(pid);
93069+ else
93070+#endif
93071+ p = find_task_by_vpid(pid);
93072 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
93073 error = check_kill_permission(sig, info, p);
93074 /*
93075@@ -3236,8 +3267,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
93076 }
93077 seg = get_fs();
93078 set_fs(KERNEL_DS);
93079- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
93080- (stack_t __force __user *) &uoss,
93081+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
93082+ (stack_t __force_user *) &uoss,
93083 compat_user_stack_pointer());
93084 set_fs(seg);
93085 if (ret >= 0 && uoss_ptr) {
93086diff --git a/kernel/smpboot.c b/kernel/smpboot.c
93087index eb89e18..a4e6792 100644
93088--- a/kernel/smpboot.c
93089+++ b/kernel/smpboot.c
93090@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
93091 }
93092 smpboot_unpark_thread(plug_thread, cpu);
93093 }
93094- list_add(&plug_thread->list, &hotplug_threads);
93095+ pax_list_add(&plug_thread->list, &hotplug_threads);
93096 out:
93097 mutex_unlock(&smpboot_threads_lock);
93098 return ret;
93099@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
93100 {
93101 get_online_cpus();
93102 mutex_lock(&smpboot_threads_lock);
93103- list_del(&plug_thread->list);
93104+ pax_list_del(&plug_thread->list);
93105 smpboot_destroy_threads(plug_thread);
93106 mutex_unlock(&smpboot_threads_lock);
93107 put_online_cpus();
93108diff --git a/kernel/softirq.c b/kernel/softirq.c
93109index 5918d22..e95d1926 100644
93110--- a/kernel/softirq.c
93111+++ b/kernel/softirq.c
93112@@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
93113 EXPORT_SYMBOL(irq_stat);
93114 #endif
93115
93116-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
93117+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
93118
93119 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
93120
93121@@ -266,7 +266,7 @@ restart:
93122 kstat_incr_softirqs_this_cpu(vec_nr);
93123
93124 trace_softirq_entry(vec_nr);
93125- h->action(h);
93126+ h->action();
93127 trace_softirq_exit(vec_nr);
93128 if (unlikely(prev_count != preempt_count())) {
93129 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
93130@@ -426,7 +426,7 @@ void __raise_softirq_irqoff(unsigned int nr)
93131 or_softirq_pending(1UL << nr);
93132 }
93133
93134-void open_softirq(int nr, void (*action)(struct softirq_action *))
93135+void __init open_softirq(int nr, void (*action)(void))
93136 {
93137 softirq_vec[nr].action = action;
93138 }
93139@@ -478,7 +478,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
93140 }
93141 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
93142
93143-static void tasklet_action(struct softirq_action *a)
93144+static void tasklet_action(void)
93145 {
93146 struct tasklet_struct *list;
93147
93148@@ -514,7 +514,7 @@ static void tasklet_action(struct softirq_action *a)
93149 }
93150 }
93151
93152-static void tasklet_hi_action(struct softirq_action *a)
93153+static __latent_entropy void tasklet_hi_action(void)
93154 {
93155 struct tasklet_struct *list;
93156
93157@@ -741,7 +741,7 @@ static struct notifier_block cpu_nfb = {
93158 .notifier_call = cpu_callback
93159 };
93160
93161-static struct smp_hotplug_thread softirq_threads = {
93162+static struct smp_hotplug_thread softirq_threads __read_only = {
93163 .store = &ksoftirqd,
93164 .thread_should_run = ksoftirqd_should_run,
93165 .thread_fn = run_ksoftirqd,
93166diff --git a/kernel/sys.c b/kernel/sys.c
93167index ce81291..df2ca85 100644
93168--- a/kernel/sys.c
93169+++ b/kernel/sys.c
93170@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
93171 error = -EACCES;
93172 goto out;
93173 }
93174+
93175+ if (gr_handle_chroot_setpriority(p, niceval)) {
93176+ error = -EACCES;
93177+ goto out;
93178+ }
93179+
93180 no_nice = security_task_setnice(p, niceval);
93181 if (no_nice) {
93182 error = no_nice;
93183@@ -351,6 +357,20 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
93184 goto error;
93185 }
93186
93187+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
93188+ goto error;
93189+
93190+ if (!gid_eq(new->gid, old->gid)) {
93191+ /* make sure we generate a learn log for what will
93192+ end up being a role transition after a full-learning
93193+ policy is generated
93194+ CAP_SETGID is required to perform a transition
93195+ we may not log a CAP_SETGID check above, e.g.
93196+ in the case where new rgid = old egid
93197+ */
93198+ gr_learn_cap(current, new, CAP_SETGID);
93199+ }
93200+
93201 if (rgid != (gid_t) -1 ||
93202 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
93203 new->sgid = new->egid;
93204@@ -386,6 +406,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
93205 old = current_cred();
93206
93207 retval = -EPERM;
93208+
93209+ if (gr_check_group_change(kgid, kgid, kgid))
93210+ goto error;
93211+
93212 if (ns_capable(old->user_ns, CAP_SETGID))
93213 new->gid = new->egid = new->sgid = new->fsgid = kgid;
93214 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
93215@@ -403,7 +427,7 @@ error:
93216 /*
93217 * change the user struct in a credentials set to match the new UID
93218 */
93219-static int set_user(struct cred *new)
93220+int set_user(struct cred *new)
93221 {
93222 struct user_struct *new_user;
93223
93224@@ -483,7 +507,18 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
93225 goto error;
93226 }
93227
93228+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
93229+ goto error;
93230+
93231 if (!uid_eq(new->uid, old->uid)) {
93232+ /* make sure we generate a learn log for what will
93233+ end up being a role transition after a full-learning
93234+ policy is generated
93235+ CAP_SETUID is required to perform a transition
93236+ we may not log a CAP_SETUID check above, e.g.
93237+ in the case where new ruid = old euid
93238+ */
93239+ gr_learn_cap(current, new, CAP_SETUID);
93240 retval = set_user(new);
93241 if (retval < 0)
93242 goto error;
93243@@ -533,6 +568,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
93244 old = current_cred();
93245
93246 retval = -EPERM;
93247+
93248+ if (gr_check_crash_uid(kuid))
93249+ goto error;
93250+ if (gr_check_user_change(kuid, kuid, kuid))
93251+ goto error;
93252+
93253 if (ns_capable(old->user_ns, CAP_SETUID)) {
93254 new->suid = new->uid = kuid;
93255 if (!uid_eq(kuid, old->uid)) {
93256@@ -602,6 +643,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
93257 goto error;
93258 }
93259
93260+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
93261+ goto error;
93262+
93263 if (ruid != (uid_t) -1) {
93264 new->uid = kruid;
93265 if (!uid_eq(kruid, old->uid)) {
93266@@ -684,6 +728,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
93267 goto error;
93268 }
93269
93270+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
93271+ goto error;
93272+
93273 if (rgid != (gid_t) -1)
93274 new->gid = krgid;
93275 if (egid != (gid_t) -1)
93276@@ -745,12 +792,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
93277 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
93278 ns_capable(old->user_ns, CAP_SETUID)) {
93279 if (!uid_eq(kuid, old->fsuid)) {
93280+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
93281+ goto error;
93282+
93283 new->fsuid = kuid;
93284 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
93285 goto change_okay;
93286 }
93287 }
93288
93289+error:
93290 abort_creds(new);
93291 return old_fsuid;
93292
93293@@ -783,12 +834,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
93294 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
93295 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
93296 ns_capable(old->user_ns, CAP_SETGID)) {
93297+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
93298+ goto error;
93299+
93300 if (!gid_eq(kgid, old->fsgid)) {
93301 new->fsgid = kgid;
93302 goto change_okay;
93303 }
93304 }
93305
93306+error:
93307 abort_creds(new);
93308 return old_fsgid;
93309
93310@@ -1167,19 +1222,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
93311 return -EFAULT;
93312
93313 down_read(&uts_sem);
93314- error = __copy_to_user(&name->sysname, &utsname()->sysname,
93315+ error = __copy_to_user(name->sysname, &utsname()->sysname,
93316 __OLD_UTS_LEN);
93317 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
93318- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
93319+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
93320 __OLD_UTS_LEN);
93321 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
93322- error |= __copy_to_user(&name->release, &utsname()->release,
93323+ error |= __copy_to_user(name->release, &utsname()->release,
93324 __OLD_UTS_LEN);
93325 error |= __put_user(0, name->release + __OLD_UTS_LEN);
93326- error |= __copy_to_user(&name->version, &utsname()->version,
93327+ error |= __copy_to_user(name->version, &utsname()->version,
93328 __OLD_UTS_LEN);
93329 error |= __put_user(0, name->version + __OLD_UTS_LEN);
93330- error |= __copy_to_user(&name->machine, &utsname()->machine,
93331+ error |= __copy_to_user(name->machine, &utsname()->machine,
93332 __OLD_UTS_LEN);
93333 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
93334 up_read(&uts_sem);
93335@@ -1381,6 +1436,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
93336 */
93337 new_rlim->rlim_cur = 1;
93338 }
93339+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
93340+ is changed to a lower value. Since tasks can be created by the same
93341+ user in between this limit change and an execve by this task, force
93342+ a recheck only for this task by setting PF_NPROC_EXCEEDED
93343+ */
93344+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
93345+ tsk->flags |= PF_NPROC_EXCEEDED;
93346 }
93347 if (!retval) {
93348 if (old_rlim)
93349diff --git a/kernel/sysctl.c b/kernel/sysctl.c
93350index 75875a7..cd8e838 100644
93351--- a/kernel/sysctl.c
93352+++ b/kernel/sysctl.c
93353@@ -94,7 +94,6 @@
93354
93355
93356 #if defined(CONFIG_SYSCTL)
93357-
93358 /* External variables not in a header file. */
93359 extern int max_threads;
93360 extern int suid_dumpable;
93361@@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
93362
93363 /* Constants used for minimum and maximum */
93364 #ifdef CONFIG_LOCKUP_DETECTOR
93365-static int sixty = 60;
93366+static int sixty __read_only = 60;
93367 #endif
93368
93369-static int __maybe_unused neg_one = -1;
93370+static int __maybe_unused neg_one __read_only = -1;
93371
93372-static int zero;
93373-static int __maybe_unused one = 1;
93374-static int __maybe_unused two = 2;
93375-static int __maybe_unused four = 4;
93376-static unsigned long one_ul = 1;
93377-static int one_hundred = 100;
93378+static int zero __read_only = 0;
93379+static int __maybe_unused one __read_only = 1;
93380+static int __maybe_unused two __read_only = 2;
93381+static int __maybe_unused three __read_only = 3;
93382+static int __maybe_unused four __read_only = 4;
93383+static unsigned long one_ul __read_only = 1;
93384+static int one_hundred __read_only = 100;
93385 #ifdef CONFIG_PRINTK
93386-static int ten_thousand = 10000;
93387+static int ten_thousand __read_only = 10000;
93388 #endif
93389
93390 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
93391@@ -181,10 +181,8 @@ static int proc_taint(struct ctl_table *table, int write,
93392 void __user *buffer, size_t *lenp, loff_t *ppos);
93393 #endif
93394
93395-#ifdef CONFIG_PRINTK
93396 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93397 void __user *buffer, size_t *lenp, loff_t *ppos);
93398-#endif
93399
93400 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
93401 void __user *buffer, size_t *lenp, loff_t *ppos);
93402@@ -215,6 +213,8 @@ static int sysrq_sysctl_handler(struct ctl_table *table, int write,
93403
93404 #endif
93405
93406+extern struct ctl_table grsecurity_table[];
93407+
93408 static struct ctl_table kern_table[];
93409 static struct ctl_table vm_table[];
93410 static struct ctl_table fs_table[];
93411@@ -229,6 +229,20 @@ extern struct ctl_table epoll_table[];
93412 int sysctl_legacy_va_layout;
93413 #endif
93414
93415+#ifdef CONFIG_PAX_SOFTMODE
93416+static struct ctl_table pax_table[] = {
93417+ {
93418+ .procname = "softmode",
93419+ .data = &pax_softmode,
93420+ .maxlen = sizeof(unsigned int),
93421+ .mode = 0600,
93422+ .proc_handler = &proc_dointvec,
93423+ },
93424+
93425+ { }
93426+};
93427+#endif
93428+
93429 /* The default sysctl tables: */
93430
93431 static struct ctl_table sysctl_base_table[] = {
93432@@ -277,6 +291,22 @@ static int max_extfrag_threshold = 1000;
93433 #endif
93434
93435 static struct ctl_table kern_table[] = {
93436+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
93437+ {
93438+ .procname = "grsecurity",
93439+ .mode = 0500,
93440+ .child = grsecurity_table,
93441+ },
93442+#endif
93443+
93444+#ifdef CONFIG_PAX_SOFTMODE
93445+ {
93446+ .procname = "pax",
93447+ .mode = 0500,
93448+ .child = pax_table,
93449+ },
93450+#endif
93451+
93452 {
93453 .procname = "sched_child_runs_first",
93454 .data = &sysctl_sched_child_runs_first,
93455@@ -641,7 +671,7 @@ static struct ctl_table kern_table[] = {
93456 .data = &modprobe_path,
93457 .maxlen = KMOD_PATH_LEN,
93458 .mode = 0644,
93459- .proc_handler = proc_dostring,
93460+ .proc_handler = proc_dostring_modpriv,
93461 },
93462 {
93463 .procname = "modules_disabled",
93464@@ -808,16 +838,20 @@ static struct ctl_table kern_table[] = {
93465 .extra1 = &zero,
93466 .extra2 = &one,
93467 },
93468+#endif
93469 {
93470 .procname = "kptr_restrict",
93471 .data = &kptr_restrict,
93472 .maxlen = sizeof(int),
93473 .mode = 0644,
93474 .proc_handler = proc_dointvec_minmax_sysadmin,
93475+#ifdef CONFIG_GRKERNSEC_HIDESYM
93476+ .extra1 = &two,
93477+#else
93478 .extra1 = &zero,
93479+#endif
93480 .extra2 = &two,
93481 },
93482-#endif
93483 {
93484 .procname = "ngroups_max",
93485 .data = &ngroups_max,
93486@@ -1073,10 +1107,17 @@ static struct ctl_table kern_table[] = {
93487 */
93488 {
93489 .procname = "perf_event_paranoid",
93490- .data = &sysctl_perf_event_paranoid,
93491- .maxlen = sizeof(sysctl_perf_event_paranoid),
93492+ .data = &sysctl_perf_event_legitimately_concerned,
93493+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
93494 .mode = 0644,
93495- .proc_handler = proc_dointvec,
93496+ /* go ahead, be a hero */
93497+ .proc_handler = proc_dointvec_minmax_sysadmin,
93498+ .extra1 = &neg_one,
93499+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
93500+ .extra2 = &three,
93501+#else
93502+ .extra2 = &two,
93503+#endif
93504 },
93505 {
93506 .procname = "perf_event_mlock_kb",
93507@@ -1335,6 +1376,13 @@ static struct ctl_table vm_table[] = {
93508 .proc_handler = proc_dointvec_minmax,
93509 .extra1 = &zero,
93510 },
93511+ {
93512+ .procname = "heap_stack_gap",
93513+ .data = &sysctl_heap_stack_gap,
93514+ .maxlen = sizeof(sysctl_heap_stack_gap),
93515+ .mode = 0644,
93516+ .proc_handler = proc_doulongvec_minmax,
93517+ },
93518 #else
93519 {
93520 .procname = "nr_trim_pages",
93521@@ -1824,6 +1872,16 @@ int proc_dostring(struct ctl_table *table, int write,
93522 (char __user *)buffer, lenp, ppos);
93523 }
93524
93525+int proc_dostring_modpriv(struct ctl_table *table, int write,
93526+ void __user *buffer, size_t *lenp, loff_t *ppos)
93527+{
93528+ if (write && !capable(CAP_SYS_MODULE))
93529+ return -EPERM;
93530+
93531+ return _proc_do_string(table->data, table->maxlen, write,
93532+ buffer, lenp, ppos);
93533+}
93534+
93535 static size_t proc_skip_spaces(char **buf)
93536 {
93537 size_t ret;
93538@@ -1929,6 +1987,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
93539 len = strlen(tmp);
93540 if (len > *size)
93541 len = *size;
93542+ if (len > sizeof(tmp))
93543+ len = sizeof(tmp);
93544 if (copy_to_user(*buf, tmp, len))
93545 return -EFAULT;
93546 *size -= len;
93547@@ -2106,7 +2166,7 @@ int proc_dointvec(struct ctl_table *table, int write,
93548 static int proc_taint(struct ctl_table *table, int write,
93549 void __user *buffer, size_t *lenp, loff_t *ppos)
93550 {
93551- struct ctl_table t;
93552+ ctl_table_no_const t;
93553 unsigned long tmptaint = get_taint();
93554 int err;
93555
93556@@ -2134,7 +2194,6 @@ static int proc_taint(struct ctl_table *table, int write,
93557 return err;
93558 }
93559
93560-#ifdef CONFIG_PRINTK
93561 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93562 void __user *buffer, size_t *lenp, loff_t *ppos)
93563 {
93564@@ -2143,7 +2202,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
93565
93566 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
93567 }
93568-#endif
93569
93570 struct do_proc_dointvec_minmax_conv_param {
93571 int *min;
93572@@ -2703,6 +2761,12 @@ int proc_dostring(struct ctl_table *table, int write,
93573 return -ENOSYS;
93574 }
93575
93576+int proc_dostring_modpriv(struct ctl_table *table, int write,
93577+ void __user *buffer, size_t *lenp, loff_t *ppos)
93578+{
93579+ return -ENOSYS;
93580+}
93581+
93582 int proc_dointvec(struct ctl_table *table, int write,
93583 void __user *buffer, size_t *lenp, loff_t *ppos)
93584 {
93585@@ -2759,5 +2823,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
93586 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
93587 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
93588 EXPORT_SYMBOL(proc_dostring);
93589+EXPORT_SYMBOL(proc_dostring_modpriv);
93590 EXPORT_SYMBOL(proc_doulongvec_minmax);
93591 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
93592diff --git a/kernel/taskstats.c b/kernel/taskstats.c
93593index 13d2f7c..c93d0b0 100644
93594--- a/kernel/taskstats.c
93595+++ b/kernel/taskstats.c
93596@@ -28,9 +28,12 @@
93597 #include <linux/fs.h>
93598 #include <linux/file.h>
93599 #include <linux/pid_namespace.h>
93600+#include <linux/grsecurity.h>
93601 #include <net/genetlink.h>
93602 #include <linux/atomic.h>
93603
93604+extern int gr_is_taskstats_denied(int pid);
93605+
93606 /*
93607 * Maximum length of a cpumask that can be specified in
93608 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
93609@@ -576,6 +579,9 @@ err:
93610
93611 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
93612 {
93613+ if (gr_is_taskstats_denied(current->pid))
93614+ return -EACCES;
93615+
93616 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
93617 return cmd_attr_register_cpumask(info);
93618 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
93619diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
93620index a7077d3..dd48a49 100644
93621--- a/kernel/time/alarmtimer.c
93622+++ b/kernel/time/alarmtimer.c
93623@@ -823,7 +823,7 @@ static int __init alarmtimer_init(void)
93624 struct platform_device *pdev;
93625 int error = 0;
93626 int i;
93627- struct k_clock alarm_clock = {
93628+ static struct k_clock alarm_clock = {
93629 .clock_getres = alarm_clock_getres,
93630 .clock_get = alarm_clock_get,
93631 .timer_create = alarm_timer_create,
93632diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
93633index 1c2fe7d..ce7483d 100644
93634--- a/kernel/time/hrtimer.c
93635+++ b/kernel/time/hrtimer.c
93636@@ -1399,7 +1399,7 @@ void hrtimer_peek_ahead_timers(void)
93637 local_irq_restore(flags);
93638 }
93639
93640-static void run_hrtimer_softirq(struct softirq_action *h)
93641+static __latent_entropy void run_hrtimer_softirq(void)
93642 {
93643 hrtimer_peek_ahead_timers();
93644 }
93645diff --git a/kernel/time/posix-cpu-timers.c b/kernel/time/posix-cpu-timers.c
93646index 3b89464..5e38379 100644
93647--- a/kernel/time/posix-cpu-timers.c
93648+++ b/kernel/time/posix-cpu-timers.c
93649@@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
93650
93651 static __init int init_posix_cpu_timers(void)
93652 {
93653- struct k_clock process = {
93654+ static struct k_clock process = {
93655 .clock_getres = process_cpu_clock_getres,
93656 .clock_get = process_cpu_clock_get,
93657 .timer_create = process_cpu_timer_create,
93658 .nsleep = process_cpu_nsleep,
93659 .nsleep_restart = process_cpu_nsleep_restart,
93660 };
93661- struct k_clock thread = {
93662+ static struct k_clock thread = {
93663 .clock_getres = thread_cpu_clock_getres,
93664 .clock_get = thread_cpu_clock_get,
93665 .timer_create = thread_cpu_timer_create,
93666diff --git a/kernel/time/posix-timers.c b/kernel/time/posix-timers.c
93667index 31ea01f..7fc61ef 100644
93668--- a/kernel/time/posix-timers.c
93669+++ b/kernel/time/posix-timers.c
93670@@ -43,6 +43,7 @@
93671 #include <linux/hash.h>
93672 #include <linux/posix-clock.h>
93673 #include <linux/posix-timers.h>
93674+#include <linux/grsecurity.h>
93675 #include <linux/syscalls.h>
93676 #include <linux/wait.h>
93677 #include <linux/workqueue.h>
93678@@ -124,7 +125,7 @@ static DEFINE_SPINLOCK(hash_lock);
93679 * which we beg off on and pass to do_sys_settimeofday().
93680 */
93681
93682-static struct k_clock posix_clocks[MAX_CLOCKS];
93683+static struct k_clock *posix_clocks[MAX_CLOCKS];
93684
93685 /*
93686 * These ones are defined below.
93687@@ -277,7 +278,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
93688 */
93689 static __init int init_posix_timers(void)
93690 {
93691- struct k_clock clock_realtime = {
93692+ static struct k_clock clock_realtime = {
93693 .clock_getres = hrtimer_get_res,
93694 .clock_get = posix_clock_realtime_get,
93695 .clock_set = posix_clock_realtime_set,
93696@@ -289,7 +290,7 @@ static __init int init_posix_timers(void)
93697 .timer_get = common_timer_get,
93698 .timer_del = common_timer_del,
93699 };
93700- struct k_clock clock_monotonic = {
93701+ static struct k_clock clock_monotonic = {
93702 .clock_getres = hrtimer_get_res,
93703 .clock_get = posix_ktime_get_ts,
93704 .nsleep = common_nsleep,
93705@@ -299,19 +300,19 @@ static __init int init_posix_timers(void)
93706 .timer_get = common_timer_get,
93707 .timer_del = common_timer_del,
93708 };
93709- struct k_clock clock_monotonic_raw = {
93710+ static struct k_clock clock_monotonic_raw = {
93711 .clock_getres = hrtimer_get_res,
93712 .clock_get = posix_get_monotonic_raw,
93713 };
93714- struct k_clock clock_realtime_coarse = {
93715+ static struct k_clock clock_realtime_coarse = {
93716 .clock_getres = posix_get_coarse_res,
93717 .clock_get = posix_get_realtime_coarse,
93718 };
93719- struct k_clock clock_monotonic_coarse = {
93720+ static struct k_clock clock_monotonic_coarse = {
93721 .clock_getres = posix_get_coarse_res,
93722 .clock_get = posix_get_monotonic_coarse,
93723 };
93724- struct k_clock clock_tai = {
93725+ static struct k_clock clock_tai = {
93726 .clock_getres = hrtimer_get_res,
93727 .clock_get = posix_get_tai,
93728 .nsleep = common_nsleep,
93729@@ -321,7 +322,7 @@ static __init int init_posix_timers(void)
93730 .timer_get = common_timer_get,
93731 .timer_del = common_timer_del,
93732 };
93733- struct k_clock clock_boottime = {
93734+ static struct k_clock clock_boottime = {
93735 .clock_getres = hrtimer_get_res,
93736 .clock_get = posix_get_boottime,
93737 .nsleep = common_nsleep,
93738@@ -533,7 +534,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
93739 return;
93740 }
93741
93742- posix_clocks[clock_id] = *new_clock;
93743+ posix_clocks[clock_id] = new_clock;
93744 }
93745 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
93746
93747@@ -579,9 +580,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
93748 return (id & CLOCKFD_MASK) == CLOCKFD ?
93749 &clock_posix_dynamic : &clock_posix_cpu;
93750
93751- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
93752+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
93753 return NULL;
93754- return &posix_clocks[id];
93755+ return posix_clocks[id];
93756 }
93757
93758 static int common_timer_create(struct k_itimer *new_timer)
93759@@ -599,7 +600,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
93760 struct k_clock *kc = clockid_to_kclock(which_clock);
93761 struct k_itimer *new_timer;
93762 int error, new_timer_id;
93763- sigevent_t event;
93764+ sigevent_t event = { };
93765 int it_id_set = IT_ID_NOT_SET;
93766
93767 if (!kc)
93768@@ -1014,6 +1015,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
93769 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
93770 return -EFAULT;
93771
93772+ /* only the CLOCK_REALTIME clock can be set, all other clocks
93773+ have their clock_set fptr set to a nosettime dummy function
93774+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
93775+ call common_clock_set, which calls do_sys_settimeofday, which
93776+ we hook
93777+ */
93778+
93779 return kc->clock_set(which_clock, &new_tp);
93780 }
93781
93782diff --git a/kernel/time/time.c b/kernel/time/time.c
93783index a9ae20f..d3fbde7 100644
93784--- a/kernel/time/time.c
93785+++ b/kernel/time/time.c
93786@@ -173,6 +173,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
93787 return error;
93788
93789 if (tz) {
93790+ /* we log in do_settimeofday called below, so don't log twice
93791+ */
93792+ if (!tv)
93793+ gr_log_timechange();
93794+
93795 sys_tz = *tz;
93796 update_vsyscall_tz();
93797 if (firsttime) {
93798diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
93799index ec1791f..6a086cd 100644
93800--- a/kernel/time/timekeeping.c
93801+++ b/kernel/time/timekeeping.c
93802@@ -15,6 +15,7 @@
93803 #include <linux/init.h>
93804 #include <linux/mm.h>
93805 #include <linux/sched.h>
93806+#include <linux/grsecurity.h>
93807 #include <linux/syscore_ops.h>
93808 #include <linux/clocksource.h>
93809 #include <linux/jiffies.h>
93810@@ -717,6 +718,8 @@ int do_settimeofday(const struct timespec *tv)
93811 if (!timespec_valid_strict(tv))
93812 return -EINVAL;
93813
93814+ gr_log_timechange();
93815+
93816 raw_spin_lock_irqsave(&timekeeper_lock, flags);
93817 write_seqcount_begin(&tk_core.seq);
93818
93819diff --git a/kernel/time/timer.c b/kernel/time/timer.c
93820index 9bbb834..3caa8ed 100644
93821--- a/kernel/time/timer.c
93822+++ b/kernel/time/timer.c
93823@@ -1394,7 +1394,7 @@ void update_process_times(int user_tick)
93824 /*
93825 * This function runs timers and the timer-tq in bottom half context.
93826 */
93827-static void run_timer_softirq(struct softirq_action *h)
93828+static __latent_entropy void run_timer_softirq(void)
93829 {
93830 struct tvec_base *base = __this_cpu_read(tvec_bases);
93831
93832@@ -1457,7 +1457,7 @@ static void process_timeout(unsigned long __data)
93833 *
93834 * In all cases the return value is guaranteed to be non-negative.
93835 */
93836-signed long __sched schedule_timeout(signed long timeout)
93837+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
93838 {
93839 struct timer_list timer;
93840 unsigned long expire;
93841diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
93842index 61ed862..3b52c65 100644
93843--- a/kernel/time/timer_list.c
93844+++ b/kernel/time/timer_list.c
93845@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
93846
93847 static void print_name_offset(struct seq_file *m, void *sym)
93848 {
93849+#ifdef CONFIG_GRKERNSEC_HIDESYM
93850+ SEQ_printf(m, "<%p>", NULL);
93851+#else
93852 char symname[KSYM_NAME_LEN];
93853
93854 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
93855 SEQ_printf(m, "<%pK>", sym);
93856 else
93857 SEQ_printf(m, "%s", symname);
93858+#endif
93859 }
93860
93861 static void
93862@@ -119,7 +123,11 @@ next_one:
93863 static void
93864 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
93865 {
93866+#ifdef CONFIG_GRKERNSEC_HIDESYM
93867+ SEQ_printf(m, " .base: %p\n", NULL);
93868+#else
93869 SEQ_printf(m, " .base: %pK\n", base);
93870+#endif
93871 SEQ_printf(m, " .index: %d\n",
93872 base->index);
93873 SEQ_printf(m, " .resolution: %Lu nsecs\n",
93874@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
93875 {
93876 struct proc_dir_entry *pe;
93877
93878+#ifdef CONFIG_GRKERNSEC_PROC_ADD
93879+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
93880+#else
93881 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
93882+#endif
93883 if (!pe)
93884 return -ENOMEM;
93885 return 0;
93886diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
93887index 1fb08f2..ca4bb1e 100644
93888--- a/kernel/time/timer_stats.c
93889+++ b/kernel/time/timer_stats.c
93890@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
93891 static unsigned long nr_entries;
93892 static struct entry entries[MAX_ENTRIES];
93893
93894-static atomic_t overflow_count;
93895+static atomic_unchecked_t overflow_count;
93896
93897 /*
93898 * The entries are in a hash-table, for fast lookup:
93899@@ -140,7 +140,7 @@ static void reset_entries(void)
93900 nr_entries = 0;
93901 memset(entries, 0, sizeof(entries));
93902 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
93903- atomic_set(&overflow_count, 0);
93904+ atomic_set_unchecked(&overflow_count, 0);
93905 }
93906
93907 static struct entry *alloc_entry(void)
93908@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93909 if (likely(entry))
93910 entry->count++;
93911 else
93912- atomic_inc(&overflow_count);
93913+ atomic_inc_unchecked(&overflow_count);
93914
93915 out_unlock:
93916 raw_spin_unlock_irqrestore(lock, flags);
93917@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
93918
93919 static void print_name_offset(struct seq_file *m, unsigned long addr)
93920 {
93921+#ifdef CONFIG_GRKERNSEC_HIDESYM
93922+ seq_printf(m, "<%p>", NULL);
93923+#else
93924 char symname[KSYM_NAME_LEN];
93925
93926 if (lookup_symbol_name(addr, symname) < 0)
93927- seq_printf(m, "<%p>", (void *)addr);
93928+ seq_printf(m, "<%pK>", (void *)addr);
93929 else
93930 seq_printf(m, "%s", symname);
93931+#endif
93932 }
93933
93934 static int tstats_show(struct seq_file *m, void *v)
93935@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
93936
93937 seq_puts(m, "Timer Stats Version: v0.3\n");
93938 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
93939- if (atomic_read(&overflow_count))
93940- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
93941+ if (atomic_read_unchecked(&overflow_count))
93942+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
93943 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
93944
93945 for (i = 0; i < nr_entries; i++) {
93946@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
93947 {
93948 struct proc_dir_entry *pe;
93949
93950+#ifdef CONFIG_GRKERNSEC_PROC_ADD
93951+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
93952+#else
93953 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
93954+#endif
93955 if (!pe)
93956 return -ENOMEM;
93957 return 0;
93958diff --git a/kernel/torture.c b/kernel/torture.c
93959index d600af2..27a4e9d 100644
93960--- a/kernel/torture.c
93961+++ b/kernel/torture.c
93962@@ -484,7 +484,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
93963 mutex_lock(&fullstop_mutex);
93964 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
93965 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
93966- ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
93967+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
93968 } else {
93969 pr_warn("Concurrent rmmod and shutdown illegal!\n");
93970 }
93971@@ -551,14 +551,14 @@ static int torture_stutter(void *arg)
93972 if (!torture_must_stop()) {
93973 if (stutter > 1) {
93974 schedule_timeout_interruptible(stutter - 1);
93975- ACCESS_ONCE(stutter_pause_test) = 2;
93976+ ACCESS_ONCE_RW(stutter_pause_test) = 2;
93977 }
93978 schedule_timeout_interruptible(1);
93979- ACCESS_ONCE(stutter_pause_test) = 1;
93980+ ACCESS_ONCE_RW(stutter_pause_test) = 1;
93981 }
93982 if (!torture_must_stop())
93983 schedule_timeout_interruptible(stutter);
93984- ACCESS_ONCE(stutter_pause_test) = 0;
93985+ ACCESS_ONCE_RW(stutter_pause_test) = 0;
93986 torture_shutdown_absorb("torture_stutter");
93987 } while (!torture_must_stop());
93988 torture_kthread_stopping("torture_stutter");
93989@@ -645,7 +645,7 @@ bool torture_cleanup(void)
93990 schedule_timeout_uninterruptible(10);
93991 return true;
93992 }
93993- ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
93994+ ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
93995 mutex_unlock(&fullstop_mutex);
93996 torture_shutdown_cleanup();
93997 torture_shuffle_cleanup();
93998diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
93999index c1bd4ad..4b861dc 100644
94000--- a/kernel/trace/blktrace.c
94001+++ b/kernel/trace/blktrace.c
94002@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
94003 struct blk_trace *bt = filp->private_data;
94004 char buf[16];
94005
94006- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
94007+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
94008
94009 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
94010 }
94011@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
94012 return 1;
94013
94014 bt = buf->chan->private_data;
94015- atomic_inc(&bt->dropped);
94016+ atomic_inc_unchecked(&bt->dropped);
94017 return 0;
94018 }
94019
94020@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
94021
94022 bt->dir = dir;
94023 bt->dev = dev;
94024- atomic_set(&bt->dropped, 0);
94025+ atomic_set_unchecked(&bt->dropped, 0);
94026 INIT_LIST_HEAD(&bt->running_list);
94027
94028 ret = -EIO;
94029diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
94030index 5916a8e..5cd3b1f 100644
94031--- a/kernel/trace/ftrace.c
94032+++ b/kernel/trace/ftrace.c
94033@@ -2128,12 +2128,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
94034 if (unlikely(ftrace_disabled))
94035 return 0;
94036
94037+ ret = ftrace_arch_code_modify_prepare();
94038+ FTRACE_WARN_ON(ret);
94039+ if (ret)
94040+ return 0;
94041+
94042 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
94043+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
94044 if (ret) {
94045 ftrace_bug(ret, ip);
94046- return 0;
94047 }
94048- return 1;
94049+ return ret ? 0 : 1;
94050 }
94051
94052 /*
94053@@ -4458,8 +4463,10 @@ static int ftrace_process_locs(struct module *mod,
94054 if (!count)
94055 return 0;
94056
94057+ pax_open_kernel();
94058 sort(start, count, sizeof(*start),
94059 ftrace_cmp_ips, ftrace_swap_ips);
94060+ pax_close_kernel();
94061
94062 start_pg = ftrace_allocate_pages(count);
94063 if (!start_pg)
94064diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
94065index 2d75c94..5ef6d32 100644
94066--- a/kernel/trace/ring_buffer.c
94067+++ b/kernel/trace/ring_buffer.c
94068@@ -352,9 +352,9 @@ struct buffer_data_page {
94069 */
94070 struct buffer_page {
94071 struct list_head list; /* list of buffer pages */
94072- local_t write; /* index for next write */
94073+ local_unchecked_t write; /* index for next write */
94074 unsigned read; /* index for next read */
94075- local_t entries; /* entries on this page */
94076+ local_unchecked_t entries; /* entries on this page */
94077 unsigned long real_end; /* real end of data */
94078 struct buffer_data_page *page; /* Actual data page */
94079 };
94080@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
94081 unsigned long last_overrun;
94082 local_t entries_bytes;
94083 local_t entries;
94084- local_t overrun;
94085- local_t commit_overrun;
94086+ local_unchecked_t overrun;
94087+ local_unchecked_t commit_overrun;
94088 local_t dropped_events;
94089 local_t committing;
94090 local_t commits;
94091@@ -1005,8 +1005,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94092 *
94093 * We add a counter to the write field to denote this.
94094 */
94095- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
94096- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
94097+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
94098+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
94099
94100 /*
94101 * Just make sure we have seen our old_write and synchronize
94102@@ -1034,8 +1034,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
94103 * cmpxchg to only update if an interrupt did not already
94104 * do it for us. If the cmpxchg fails, we don't care.
94105 */
94106- (void)local_cmpxchg(&next_page->write, old_write, val);
94107- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
94108+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
94109+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
94110
94111 /*
94112 * No need to worry about races with clearing out the commit.
94113@@ -1402,12 +1402,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
94114
94115 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
94116 {
94117- return local_read(&bpage->entries) & RB_WRITE_MASK;
94118+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
94119 }
94120
94121 static inline unsigned long rb_page_write(struct buffer_page *bpage)
94122 {
94123- return local_read(&bpage->write) & RB_WRITE_MASK;
94124+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
94125 }
94126
94127 static int
94128@@ -1502,7 +1502,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
94129 * bytes consumed in ring buffer from here.
94130 * Increment overrun to account for the lost events.
94131 */
94132- local_add(page_entries, &cpu_buffer->overrun);
94133+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
94134 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94135 }
94136
94137@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
94138 * it is our responsibility to update
94139 * the counters.
94140 */
94141- local_add(entries, &cpu_buffer->overrun);
94142+ local_add_unchecked(entries, &cpu_buffer->overrun);
94143 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
94144
94145 /*
94146@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94147 if (tail == BUF_PAGE_SIZE)
94148 tail_page->real_end = 0;
94149
94150- local_sub(length, &tail_page->write);
94151+ local_sub_unchecked(length, &tail_page->write);
94152 return;
94153 }
94154
94155@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94156 rb_event_set_padding(event);
94157
94158 /* Set the write back to the previous setting */
94159- local_sub(length, &tail_page->write);
94160+ local_sub_unchecked(length, &tail_page->write);
94161 return;
94162 }
94163
94164@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
94165
94166 /* Set write to end of buffer */
94167 length = (tail + length) - BUF_PAGE_SIZE;
94168- local_sub(length, &tail_page->write);
94169+ local_sub_unchecked(length, &tail_page->write);
94170 }
94171
94172 /*
94173@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
94174 * about it.
94175 */
94176 if (unlikely(next_page == commit_page)) {
94177- local_inc(&cpu_buffer->commit_overrun);
94178+ local_inc_unchecked(&cpu_buffer->commit_overrun);
94179 goto out_reset;
94180 }
94181
94182@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
94183 cpu_buffer->tail_page) &&
94184 (cpu_buffer->commit_page ==
94185 cpu_buffer->reader_page))) {
94186- local_inc(&cpu_buffer->commit_overrun);
94187+ local_inc_unchecked(&cpu_buffer->commit_overrun);
94188 goto out_reset;
94189 }
94190 }
94191@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94192 length += RB_LEN_TIME_EXTEND;
94193
94194 tail_page = cpu_buffer->tail_page;
94195- write = local_add_return(length, &tail_page->write);
94196+ write = local_add_return_unchecked(length, &tail_page->write);
94197
94198 /* set write to only the index of the write */
94199 write &= RB_WRITE_MASK;
94200@@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
94201 kmemcheck_annotate_bitfield(event, bitfield);
94202 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
94203
94204- local_inc(&tail_page->entries);
94205+ local_inc_unchecked(&tail_page->entries);
94206
94207 /*
94208 * If this is the first commit on the page, then update
94209@@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94210
94211 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
94212 unsigned long write_mask =
94213- local_read(&bpage->write) & ~RB_WRITE_MASK;
94214+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
94215 unsigned long event_length = rb_event_length(event);
94216 /*
94217 * This is on the tail page. It is possible that
94218@@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
94219 */
94220 old_index += write_mask;
94221 new_index += write_mask;
94222- index = local_cmpxchg(&bpage->write, old_index, new_index);
94223+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
94224 if (index == old_index) {
94225 /* update counters */
94226 local_sub(event_length, &cpu_buffer->entries_bytes);
94227@@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94228
94229 /* Do the likely case first */
94230 if (likely(bpage->page == (void *)addr)) {
94231- local_dec(&bpage->entries);
94232+ local_dec_unchecked(&bpage->entries);
94233 return;
94234 }
94235
94236@@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
94237 start = bpage;
94238 do {
94239 if (bpage->page == (void *)addr) {
94240- local_dec(&bpage->entries);
94241+ local_dec_unchecked(&bpage->entries);
94242 return;
94243 }
94244 rb_inc_page(cpu_buffer, &bpage);
94245@@ -3146,7 +3146,7 @@ static inline unsigned long
94246 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
94247 {
94248 return local_read(&cpu_buffer->entries) -
94249- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
94250+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
94251 }
94252
94253 /**
94254@@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
94255 return 0;
94256
94257 cpu_buffer = buffer->buffers[cpu];
94258- ret = local_read(&cpu_buffer->overrun);
94259+ ret = local_read_unchecked(&cpu_buffer->overrun);
94260
94261 return ret;
94262 }
94263@@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
94264 return 0;
94265
94266 cpu_buffer = buffer->buffers[cpu];
94267- ret = local_read(&cpu_buffer->commit_overrun);
94268+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
94269
94270 return ret;
94271 }
94272@@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
94273 /* if you care about this being correct, lock the buffer */
94274 for_each_buffer_cpu(buffer, cpu) {
94275 cpu_buffer = buffer->buffers[cpu];
94276- overruns += local_read(&cpu_buffer->overrun);
94277+ overruns += local_read_unchecked(&cpu_buffer->overrun);
94278 }
94279
94280 return overruns;
94281@@ -3514,8 +3514,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94282 /*
94283 * Reset the reader page to size zero.
94284 */
94285- local_set(&cpu_buffer->reader_page->write, 0);
94286- local_set(&cpu_buffer->reader_page->entries, 0);
94287+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94288+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94289 local_set(&cpu_buffer->reader_page->page->commit, 0);
94290 cpu_buffer->reader_page->real_end = 0;
94291
94292@@ -3549,7 +3549,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
94293 * want to compare with the last_overrun.
94294 */
94295 smp_mb();
94296- overwrite = local_read(&(cpu_buffer->overrun));
94297+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
94298
94299 /*
94300 * Here's the tricky part.
94301@@ -4121,8 +4121,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94302
94303 cpu_buffer->head_page
94304 = list_entry(cpu_buffer->pages, struct buffer_page, list);
94305- local_set(&cpu_buffer->head_page->write, 0);
94306- local_set(&cpu_buffer->head_page->entries, 0);
94307+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
94308+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
94309 local_set(&cpu_buffer->head_page->page->commit, 0);
94310
94311 cpu_buffer->head_page->read = 0;
94312@@ -4132,14 +4132,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
94313
94314 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
94315 INIT_LIST_HEAD(&cpu_buffer->new_pages);
94316- local_set(&cpu_buffer->reader_page->write, 0);
94317- local_set(&cpu_buffer->reader_page->entries, 0);
94318+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
94319+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
94320 local_set(&cpu_buffer->reader_page->page->commit, 0);
94321 cpu_buffer->reader_page->read = 0;
94322
94323 local_set(&cpu_buffer->entries_bytes, 0);
94324- local_set(&cpu_buffer->overrun, 0);
94325- local_set(&cpu_buffer->commit_overrun, 0);
94326+ local_set_unchecked(&cpu_buffer->overrun, 0);
94327+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
94328 local_set(&cpu_buffer->dropped_events, 0);
94329 local_set(&cpu_buffer->entries, 0);
94330 local_set(&cpu_buffer->committing, 0);
94331@@ -4544,8 +4544,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
94332 rb_init_page(bpage);
94333 bpage = reader->page;
94334 reader->page = *data_page;
94335- local_set(&reader->write, 0);
94336- local_set(&reader->entries, 0);
94337+ local_set_unchecked(&reader->write, 0);
94338+ local_set_unchecked(&reader->entries, 0);
94339 reader->read = 0;
94340 *data_page = bpage;
94341
94342diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
94343index 8a52839..dd6d7c8 100644
94344--- a/kernel/trace/trace.c
94345+++ b/kernel/trace/trace.c
94346@@ -3487,7 +3487,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
94347 return 0;
94348 }
94349
94350-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
94351+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
94352 {
94353 /* do nothing if flag is already set */
94354 if (!!(trace_flags & mask) == !!enabled)
94355diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
94356index 385391f..8d2250f 100644
94357--- a/kernel/trace/trace.h
94358+++ b/kernel/trace/trace.h
94359@@ -1280,7 +1280,7 @@ extern const char *__stop___tracepoint_str[];
94360 void trace_printk_init_buffers(void);
94361 void trace_printk_start_comm(void);
94362 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
94363-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
94364+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
94365
94366 /*
94367 * Normal trace_printk() and friends allocates special buffers
94368diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
94369index 57b67b1..66082a9 100644
94370--- a/kernel/trace/trace_clock.c
94371+++ b/kernel/trace/trace_clock.c
94372@@ -124,7 +124,7 @@ u64 notrace trace_clock_global(void)
94373 return now;
94374 }
94375
94376-static atomic64_t trace_counter;
94377+static atomic64_unchecked_t trace_counter;
94378
94379 /*
94380 * trace_clock_counter(): simply an atomic counter.
94381@@ -133,5 +133,5 @@ static atomic64_t trace_counter;
94382 */
94383 u64 notrace trace_clock_counter(void)
94384 {
94385- return atomic64_add_return(1, &trace_counter);
94386+ return atomic64_inc_return_unchecked(&trace_counter);
94387 }
94388diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
94389index ef06ce7..3ea161d 100644
94390--- a/kernel/trace/trace_events.c
94391+++ b/kernel/trace/trace_events.c
94392@@ -1720,7 +1720,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
94393 return 0;
94394 }
94395
94396-struct ftrace_module_file_ops;
94397 static void __add_event_to_tracers(struct ftrace_event_call *call);
94398
94399 /* Add an additional event_call dynamically */
94400diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
94401index 0abd9b8..6a663a2 100644
94402--- a/kernel/trace/trace_mmiotrace.c
94403+++ b/kernel/trace/trace_mmiotrace.c
94404@@ -24,7 +24,7 @@ struct header_iter {
94405 static struct trace_array *mmio_trace_array;
94406 static bool overrun_detected;
94407 static unsigned long prev_overruns;
94408-static atomic_t dropped_count;
94409+static atomic_unchecked_t dropped_count;
94410
94411 static void mmio_reset_data(struct trace_array *tr)
94412 {
94413@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
94414
94415 static unsigned long count_overruns(struct trace_iterator *iter)
94416 {
94417- unsigned long cnt = atomic_xchg(&dropped_count, 0);
94418+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
94419 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
94420
94421 if (over > prev_overruns)
94422@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
94423 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
94424 sizeof(*entry), 0, pc);
94425 if (!event) {
94426- atomic_inc(&dropped_count);
94427+ atomic_inc_unchecked(&dropped_count);
94428 return;
94429 }
94430 entry = ring_buffer_event_data(event);
94431@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
94432 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
94433 sizeof(*entry), 0, pc);
94434 if (!event) {
94435- atomic_inc(&dropped_count);
94436+ atomic_inc_unchecked(&dropped_count);
94437 return;
94438 }
94439 entry = ring_buffer_event_data(event);
94440diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
94441index c6977d5..d243785 100644
94442--- a/kernel/trace/trace_output.c
94443+++ b/kernel/trace/trace_output.c
94444@@ -712,14 +712,16 @@ int register_ftrace_event(struct trace_event *event)
94445 goto out;
94446 }
94447
94448+ pax_open_kernel();
94449 if (event->funcs->trace == NULL)
94450- event->funcs->trace = trace_nop_print;
94451+ *(void **)&event->funcs->trace = trace_nop_print;
94452 if (event->funcs->raw == NULL)
94453- event->funcs->raw = trace_nop_print;
94454+ *(void **)&event->funcs->raw = trace_nop_print;
94455 if (event->funcs->hex == NULL)
94456- event->funcs->hex = trace_nop_print;
94457+ *(void **)&event->funcs->hex = trace_nop_print;
94458 if (event->funcs->binary == NULL)
94459- event->funcs->binary = trace_nop_print;
94460+ *(void **)&event->funcs->binary = trace_nop_print;
94461+ pax_close_kernel();
94462
94463 key = event->type & (EVENT_HASHSIZE - 1);
94464
94465diff --git a/kernel/trace/trace_seq.c b/kernel/trace/trace_seq.c
94466index 1f24ed9..10407ec 100644
94467--- a/kernel/trace/trace_seq.c
94468+++ b/kernel/trace/trace_seq.c
94469@@ -367,7 +367,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
94470
94471 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
94472 if (!IS_ERR(p)) {
94473- p = mangle_path(s->buffer + s->len, p, "\n");
94474+ p = mangle_path(s->buffer + s->len, p, "\n\\");
94475 if (p) {
94476 s->len = p - s->buffer;
94477 return 1;
94478diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
94479index 8a4e5cb..64f270d 100644
94480--- a/kernel/trace/trace_stack.c
94481+++ b/kernel/trace/trace_stack.c
94482@@ -91,7 +91,7 @@ check_stack(unsigned long ip, unsigned long *stack)
94483 return;
94484
94485 /* we do not handle interrupt stacks yet */
94486- if (!object_is_on_stack(stack))
94487+ if (!object_starts_on_stack(stack))
94488 return;
94489
94490 local_irq_save(flags);
94491diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
94492index 7e3cd7a..5156a5fe 100644
94493--- a/kernel/trace/trace_syscalls.c
94494+++ b/kernel/trace/trace_syscalls.c
94495@@ -602,6 +602,8 @@ static int perf_sysenter_enable(struct ftrace_event_call *call)
94496 int num;
94497
94498 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94499+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94500+ return -EINVAL;
94501
94502 mutex_lock(&syscall_trace_lock);
94503 if (!sys_perf_refcount_enter)
94504@@ -622,6 +624,8 @@ static void perf_sysenter_disable(struct ftrace_event_call *call)
94505 int num;
94506
94507 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94508+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94509+ return;
94510
94511 mutex_lock(&syscall_trace_lock);
94512 sys_perf_refcount_enter--;
94513@@ -674,6 +678,8 @@ static int perf_sysexit_enable(struct ftrace_event_call *call)
94514 int num;
94515
94516 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94517+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94518+ return -EINVAL;
94519
94520 mutex_lock(&syscall_trace_lock);
94521 if (!sys_perf_refcount_exit)
94522@@ -694,6 +700,8 @@ static void perf_sysexit_disable(struct ftrace_event_call *call)
94523 int num;
94524
94525 num = ((struct syscall_metadata *)call->data)->syscall_nr;
94526+ if (WARN_ON_ONCE(num < 0 || num >= NR_syscalls))
94527+ return;
94528
94529 mutex_lock(&syscall_trace_lock);
94530 sys_perf_refcount_exit--;
94531diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
94532index aa312b0..395f343 100644
94533--- a/kernel/user_namespace.c
94534+++ b/kernel/user_namespace.c
94535@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
94536 !kgid_has_mapping(parent_ns, group))
94537 return -EPERM;
94538
94539+#ifdef CONFIG_GRKERNSEC
94540+ /*
94541+ * This doesn't really inspire confidence:
94542+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
94543+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
94544+ * Increases kernel attack surface in areas developers
94545+ * previously cared little about ("low importance due
94546+ * to requiring "root" capability")
94547+ * To be removed when this code receives *proper* review
94548+ */
94549+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
94550+ !capable(CAP_SETGID))
94551+ return -EPERM;
94552+#endif
94553+
94554 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
94555 if (!ns)
94556 return -ENOMEM;
94557@@ -872,7 +887,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
94558 if (atomic_read(&current->mm->mm_users) > 1)
94559 return -EINVAL;
94560
94561- if (current->fs->users != 1)
94562+ if (atomic_read(&current->fs->users) != 1)
94563 return -EINVAL;
94564
94565 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
94566diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
94567index c8eac43..4b5f08f 100644
94568--- a/kernel/utsname_sysctl.c
94569+++ b/kernel/utsname_sysctl.c
94570@@ -47,7 +47,7 @@ static void put_uts(struct ctl_table *table, int write, void *which)
94571 static int proc_do_uts_string(struct ctl_table *table, int write,
94572 void __user *buffer, size_t *lenp, loff_t *ppos)
94573 {
94574- struct ctl_table uts_table;
94575+ ctl_table_no_const uts_table;
94576 int r;
94577 memcpy(&uts_table, table, sizeof(uts_table));
94578 uts_table.data = get_uts(table, write);
94579diff --git a/kernel/watchdog.c b/kernel/watchdog.c
94580index a8d6914..8fbdb13 100644
94581--- a/kernel/watchdog.c
94582+++ b/kernel/watchdog.c
94583@@ -521,7 +521,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
94584 static void watchdog_nmi_disable(unsigned int cpu) { return; }
94585 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
94586
94587-static struct smp_hotplug_thread watchdog_threads = {
94588+static struct smp_hotplug_thread watchdog_threads __read_only = {
94589 .store = &softlockup_watchdog,
94590 .thread_should_run = watchdog_should_run,
94591 .thread_fn = watchdog,
94592diff --git a/kernel/workqueue.c b/kernel/workqueue.c
94593index 5dbe22a..872413c 100644
94594--- a/kernel/workqueue.c
94595+++ b/kernel/workqueue.c
94596@@ -4507,7 +4507,7 @@ static void rebind_workers(struct worker_pool *pool)
94597 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
94598 worker_flags |= WORKER_REBOUND;
94599 worker_flags &= ~WORKER_UNBOUND;
94600- ACCESS_ONCE(worker->flags) = worker_flags;
94601+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
94602 }
94603
94604 spin_unlock_irq(&pool->lock);
94605diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
94606index a285900..5e3b26b 100644
94607--- a/lib/Kconfig.debug
94608+++ b/lib/Kconfig.debug
94609@@ -882,7 +882,7 @@ config DEBUG_MUTEXES
94610
94611 config DEBUG_WW_MUTEX_SLOWPATH
94612 bool "Wait/wound mutex debugging: Slowpath testing"
94613- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94614+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94615 select DEBUG_LOCK_ALLOC
94616 select DEBUG_SPINLOCK
94617 select DEBUG_MUTEXES
94618@@ -899,7 +899,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
94619
94620 config DEBUG_LOCK_ALLOC
94621 bool "Lock debugging: detect incorrect freeing of live locks"
94622- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94623+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94624 select DEBUG_SPINLOCK
94625 select DEBUG_MUTEXES
94626 select LOCKDEP
94627@@ -913,7 +913,7 @@ config DEBUG_LOCK_ALLOC
94628
94629 config PROVE_LOCKING
94630 bool "Lock debugging: prove locking correctness"
94631- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94632+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94633 select LOCKDEP
94634 select DEBUG_SPINLOCK
94635 select DEBUG_MUTEXES
94636@@ -964,7 +964,7 @@ config LOCKDEP
94637
94638 config LOCK_STAT
94639 bool "Lock usage statistics"
94640- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
94641+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
94642 select LOCKDEP
94643 select DEBUG_SPINLOCK
94644 select DEBUG_MUTEXES
94645@@ -1437,6 +1437,7 @@ config LATENCYTOP
94646 depends on DEBUG_KERNEL
94647 depends on STACKTRACE_SUPPORT
94648 depends on PROC_FS
94649+ depends on !GRKERNSEC_HIDESYM
94650 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
94651 select KALLSYMS
94652 select KALLSYMS_ALL
94653@@ -1453,7 +1454,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94654 config DEBUG_STRICT_USER_COPY_CHECKS
94655 bool "Strict user copy size checks"
94656 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
94657- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
94658+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
94659 help
94660 Enabling this option turns a certain set of sanity checks for user
94661 copy operations into compile time failures.
94662@@ -1581,7 +1582,7 @@ endmenu # runtime tests
94663
94664 config PROVIDE_OHCI1394_DMA_INIT
94665 bool "Remote debugging over FireWire early on boot"
94666- depends on PCI && X86
94667+ depends on PCI && X86 && !GRKERNSEC
94668 help
94669 If you want to debug problems which hang or crash the kernel early
94670 on boot and the crashing machine has a FireWire port, you can use
94671diff --git a/lib/Makefile b/lib/Makefile
94672index d6b4bc4..a3724eb 100644
94673--- a/lib/Makefile
94674+++ b/lib/Makefile
94675@@ -55,7 +55,7 @@ obj-$(CONFIG_BTREE) += btree.o
94676 obj-$(CONFIG_INTERVAL_TREE) += interval_tree.o
94677 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
94678 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
94679-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
94680+obj-y += list_debug.o
94681 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
94682
94683 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
94684diff --git a/lib/average.c b/lib/average.c
94685index 114d1be..ab0350c 100644
94686--- a/lib/average.c
94687+++ b/lib/average.c
94688@@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
94689 {
94690 unsigned long internal = ACCESS_ONCE(avg->internal);
94691
94692- ACCESS_ONCE(avg->internal) = internal ?
94693+ ACCESS_ONCE_RW(avg->internal) = internal ?
94694 (((internal << avg->weight) - internal) +
94695 (val << avg->factor)) >> avg->weight :
94696 (val << avg->factor);
94697diff --git a/lib/bitmap.c b/lib/bitmap.c
94698index 33ce011..89e3d6f 100644
94699--- a/lib/bitmap.c
94700+++ b/lib/bitmap.c
94701@@ -433,7 +433,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
94702 {
94703 int c, old_c, totaldigits, ndigits, nchunks, nbits;
94704 u32 chunk;
94705- const char __user __force *ubuf = (const char __user __force *)buf;
94706+ const char __user *ubuf = (const char __force_user *)buf;
94707
94708 bitmap_zero(maskp, nmaskbits);
94709
94710@@ -518,7 +518,7 @@ int bitmap_parse_user(const char __user *ubuf,
94711 {
94712 if (!access_ok(VERIFY_READ, ubuf, ulen))
94713 return -EFAULT;
94714- return __bitmap_parse((const char __force *)ubuf,
94715+ return __bitmap_parse((const char __force_kernel *)ubuf,
94716 ulen, 1, maskp, nmaskbits);
94717
94718 }
94719@@ -609,7 +609,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
94720 {
94721 unsigned a, b;
94722 int c, old_c, totaldigits;
94723- const char __user __force *ubuf = (const char __user __force *)buf;
94724+ const char __user *ubuf = (const char __force_user *)buf;
94725 int exp_digit, in_range;
94726
94727 totaldigits = c = 0;
94728@@ -704,7 +704,7 @@ int bitmap_parselist_user(const char __user *ubuf,
94729 {
94730 if (!access_ok(VERIFY_READ, ubuf, ulen))
94731 return -EFAULT;
94732- return __bitmap_parselist((const char __force *)ubuf,
94733+ return __bitmap_parselist((const char __force_kernel *)ubuf,
94734 ulen, 1, maskp, nmaskbits);
94735 }
94736 EXPORT_SYMBOL(bitmap_parselist_user);
94737diff --git a/lib/bug.c b/lib/bug.c
94738index d1d7c78..b354235 100644
94739--- a/lib/bug.c
94740+++ b/lib/bug.c
94741@@ -137,6 +137,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
94742 return BUG_TRAP_TYPE_NONE;
94743
94744 bug = find_bug(bugaddr);
94745+ if (!bug)
94746+ return BUG_TRAP_TYPE_NONE;
94747
94748 file = NULL;
94749 line = 0;
94750diff --git a/lib/debugobjects.c b/lib/debugobjects.c
94751index 547f7f9..a6d4ba0 100644
94752--- a/lib/debugobjects.c
94753+++ b/lib/debugobjects.c
94754@@ -289,7 +289,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
94755 if (limit > 4)
94756 return;
94757
94758- is_on_stack = object_is_on_stack(addr);
94759+ is_on_stack = object_starts_on_stack(addr);
94760 if (is_on_stack == onstack)
94761 return;
94762
94763diff --git a/lib/div64.c b/lib/div64.c
94764index 4382ad7..08aa558 100644
94765--- a/lib/div64.c
94766+++ b/lib/div64.c
94767@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
94768 EXPORT_SYMBOL(__div64_32);
94769
94770 #ifndef div_s64_rem
94771-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94772+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
94773 {
94774 u64 quotient;
94775
94776@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
94777 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
94778 */
94779 #ifndef div64_u64
94780-u64 div64_u64(u64 dividend, u64 divisor)
94781+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
94782 {
94783 u32 high = divisor >> 32;
94784 u64 quot;
94785diff --git a/lib/dma-debug.c b/lib/dma-debug.c
94786index 98f2d7e..899da5c 100644
94787--- a/lib/dma-debug.c
94788+++ b/lib/dma-debug.c
94789@@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
94790
94791 void dma_debug_add_bus(struct bus_type *bus)
94792 {
94793- struct notifier_block *nb;
94794+ notifier_block_no_const *nb;
94795
94796 if (global_disable)
94797 return;
94798@@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
94799
94800 static void check_for_stack(struct device *dev, void *addr)
94801 {
94802- if (object_is_on_stack(addr))
94803+ if (object_starts_on_stack(addr))
94804 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
94805 "stack [addr=%p]\n", addr);
94806 }
94807diff --git a/lib/hash.c b/lib/hash.c
94808index fea973f..386626f 100644
94809--- a/lib/hash.c
94810+++ b/lib/hash.c
94811@@ -14,7 +14,7 @@
94812 #include <linux/hash.h>
94813 #include <linux/cache.h>
94814
94815-static struct fast_hash_ops arch_hash_ops __read_mostly = {
94816+static struct fast_hash_ops arch_hash_ops __read_only = {
94817 .hash = jhash,
94818 .hash2 = jhash2,
94819 };
94820diff --git a/lib/inflate.c b/lib/inflate.c
94821index 013a761..c28f3fc 100644
94822--- a/lib/inflate.c
94823+++ b/lib/inflate.c
94824@@ -269,7 +269,7 @@ static void free(void *where)
94825 malloc_ptr = free_mem_ptr;
94826 }
94827 #else
94828-#define malloc(a) kmalloc(a, GFP_KERNEL)
94829+#define malloc(a) kmalloc((a), GFP_KERNEL)
94830 #define free(a) kfree(a)
94831 #endif
94832
94833diff --git a/lib/ioremap.c b/lib/ioremap.c
94834index 0c9216c..863bd89 100644
94835--- a/lib/ioremap.c
94836+++ b/lib/ioremap.c
94837@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
94838 unsigned long next;
94839
94840 phys_addr -= addr;
94841- pmd = pmd_alloc(&init_mm, pud, addr);
94842+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
94843 if (!pmd)
94844 return -ENOMEM;
94845 do {
94846@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
94847 unsigned long next;
94848
94849 phys_addr -= addr;
94850- pud = pud_alloc(&init_mm, pgd, addr);
94851+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
94852 if (!pud)
94853 return -ENOMEM;
94854 do {
94855diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
94856index bd2bea9..6b3c95e 100644
94857--- a/lib/is_single_threaded.c
94858+++ b/lib/is_single_threaded.c
94859@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
94860 struct task_struct *p, *t;
94861 bool ret;
94862
94863+ if (!mm)
94864+ return true;
94865+
94866 if (atomic_read(&task->signal->live) != 1)
94867 return false;
94868
94869diff --git a/lib/kobject.c b/lib/kobject.c
94870index 58751bb..93a1853 100644
94871--- a/lib/kobject.c
94872+++ b/lib/kobject.c
94873@@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
94874
94875
94876 static DEFINE_SPINLOCK(kobj_ns_type_lock);
94877-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
94878+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
94879
94880-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94881+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
94882 {
94883 enum kobj_ns_type type = ops->type;
94884 int error;
94885diff --git a/lib/list_debug.c b/lib/list_debug.c
94886index c24c2f7..f0296f4 100644
94887--- a/lib/list_debug.c
94888+++ b/lib/list_debug.c
94889@@ -11,7 +11,9 @@
94890 #include <linux/bug.h>
94891 #include <linux/kernel.h>
94892 #include <linux/rculist.h>
94893+#include <linux/mm.h>
94894
94895+#ifdef CONFIG_DEBUG_LIST
94896 /*
94897 * Insert a new entry between two known consecutive entries.
94898 *
94899@@ -19,21 +21,40 @@
94900 * the prev/next entries already!
94901 */
94902
94903+static bool __list_add_debug(struct list_head *new,
94904+ struct list_head *prev,
94905+ struct list_head *next)
94906+{
94907+ if (unlikely(next->prev != prev)) {
94908+ printk(KERN_ERR "list_add corruption. next->prev should be "
94909+ "prev (%p), but was %p. (next=%p).\n",
94910+ prev, next->prev, next);
94911+ BUG();
94912+ return false;
94913+ }
94914+ if (unlikely(prev->next != next)) {
94915+ printk(KERN_ERR "list_add corruption. prev->next should be "
94916+ "next (%p), but was %p. (prev=%p).\n",
94917+ next, prev->next, prev);
94918+ BUG();
94919+ return false;
94920+ }
94921+ if (unlikely(new == prev || new == next)) {
94922+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
94923+ new, prev, next);
94924+ BUG();
94925+ return false;
94926+ }
94927+ return true;
94928+}
94929+
94930 void __list_add(struct list_head *new,
94931- struct list_head *prev,
94932- struct list_head *next)
94933+ struct list_head *prev,
94934+ struct list_head *next)
94935 {
94936- WARN(next->prev != prev,
94937- "list_add corruption. next->prev should be "
94938- "prev (%p), but was %p. (next=%p).\n",
94939- prev, next->prev, next);
94940- WARN(prev->next != next,
94941- "list_add corruption. prev->next should be "
94942- "next (%p), but was %p. (prev=%p).\n",
94943- next, prev->next, prev);
94944- WARN(new == prev || new == next,
94945- "list_add double add: new=%p, prev=%p, next=%p.\n",
94946- new, prev, next);
94947+ if (!__list_add_debug(new, prev, next))
94948+ return;
94949+
94950 next->prev = new;
94951 new->next = next;
94952 new->prev = prev;
94953@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
94954 }
94955 EXPORT_SYMBOL(__list_add);
94956
94957-void __list_del_entry(struct list_head *entry)
94958+static bool __list_del_entry_debug(struct list_head *entry)
94959 {
94960 struct list_head *prev, *next;
94961
94962 prev = entry->prev;
94963 next = entry->next;
94964
94965- if (WARN(next == LIST_POISON1,
94966- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
94967- entry, LIST_POISON1) ||
94968- WARN(prev == LIST_POISON2,
94969- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
94970- entry, LIST_POISON2) ||
94971- WARN(prev->next != entry,
94972- "list_del corruption. prev->next should be %p, "
94973- "but was %p\n", entry, prev->next) ||
94974- WARN(next->prev != entry,
94975- "list_del corruption. next->prev should be %p, "
94976- "but was %p\n", entry, next->prev))
94977+ if (unlikely(next == LIST_POISON1)) {
94978+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
94979+ entry, LIST_POISON1);
94980+ BUG();
94981+ return false;
94982+ }
94983+ if (unlikely(prev == LIST_POISON2)) {
94984+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
94985+ entry, LIST_POISON2);
94986+ BUG();
94987+ return false;
94988+ }
94989+ if (unlikely(entry->prev->next != entry)) {
94990+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
94991+ "but was %p\n", entry, prev->next);
94992+ BUG();
94993+ return false;
94994+ }
94995+ if (unlikely(entry->next->prev != entry)) {
94996+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
94997+ "but was %p\n", entry, next->prev);
94998+ BUG();
94999+ return false;
95000+ }
95001+ return true;
95002+}
95003+
95004+void __list_del_entry(struct list_head *entry)
95005+{
95006+ if (!__list_del_entry_debug(entry))
95007 return;
95008
95009- __list_del(prev, next);
95010+ __list_del(entry->prev, entry->next);
95011 }
95012 EXPORT_SYMBOL(__list_del_entry);
95013
95014@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
95015 void __list_add_rcu(struct list_head *new,
95016 struct list_head *prev, struct list_head *next)
95017 {
95018- WARN(next->prev != prev,
95019- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
95020- prev, next->prev, next);
95021- WARN(prev->next != next,
95022- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
95023- next, prev->next, prev);
95024+ if (!__list_add_debug(new, prev, next))
95025+ return;
95026+
95027 new->next = next;
95028 new->prev = prev;
95029 rcu_assign_pointer(list_next_rcu(prev), new);
95030 next->prev = new;
95031 }
95032 EXPORT_SYMBOL(__list_add_rcu);
95033+#endif
95034+
95035+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
95036+{
95037+#ifdef CONFIG_DEBUG_LIST
95038+ if (!__list_add_debug(new, prev, next))
95039+ return;
95040+#endif
95041+
95042+ pax_open_kernel();
95043+ next->prev = new;
95044+ new->next = next;
95045+ new->prev = prev;
95046+ prev->next = new;
95047+ pax_close_kernel();
95048+}
95049+EXPORT_SYMBOL(__pax_list_add);
95050+
95051+void pax_list_del(struct list_head *entry)
95052+{
95053+#ifdef CONFIG_DEBUG_LIST
95054+ if (!__list_del_entry_debug(entry))
95055+ return;
95056+#endif
95057+
95058+ pax_open_kernel();
95059+ __list_del(entry->prev, entry->next);
95060+ entry->next = LIST_POISON1;
95061+ entry->prev = LIST_POISON2;
95062+ pax_close_kernel();
95063+}
95064+EXPORT_SYMBOL(pax_list_del);
95065+
95066+void pax_list_del_init(struct list_head *entry)
95067+{
95068+ pax_open_kernel();
95069+ __list_del(entry->prev, entry->next);
95070+ INIT_LIST_HEAD(entry);
95071+ pax_close_kernel();
95072+}
95073+EXPORT_SYMBOL(pax_list_del_init);
95074+
95075+void __pax_list_add_rcu(struct list_head *new,
95076+ struct list_head *prev, struct list_head *next)
95077+{
95078+#ifdef CONFIG_DEBUG_LIST
95079+ if (!__list_add_debug(new, prev, next))
95080+ return;
95081+#endif
95082+
95083+ pax_open_kernel();
95084+ new->next = next;
95085+ new->prev = prev;
95086+ rcu_assign_pointer(list_next_rcu(prev), new);
95087+ next->prev = new;
95088+ pax_close_kernel();
95089+}
95090+EXPORT_SYMBOL(__pax_list_add_rcu);
95091+
95092+void pax_list_del_rcu(struct list_head *entry)
95093+{
95094+#ifdef CONFIG_DEBUG_LIST
95095+ if (!__list_del_entry_debug(entry))
95096+ return;
95097+#endif
95098+
95099+ pax_open_kernel();
95100+ __list_del(entry->prev, entry->next);
95101+ entry->next = LIST_POISON1;
95102+ entry->prev = LIST_POISON2;
95103+ pax_close_kernel();
95104+}
95105+EXPORT_SYMBOL(pax_list_del_rcu);
95106diff --git a/lib/lockref.c b/lib/lockref.c
95107index d2233de..fa1a2f6 100644
95108--- a/lib/lockref.c
95109+++ b/lib/lockref.c
95110@@ -48,13 +48,13 @@
95111 void lockref_get(struct lockref *lockref)
95112 {
95113 CMPXCHG_LOOP(
95114- new.count++;
95115+ __lockref_inc(&new);
95116 ,
95117 return;
95118 );
95119
95120 spin_lock(&lockref->lock);
95121- lockref->count++;
95122+ __lockref_inc(lockref);
95123 spin_unlock(&lockref->lock);
95124 }
95125 EXPORT_SYMBOL(lockref_get);
95126@@ -69,7 +69,7 @@ int lockref_get_not_zero(struct lockref *lockref)
95127 int retval;
95128
95129 CMPXCHG_LOOP(
95130- new.count++;
95131+ __lockref_inc(&new);
95132 if (!old.count)
95133 return 0;
95134 ,
95135@@ -79,7 +79,7 @@ int lockref_get_not_zero(struct lockref *lockref)
95136 spin_lock(&lockref->lock);
95137 retval = 0;
95138 if (lockref->count) {
95139- lockref->count++;
95140+ __lockref_inc(lockref);
95141 retval = 1;
95142 }
95143 spin_unlock(&lockref->lock);
95144@@ -96,7 +96,7 @@ EXPORT_SYMBOL(lockref_get_not_zero);
95145 int lockref_get_or_lock(struct lockref *lockref)
95146 {
95147 CMPXCHG_LOOP(
95148- new.count++;
95149+ __lockref_inc(&new);
95150 if (!old.count)
95151 break;
95152 ,
95153@@ -106,7 +106,7 @@ int lockref_get_or_lock(struct lockref *lockref)
95154 spin_lock(&lockref->lock);
95155 if (!lockref->count)
95156 return 0;
95157- lockref->count++;
95158+ __lockref_inc(lockref);
95159 spin_unlock(&lockref->lock);
95160 return 1;
95161 }
95162@@ -120,7 +120,7 @@ EXPORT_SYMBOL(lockref_get_or_lock);
95163 int lockref_put_or_lock(struct lockref *lockref)
95164 {
95165 CMPXCHG_LOOP(
95166- new.count--;
95167+ __lockref_dec(&new);
95168 if (old.count <= 1)
95169 break;
95170 ,
95171@@ -130,7 +130,7 @@ int lockref_put_or_lock(struct lockref *lockref)
95172 spin_lock(&lockref->lock);
95173 if (lockref->count <= 1)
95174 return 0;
95175- lockref->count--;
95176+ __lockref_dec(lockref);
95177 spin_unlock(&lockref->lock);
95178 return 1;
95179 }
95180@@ -157,7 +157,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95181 int retval;
95182
95183 CMPXCHG_LOOP(
95184- new.count++;
95185+ __lockref_inc(&new);
95186 if ((int)old.count < 0)
95187 return 0;
95188 ,
95189@@ -167,7 +167,7 @@ int lockref_get_not_dead(struct lockref *lockref)
95190 spin_lock(&lockref->lock);
95191 retval = 0;
95192 if ((int) lockref->count >= 0) {
95193- lockref->count++;
95194+ __lockref_inc(lockref);
95195 retval = 1;
95196 }
95197 spin_unlock(&lockref->lock);
95198diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
95199index a89cf09..1a42c2d 100644
95200--- a/lib/percpu-refcount.c
95201+++ b/lib/percpu-refcount.c
95202@@ -29,7 +29,7 @@
95203 * can't hit 0 before we've added up all the percpu refs.
95204 */
95205
95206-#define PCPU_COUNT_BIAS (1U << 31)
95207+#define PCPU_COUNT_BIAS (1U << 30)
95208
95209 static unsigned __percpu *pcpu_count_ptr(struct percpu_ref *ref)
95210 {
95211diff --git a/lib/radix-tree.c b/lib/radix-tree.c
95212index 3291a8e..346a91e 100644
95213--- a/lib/radix-tree.c
95214+++ b/lib/radix-tree.c
95215@@ -67,7 +67,7 @@ struct radix_tree_preload {
95216 int nr;
95217 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
95218 };
95219-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
95220+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
95221
95222 static inline void *ptr_to_indirect(void *ptr)
95223 {
95224diff --git a/lib/random32.c b/lib/random32.c
95225index c9b6bf3..4752c6d4 100644
95226--- a/lib/random32.c
95227+++ b/lib/random32.c
95228@@ -46,7 +46,7 @@ static inline void prandom_state_selftest(void)
95229 }
95230 #endif
95231
95232-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
95233+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
95234
95235 /**
95236 * prandom_u32_state - seeded pseudo-random number generator.
95237diff --git a/lib/rbtree.c b/lib/rbtree.c
95238index c16c81a..4dcbda1 100644
95239--- a/lib/rbtree.c
95240+++ b/lib/rbtree.c
95241@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
95242 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
95243
95244 static const struct rb_augment_callbacks dummy_callbacks = {
95245- dummy_propagate, dummy_copy, dummy_rotate
95246+ .propagate = dummy_propagate,
95247+ .copy = dummy_copy,
95248+ .rotate = dummy_rotate
95249 };
95250
95251 void rb_insert_color(struct rb_node *node, struct rb_root *root)
95252diff --git a/lib/show_mem.c b/lib/show_mem.c
95253index 0922579..9d7adb9 100644
95254--- a/lib/show_mem.c
95255+++ b/lib/show_mem.c
95256@@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
95257 quicklist_total_size());
95258 #endif
95259 #ifdef CONFIG_MEMORY_FAILURE
95260- printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
95261+ printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
95262 #endif
95263 }
95264diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
95265index bb2b201..46abaf9 100644
95266--- a/lib/strncpy_from_user.c
95267+++ b/lib/strncpy_from_user.c
95268@@ -21,7 +21,7 @@
95269 */
95270 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
95271 {
95272- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95273+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95274 long res = 0;
95275
95276 /*
95277diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
95278index a28df52..3d55877 100644
95279--- a/lib/strnlen_user.c
95280+++ b/lib/strnlen_user.c
95281@@ -26,7 +26,7 @@
95282 */
95283 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
95284 {
95285- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95286+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
95287 long align, res = 0;
95288 unsigned long c;
95289
95290diff --git a/lib/swiotlb.c b/lib/swiotlb.c
95291index 4abda07..b9d3765 100644
95292--- a/lib/swiotlb.c
95293+++ b/lib/swiotlb.c
95294@@ -682,7 +682,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
95295
95296 void
95297 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
95298- dma_addr_t dev_addr)
95299+ dma_addr_t dev_addr, struct dma_attrs *attrs)
95300 {
95301 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
95302
95303diff --git a/lib/test_bpf.c b/lib/test_bpf.c
95304index 89e0345..3347efe 100644
95305--- a/lib/test_bpf.c
95306+++ b/lib/test_bpf.c
95307@@ -1798,7 +1798,7 @@ static struct bpf_prog *generate_filter(int which, int *err)
95308 break;
95309
95310 case INTERNAL:
95311- fp = kzalloc(bpf_prog_size(flen), GFP_KERNEL);
95312+ fp = bpf_prog_alloc(bpf_prog_size(flen), 0);
95313 if (fp == NULL) {
95314 pr_cont("UNEXPECTED_FAIL no memory left\n");
95315 *err = -ENOMEM;
95316diff --git a/lib/usercopy.c b/lib/usercopy.c
95317index 4f5b1dd..7cab418 100644
95318--- a/lib/usercopy.c
95319+++ b/lib/usercopy.c
95320@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
95321 WARN(1, "Buffer overflow detected!\n");
95322 }
95323 EXPORT_SYMBOL(copy_from_user_overflow);
95324+
95325+void copy_to_user_overflow(void)
95326+{
95327+ WARN(1, "Buffer overflow detected!\n");
95328+}
95329+EXPORT_SYMBOL(copy_to_user_overflow);
95330diff --git a/lib/vsprintf.c b/lib/vsprintf.c
95331index 6fe2c84..2fe5ec6 100644
95332--- a/lib/vsprintf.c
95333+++ b/lib/vsprintf.c
95334@@ -16,6 +16,9 @@
95335 * - scnprintf and vscnprintf
95336 */
95337
95338+#ifdef CONFIG_GRKERNSEC_HIDESYM
95339+#define __INCLUDED_BY_HIDESYM 1
95340+#endif
95341 #include <stdarg.h>
95342 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
95343 #include <linux/types.h>
95344@@ -624,7 +627,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
95345 #ifdef CONFIG_KALLSYMS
95346 if (*fmt == 'B')
95347 sprint_backtrace(sym, value);
95348- else if (*fmt != 'f' && *fmt != 's')
95349+ else if (*fmt != 'f' && *fmt != 's' && *fmt != 'X')
95350 sprint_symbol(sym, value);
95351 else
95352 sprint_symbol_no_offset(sym, value);
95353@@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
95354 return number(buf, end, num, spec);
95355 }
95356
95357+#ifdef CONFIG_GRKERNSEC_HIDESYM
95358+int kptr_restrict __read_mostly = 2;
95359+#else
95360 int kptr_restrict __read_mostly;
95361+#endif
95362
95363 /*
95364 * Show a '%p' thing. A kernel extension is that the '%p' is followed
95365@@ -1194,8 +1201,10 @@ int kptr_restrict __read_mostly;
95366 *
95367 * - 'F' For symbolic function descriptor pointers with offset
95368 * - 'f' For simple symbolic function names without offset
95369+ * - 'X' For simple symbolic function names without offset approved for use with GRKERNSEC_HIDESYM
95370 * - 'S' For symbolic direct pointers with offset
95371 * - 's' For symbolic direct pointers without offset
95372+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
95373 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
95374 * - 'B' For backtraced symbolic direct pointers with offset
95375 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
95376@@ -1263,12 +1272,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95377
95378 if (!ptr && *fmt != 'K') {
95379 /*
95380- * Print (null) with the same width as a pointer so it makes
95381+ * Print (nil) with the same width as a pointer so it makes
95382 * tabular output look nice.
95383 */
95384 if (spec.field_width == -1)
95385 spec.field_width = default_width;
95386- return string(buf, end, "(null)", spec);
95387+ return string(buf, end, "(nil)", spec);
95388 }
95389
95390 switch (*fmt) {
95391@@ -1278,6 +1287,14 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95392 /* Fallthrough */
95393 case 'S':
95394 case 's':
95395+#ifdef CONFIG_GRKERNSEC_HIDESYM
95396+ break;
95397+#else
95398+ return symbol_string(buf, end, ptr, spec, fmt);
95399+#endif
95400+ case 'X':
95401+ ptr = dereference_function_descriptor(ptr);
95402+ case 'A':
95403 case 'B':
95404 return symbol_string(buf, end, ptr, spec, fmt);
95405 case 'R':
95406@@ -1333,6 +1350,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95407 va_end(va);
95408 return buf;
95409 }
95410+ case 'P':
95411+ break;
95412 case 'K':
95413 /*
95414 * %pK cannot be used in IRQ context because its test
95415@@ -1390,6 +1409,22 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
95416 ((const struct file *)ptr)->f_path.dentry,
95417 spec, fmt);
95418 }
95419+
95420+#ifdef CONFIG_GRKERNSEC_HIDESYM
95421+ /* 'P' = approved pointers to copy to userland,
95422+ as in the /proc/kallsyms case, as we make it display nothing
95423+ for non-root users, and the real contents for root users
95424+ 'X' = approved simple symbols
95425+ Also ignore 'K' pointers, since we force their NULLing for non-root users
95426+ above
95427+ */
95428+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'X' && *fmt != 'K' && is_usercopy_object(buf)) {
95429+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
95430+ dump_stack();
95431+ ptr = NULL;
95432+ }
95433+#endif
95434+
95435 spec.flags |= SMALL;
95436 if (spec.field_width == -1) {
95437 spec.field_width = default_width;
95438@@ -2089,11 +2124,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95439 typeof(type) value; \
95440 if (sizeof(type) == 8) { \
95441 args = PTR_ALIGN(args, sizeof(u32)); \
95442- *(u32 *)&value = *(u32 *)args; \
95443- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
95444+ *(u32 *)&value = *(const u32 *)args; \
95445+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
95446 } else { \
95447 args = PTR_ALIGN(args, sizeof(type)); \
95448- value = *(typeof(type) *)args; \
95449+ value = *(const typeof(type) *)args; \
95450 } \
95451 args += sizeof(type); \
95452 value; \
95453@@ -2156,7 +2191,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
95454 case FORMAT_TYPE_STR: {
95455 const char *str_arg = args;
95456 args += strlen(str_arg) + 1;
95457- str = string(str, end, (char *)str_arg, spec);
95458+ str = string(str, end, str_arg, spec);
95459 break;
95460 }
95461
95462diff --git a/localversion-grsec b/localversion-grsec
95463new file mode 100644
95464index 0000000..7cd6065
95465--- /dev/null
95466+++ b/localversion-grsec
95467@@ -0,0 +1 @@
95468+-grsec
95469diff --git a/mm/Kconfig b/mm/Kconfig
95470index 886db21..f514de2 100644
95471--- a/mm/Kconfig
95472+++ b/mm/Kconfig
95473@@ -333,10 +333,11 @@ config KSM
95474 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
95475
95476 config DEFAULT_MMAP_MIN_ADDR
95477- int "Low address space to protect from user allocation"
95478+ int "Low address space to protect from user allocation"
95479 depends on MMU
95480- default 4096
95481- help
95482+ default 32768 if ALPHA || ARM || PARISC || SPARC32
95483+ default 65536
95484+ help
95485 This is the portion of low virtual memory which should be protected
95486 from userspace allocation. Keeping a user from writing to low pages
95487 can help reduce the impact of kernel NULL pointer bugs.
95488@@ -367,7 +368,7 @@ config MEMORY_FAILURE
95489
95490 config HWPOISON_INJECT
95491 tristate "HWPoison pages injector"
95492- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
95493+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
95494 select PROC_PAGE_MONITOR
95495
95496 config NOMMU_INITIAL_TRIM_EXCESS
95497diff --git a/mm/backing-dev.c b/mm/backing-dev.c
95498index 1706cbb..f89dbca 100644
95499--- a/mm/backing-dev.c
95500+++ b/mm/backing-dev.c
95501@@ -12,7 +12,7 @@
95502 #include <linux/device.h>
95503 #include <trace/events/writeback.h>
95504
95505-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
95506+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
95507
95508 struct backing_dev_info default_backing_dev_info = {
95509 .name = "default",
95510@@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
95511 return err;
95512
95513 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
95514- atomic_long_inc_return(&bdi_seq));
95515+ atomic_long_inc_return_unchecked(&bdi_seq));
95516 if (err) {
95517 bdi_destroy(bdi);
95518 return err;
95519diff --git a/mm/filemap.c b/mm/filemap.c
95520index 90effcd..539aa64 100644
95521--- a/mm/filemap.c
95522+++ b/mm/filemap.c
95523@@ -2092,7 +2092,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
95524 struct address_space *mapping = file->f_mapping;
95525
95526 if (!mapping->a_ops->readpage)
95527- return -ENOEXEC;
95528+ return -ENODEV;
95529 file_accessed(file);
95530 vma->vm_ops = &generic_file_vm_ops;
95531 return 0;
95532@@ -2270,6 +2270,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
95533 *pos = i_size_read(inode);
95534
95535 if (limit != RLIM_INFINITY) {
95536+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
95537 if (*pos >= limit) {
95538 send_sig(SIGXFSZ, current, 0);
95539 return -EFBIG;
95540diff --git a/mm/fremap.c b/mm/fremap.c
95541index 72b8fa3..c5b39f1 100644
95542--- a/mm/fremap.c
95543+++ b/mm/fremap.c
95544@@ -180,6 +180,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
95545 retry:
95546 vma = find_vma(mm, start);
95547
95548+#ifdef CONFIG_PAX_SEGMEXEC
95549+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
95550+ goto out;
95551+#endif
95552+
95553 /*
95554 * Make sure the vma is shared, that it supports prefaulting,
95555 * and that the remapped range is valid and fully within
95556diff --git a/mm/gup.c b/mm/gup.c
95557index 91d044b..a58ecf6 100644
95558--- a/mm/gup.c
95559+++ b/mm/gup.c
95560@@ -270,11 +270,6 @@ static int faultin_page(struct task_struct *tsk, struct vm_area_struct *vma,
95561 unsigned int fault_flags = 0;
95562 int ret;
95563
95564- /* For mlock, just skip the stack guard page. */
95565- if ((*flags & FOLL_MLOCK) &&
95566- (stack_guard_page_start(vma, address) ||
95567- stack_guard_page_end(vma, address + PAGE_SIZE)))
95568- return -ENOENT;
95569 if (*flags & FOLL_WRITE)
95570 fault_flags |= FAULT_FLAG_WRITE;
95571 if (nonblocking)
95572@@ -436,14 +431,14 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95573 if (!(gup_flags & FOLL_FORCE))
95574 gup_flags |= FOLL_NUMA;
95575
95576- do {
95577+ while (nr_pages) {
95578 struct page *page;
95579 unsigned int foll_flags = gup_flags;
95580 unsigned int page_increm;
95581
95582 /* first iteration or cross vma bound */
95583 if (!vma || start >= vma->vm_end) {
95584- vma = find_extend_vma(mm, start);
95585+ vma = find_vma(mm, start);
95586 if (!vma && in_gate_area(mm, start)) {
95587 int ret;
95588 ret = get_gate_page(mm, start & PAGE_MASK,
95589@@ -455,7 +450,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
95590 goto next_page;
95591 }
95592
95593- if (!vma || check_vma_flags(vma, gup_flags))
95594+ if (!vma || start < vma->vm_start || check_vma_flags(vma, gup_flags))
95595 return i ? : -EFAULT;
95596 if (is_vm_hugetlb_page(vma)) {
95597 i = follow_hugetlb_page(mm, vma, pages, vmas,
95598@@ -510,7 +505,7 @@ next_page:
95599 i += page_increm;
95600 start += page_increm * PAGE_SIZE;
95601 nr_pages -= page_increm;
95602- } while (nr_pages);
95603+ }
95604 return i;
95605 }
95606 EXPORT_SYMBOL(__get_user_pages);
95607diff --git a/mm/highmem.c b/mm/highmem.c
95608index 123bcd3..0de52ba 100644
95609--- a/mm/highmem.c
95610+++ b/mm/highmem.c
95611@@ -195,8 +195,9 @@ static void flush_all_zero_pkmaps(void)
95612 * So no dangers, even with speculative execution.
95613 */
95614 page = pte_page(pkmap_page_table[i]);
95615+ pax_open_kernel();
95616 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
95617-
95618+ pax_close_kernel();
95619 set_page_address(page, NULL);
95620 need_flush = 1;
95621 }
95622@@ -259,9 +260,11 @@ start:
95623 }
95624 }
95625 vaddr = PKMAP_ADDR(last_pkmap_nr);
95626+
95627+ pax_open_kernel();
95628 set_pte_at(&init_mm, vaddr,
95629 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
95630-
95631+ pax_close_kernel();
95632 pkmap_count[last_pkmap_nr] = 1;
95633 set_page_address(page, (void *)vaddr);
95634
95635diff --git a/mm/hugetlb.c b/mm/hugetlb.c
95636index eeceeeb..a209d58 100644
95637--- a/mm/hugetlb.c
95638+++ b/mm/hugetlb.c
95639@@ -2258,6 +2258,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95640 struct ctl_table *table, int write,
95641 void __user *buffer, size_t *length, loff_t *ppos)
95642 {
95643+ ctl_table_no_const t;
95644 struct hstate *h = &default_hstate;
95645 unsigned long tmp = h->max_huge_pages;
95646 int ret;
95647@@ -2265,9 +2266,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
95648 if (!hugepages_supported())
95649 return -ENOTSUPP;
95650
95651- table->data = &tmp;
95652- table->maxlen = sizeof(unsigned long);
95653- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95654+ t = *table;
95655+ t.data = &tmp;
95656+ t.maxlen = sizeof(unsigned long);
95657+ ret = proc_doulongvec_minmax(&t, write, buffer, length, ppos);
95658 if (ret)
95659 goto out;
95660
95661@@ -2302,6 +2304,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95662 struct hstate *h = &default_hstate;
95663 unsigned long tmp;
95664 int ret;
95665+ ctl_table_no_const hugetlb_table;
95666
95667 if (!hugepages_supported())
95668 return -ENOTSUPP;
95669@@ -2311,9 +2314,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
95670 if (write && hstate_is_gigantic(h))
95671 return -EINVAL;
95672
95673- table->data = &tmp;
95674- table->maxlen = sizeof(unsigned long);
95675- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
95676+ hugetlb_table = *table;
95677+ hugetlb_table.data = &tmp;
95678+ hugetlb_table.maxlen = sizeof(unsigned long);
95679+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
95680 if (ret)
95681 goto out;
95682
95683@@ -2792,6 +2796,27 @@ static void unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
95684 mutex_unlock(&mapping->i_mmap_mutex);
95685 }
95686
95687+#ifdef CONFIG_PAX_SEGMEXEC
95688+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
95689+{
95690+ struct mm_struct *mm = vma->vm_mm;
95691+ struct vm_area_struct *vma_m;
95692+ unsigned long address_m;
95693+ pte_t *ptep_m;
95694+
95695+ vma_m = pax_find_mirror_vma(vma);
95696+ if (!vma_m)
95697+ return;
95698+
95699+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
95700+ address_m = address + SEGMEXEC_TASK_SIZE;
95701+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
95702+ get_page(page_m);
95703+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
95704+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
95705+}
95706+#endif
95707+
95708 /*
95709 * Hugetlb_cow() should be called with page lock of the original hugepage held.
95710 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
95711@@ -2903,6 +2928,11 @@ retry_avoidcopy:
95712 make_huge_pte(vma, new_page, 1));
95713 page_remove_rmap(old_page);
95714 hugepage_add_new_anon_rmap(new_page, vma, address);
95715+
95716+#ifdef CONFIG_PAX_SEGMEXEC
95717+ pax_mirror_huge_pte(vma, address, new_page);
95718+#endif
95719+
95720 /* Make the old page be freed below */
95721 new_page = old_page;
95722 }
95723@@ -3063,6 +3093,10 @@ retry:
95724 && (vma->vm_flags & VM_SHARED)));
95725 set_huge_pte_at(mm, address, ptep, new_pte);
95726
95727+#ifdef CONFIG_PAX_SEGMEXEC
95728+ pax_mirror_huge_pte(vma, address, page);
95729+#endif
95730+
95731 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
95732 /* Optimization, do the COW without a second fault */
95733 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
95734@@ -3129,6 +3163,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95735 struct hstate *h = hstate_vma(vma);
95736 struct address_space *mapping;
95737
95738+#ifdef CONFIG_PAX_SEGMEXEC
95739+ struct vm_area_struct *vma_m;
95740+#endif
95741+
95742 address &= huge_page_mask(h);
95743
95744 ptep = huge_pte_offset(mm, address);
95745@@ -3142,6 +3180,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
95746 VM_FAULT_SET_HINDEX(hstate_index(h));
95747 }
95748
95749+#ifdef CONFIG_PAX_SEGMEXEC
95750+ vma_m = pax_find_mirror_vma(vma);
95751+ if (vma_m) {
95752+ unsigned long address_m;
95753+
95754+ if (vma->vm_start > vma_m->vm_start) {
95755+ address_m = address;
95756+ address -= SEGMEXEC_TASK_SIZE;
95757+ vma = vma_m;
95758+ h = hstate_vma(vma);
95759+ } else
95760+ address_m = address + SEGMEXEC_TASK_SIZE;
95761+
95762+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
95763+ return VM_FAULT_OOM;
95764+ address_m &= HPAGE_MASK;
95765+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
95766+ }
95767+#endif
95768+
95769 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
95770 if (!ptep)
95771 return VM_FAULT_OOM;
95772diff --git a/mm/internal.h b/mm/internal.h
95773index a1b651b..f688570 100644
95774--- a/mm/internal.h
95775+++ b/mm/internal.h
95776@@ -109,6 +109,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
95777 * in mm/page_alloc.c
95778 */
95779 extern void __free_pages_bootmem(struct page *page, unsigned int order);
95780+extern void free_compound_page(struct page *page);
95781 extern void prep_compound_page(struct page *page, unsigned long order);
95782 #ifdef CONFIG_MEMORY_FAILURE
95783 extern bool is_free_buddy_page(struct page *page);
95784@@ -351,7 +352,7 @@ extern u32 hwpoison_filter_enable;
95785
95786 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
95787 unsigned long, unsigned long,
95788- unsigned long, unsigned long);
95789+ unsigned long, unsigned long) __intentional_overflow(-1);
95790
95791 extern void set_pageblock_order(void);
95792 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
95793diff --git a/mm/iov_iter.c b/mm/iov_iter.c
95794index 9a09f20..6ef0515 100644
95795--- a/mm/iov_iter.c
95796+++ b/mm/iov_iter.c
95797@@ -173,7 +173,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
95798
95799 while (bytes) {
95800 char __user *buf = iov->iov_base + base;
95801- int copy = min(bytes, iov->iov_len - base);
95802+ size_t copy = min(bytes, iov->iov_len - base);
95803
95804 base = 0;
95805 left = __copy_from_user_inatomic(vaddr, buf, copy);
95806@@ -201,7 +201,7 @@ static size_t copy_from_user_atomic_iovec(struct page *page,
95807
95808 kaddr = kmap_atomic(page);
95809 if (likely(i->nr_segs == 1)) {
95810- int left;
95811+ size_t left;
95812 char __user *buf = i->iov->iov_base + i->iov_offset;
95813 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
95814 copied = bytes - left;
95815@@ -231,7 +231,7 @@ static void advance_iovec(struct iov_iter *i, size_t bytes)
95816 * zero-length segments (without overruning the iovec).
95817 */
95818 while (bytes || unlikely(i->count && !iov->iov_len)) {
95819- int copy;
95820+ size_t copy;
95821
95822 copy = min(bytes, iov->iov_len - base);
95823 BUG_ON(!i->count || i->count < copy);
95824diff --git a/mm/kmemleak.c b/mm/kmemleak.c
95825index 3cda50c..032ba634 100644
95826--- a/mm/kmemleak.c
95827+++ b/mm/kmemleak.c
95828@@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
95829
95830 for (i = 0; i < object->trace_len; i++) {
95831 void *ptr = (void *)object->trace[i];
95832- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
95833+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
95834 }
95835 }
95836
95837@@ -1905,7 +1905,7 @@ static int __init kmemleak_late_init(void)
95838 return -ENOMEM;
95839 }
95840
95841- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
95842+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
95843 &kmemleak_fops);
95844 if (!dentry)
95845 pr_warning("Failed to create the debugfs kmemleak file\n");
95846diff --git a/mm/maccess.c b/mm/maccess.c
95847index d53adf9..03a24bf 100644
95848--- a/mm/maccess.c
95849+++ b/mm/maccess.c
95850@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
95851 set_fs(KERNEL_DS);
95852 pagefault_disable();
95853 ret = __copy_from_user_inatomic(dst,
95854- (__force const void __user *)src, size);
95855+ (const void __force_user *)src, size);
95856 pagefault_enable();
95857 set_fs(old_fs);
95858
95859@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
95860
95861 set_fs(KERNEL_DS);
95862 pagefault_disable();
95863- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
95864+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
95865 pagefault_enable();
95866 set_fs(old_fs);
95867
95868diff --git a/mm/madvise.c b/mm/madvise.c
95869index 0938b30..199abe8 100644
95870--- a/mm/madvise.c
95871+++ b/mm/madvise.c
95872@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
95873 pgoff_t pgoff;
95874 unsigned long new_flags = vma->vm_flags;
95875
95876+#ifdef CONFIG_PAX_SEGMEXEC
95877+ struct vm_area_struct *vma_m;
95878+#endif
95879+
95880 switch (behavior) {
95881 case MADV_NORMAL:
95882 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
95883@@ -126,6 +130,13 @@ success:
95884 /*
95885 * vm_flags is protected by the mmap_sem held in write mode.
95886 */
95887+
95888+#ifdef CONFIG_PAX_SEGMEXEC
95889+ vma_m = pax_find_mirror_vma(vma);
95890+ if (vma_m)
95891+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
95892+#endif
95893+
95894 vma->vm_flags = new_flags;
95895
95896 out:
95897@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95898 struct vm_area_struct **prev,
95899 unsigned long start, unsigned long end)
95900 {
95901+
95902+#ifdef CONFIG_PAX_SEGMEXEC
95903+ struct vm_area_struct *vma_m;
95904+#endif
95905+
95906 *prev = vma;
95907 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
95908 return -EINVAL;
95909@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
95910 zap_page_range(vma, start, end - start, &details);
95911 } else
95912 zap_page_range(vma, start, end - start, NULL);
95913+
95914+#ifdef CONFIG_PAX_SEGMEXEC
95915+ vma_m = pax_find_mirror_vma(vma);
95916+ if (vma_m) {
95917+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
95918+ struct zap_details details = {
95919+ .nonlinear_vma = vma_m,
95920+ .last_index = ULONG_MAX,
95921+ };
95922+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
95923+ } else
95924+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
95925+ }
95926+#endif
95927+
95928 return 0;
95929 }
95930
95931@@ -488,6 +519,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
95932 if (end < start)
95933 return error;
95934
95935+#ifdef CONFIG_PAX_SEGMEXEC
95936+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95937+ if (end > SEGMEXEC_TASK_SIZE)
95938+ return error;
95939+ } else
95940+#endif
95941+
95942+ if (end > TASK_SIZE)
95943+ return error;
95944+
95945 error = 0;
95946 if (end == start)
95947 return error;
95948diff --git a/mm/memory-failure.c b/mm/memory-failure.c
95949index 44c6bd2..60369dc3 100644
95950--- a/mm/memory-failure.c
95951+++ b/mm/memory-failure.c
95952@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
95953
95954 int sysctl_memory_failure_recovery __read_mostly = 1;
95955
95956-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95957+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
95958
95959 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
95960
95961@@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
95962 pfn, t->comm, t->pid);
95963 si.si_signo = SIGBUS;
95964 si.si_errno = 0;
95965- si.si_addr = (void *)addr;
95966+ si.si_addr = (void __user *)addr;
95967 #ifdef __ARCH_SI_TRAPNO
95968 si.si_trapno = trapno;
95969 #endif
95970@@ -791,7 +791,7 @@ static struct page_state {
95971 unsigned long res;
95972 char *msg;
95973 int (*action)(struct page *p, unsigned long pfn);
95974-} error_states[] = {
95975+} __do_const error_states[] = {
95976 { reserved, reserved, "reserved kernel", me_kernel },
95977 /*
95978 * free pages are specially detected outside this table:
95979@@ -1099,7 +1099,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95980 nr_pages = 1 << compound_order(hpage);
95981 else /* normal page or thp */
95982 nr_pages = 1;
95983- atomic_long_add(nr_pages, &num_poisoned_pages);
95984+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
95985
95986 /*
95987 * We need/can do nothing about count=0 pages.
95988@@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95989 if (PageHWPoison(hpage)) {
95990 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
95991 || (p != hpage && TestSetPageHWPoison(hpage))) {
95992- atomic_long_sub(nr_pages, &num_poisoned_pages);
95993+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
95994 unlock_page(hpage);
95995 return 0;
95996 }
95997@@ -1196,14 +1196,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
95998 */
95999 if (!PageHWPoison(p)) {
96000 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
96001- atomic_long_sub(nr_pages, &num_poisoned_pages);
96002+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96003 put_page(hpage);
96004 res = 0;
96005 goto out;
96006 }
96007 if (hwpoison_filter(p)) {
96008 if (TestClearPageHWPoison(p))
96009- atomic_long_sub(nr_pages, &num_poisoned_pages);
96010+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96011 unlock_page(hpage);
96012 put_page(hpage);
96013 return 0;
96014@@ -1433,7 +1433,7 @@ int unpoison_memory(unsigned long pfn)
96015 return 0;
96016 }
96017 if (TestClearPageHWPoison(p))
96018- atomic_long_dec(&num_poisoned_pages);
96019+ atomic_long_dec_unchecked(&num_poisoned_pages);
96020 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
96021 return 0;
96022 }
96023@@ -1447,7 +1447,7 @@ int unpoison_memory(unsigned long pfn)
96024 */
96025 if (TestClearPageHWPoison(page)) {
96026 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
96027- atomic_long_sub(nr_pages, &num_poisoned_pages);
96028+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
96029 freeit = 1;
96030 if (PageHuge(page))
96031 clear_page_hwpoison_huge_page(page);
96032@@ -1572,11 +1572,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
96033 if (PageHuge(page)) {
96034 set_page_hwpoison_huge_page(hpage);
96035 dequeue_hwpoisoned_huge_page(hpage);
96036- atomic_long_add(1 << compound_order(hpage),
96037+ atomic_long_add_unchecked(1 << compound_order(hpage),
96038 &num_poisoned_pages);
96039 } else {
96040 SetPageHWPoison(page);
96041- atomic_long_inc(&num_poisoned_pages);
96042+ atomic_long_inc_unchecked(&num_poisoned_pages);
96043 }
96044 }
96045 return ret;
96046@@ -1615,7 +1615,7 @@ static int __soft_offline_page(struct page *page, int flags)
96047 put_page(page);
96048 pr_info("soft_offline: %#lx: invalidated\n", pfn);
96049 SetPageHWPoison(page);
96050- atomic_long_inc(&num_poisoned_pages);
96051+ atomic_long_inc_unchecked(&num_poisoned_pages);
96052 return 0;
96053 }
96054
96055@@ -1666,7 +1666,7 @@ static int __soft_offline_page(struct page *page, int flags)
96056 if (!is_free_buddy_page(page))
96057 pr_info("soft offline: %#lx: page leaked\n",
96058 pfn);
96059- atomic_long_inc(&num_poisoned_pages);
96060+ atomic_long_inc_unchecked(&num_poisoned_pages);
96061 }
96062 } else {
96063 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
96064@@ -1736,11 +1736,11 @@ int soft_offline_page(struct page *page, int flags)
96065 if (PageHuge(page)) {
96066 set_page_hwpoison_huge_page(hpage);
96067 dequeue_hwpoisoned_huge_page(hpage);
96068- atomic_long_add(1 << compound_order(hpage),
96069+ atomic_long_add_unchecked(1 << compound_order(hpage),
96070 &num_poisoned_pages);
96071 } else {
96072 SetPageHWPoison(page);
96073- atomic_long_inc(&num_poisoned_pages);
96074+ atomic_long_inc_unchecked(&num_poisoned_pages);
96075 }
96076 }
96077 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
96078diff --git a/mm/memory.c b/mm/memory.c
96079index 37b80fc..68218aa 100644
96080--- a/mm/memory.c
96081+++ b/mm/memory.c
96082@@ -415,6 +415,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96083 free_pte_range(tlb, pmd, addr);
96084 } while (pmd++, addr = next, addr != end);
96085
96086+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
96087 start &= PUD_MASK;
96088 if (start < floor)
96089 return;
96090@@ -429,6 +430,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
96091 pmd = pmd_offset(pud, start);
96092 pud_clear(pud);
96093 pmd_free_tlb(tlb, pmd, start);
96094+#endif
96095+
96096 }
96097
96098 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96099@@ -448,6 +451,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96100 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
96101 } while (pud++, addr = next, addr != end);
96102
96103+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
96104 start &= PGDIR_MASK;
96105 if (start < floor)
96106 return;
96107@@ -462,6 +466,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
96108 pud = pud_offset(pgd, start);
96109 pgd_clear(pgd);
96110 pud_free_tlb(tlb, pud, start);
96111+#endif
96112+
96113 }
96114
96115 /*
96116@@ -691,10 +697,10 @@ static void print_bad_pte(struct vm_area_struct *vma, unsigned long addr,
96117 * Choose text because data symbols depend on CONFIG_KALLSYMS_ALL=y
96118 */
96119 if (vma->vm_ops)
96120- printk(KERN_ALERT "vma->vm_ops->fault: %pSR\n",
96121+ printk(KERN_ALERT "vma->vm_ops->fault: %pAR\n",
96122 vma->vm_ops->fault);
96123 if (vma->vm_file)
96124- printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pSR\n",
96125+ printk(KERN_ALERT "vma->vm_file->f_op->mmap: %pAR\n",
96126 vma->vm_file->f_op->mmap);
96127 dump_stack();
96128 add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
96129@@ -1501,6 +1507,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
96130 page_add_file_rmap(page);
96131 set_pte_at(mm, addr, pte, mk_pte(page, prot));
96132
96133+#ifdef CONFIG_PAX_SEGMEXEC
96134+ pax_mirror_file_pte(vma, addr, page, ptl);
96135+#endif
96136+
96137 retval = 0;
96138 pte_unmap_unlock(pte, ptl);
96139 return retval;
96140@@ -1545,9 +1555,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
96141 if (!page_count(page))
96142 return -EINVAL;
96143 if (!(vma->vm_flags & VM_MIXEDMAP)) {
96144+
96145+#ifdef CONFIG_PAX_SEGMEXEC
96146+ struct vm_area_struct *vma_m;
96147+#endif
96148+
96149 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
96150 BUG_ON(vma->vm_flags & VM_PFNMAP);
96151 vma->vm_flags |= VM_MIXEDMAP;
96152+
96153+#ifdef CONFIG_PAX_SEGMEXEC
96154+ vma_m = pax_find_mirror_vma(vma);
96155+ if (vma_m)
96156+ vma_m->vm_flags |= VM_MIXEDMAP;
96157+#endif
96158+
96159 }
96160 return insert_page(vma, addr, page, vma->vm_page_prot);
96161 }
96162@@ -1630,6 +1652,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
96163 unsigned long pfn)
96164 {
96165 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
96166+ BUG_ON(vma->vm_mirror);
96167
96168 if (addr < vma->vm_start || addr >= vma->vm_end)
96169 return -EFAULT;
96170@@ -1877,7 +1900,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
96171
96172 BUG_ON(pud_huge(*pud));
96173
96174- pmd = pmd_alloc(mm, pud, addr);
96175+ pmd = (mm == &init_mm) ?
96176+ pmd_alloc_kernel(mm, pud, addr) :
96177+ pmd_alloc(mm, pud, addr);
96178 if (!pmd)
96179 return -ENOMEM;
96180 do {
96181@@ -1897,7 +1922,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
96182 unsigned long next;
96183 int err;
96184
96185- pud = pud_alloc(mm, pgd, addr);
96186+ pud = (mm == &init_mm) ?
96187+ pud_alloc_kernel(mm, pgd, addr) :
96188+ pud_alloc(mm, pgd, addr);
96189 if (!pud)
96190 return -ENOMEM;
96191 do {
96192@@ -2019,6 +2046,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
96193 return ret;
96194 }
96195
96196+#ifdef CONFIG_PAX_SEGMEXEC
96197+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
96198+{
96199+ struct mm_struct *mm = vma->vm_mm;
96200+ spinlock_t *ptl;
96201+ pte_t *pte, entry;
96202+
96203+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
96204+ entry = *pte;
96205+ if (!pte_present(entry)) {
96206+ if (!pte_none(entry)) {
96207+ BUG_ON(pte_file(entry));
96208+ free_swap_and_cache(pte_to_swp_entry(entry));
96209+ pte_clear_not_present_full(mm, address, pte, 0);
96210+ }
96211+ } else {
96212+ struct page *page;
96213+
96214+ flush_cache_page(vma, address, pte_pfn(entry));
96215+ entry = ptep_clear_flush(vma, address, pte);
96216+ BUG_ON(pte_dirty(entry));
96217+ page = vm_normal_page(vma, address, entry);
96218+ if (page) {
96219+ update_hiwater_rss(mm);
96220+ if (PageAnon(page))
96221+ dec_mm_counter_fast(mm, MM_ANONPAGES);
96222+ else
96223+ dec_mm_counter_fast(mm, MM_FILEPAGES);
96224+ page_remove_rmap(page);
96225+ page_cache_release(page);
96226+ }
96227+ }
96228+ pte_unmap_unlock(pte, ptl);
96229+}
96230+
96231+/* PaX: if vma is mirrored, synchronize the mirror's PTE
96232+ *
96233+ * the ptl of the lower mapped page is held on entry and is not released on exit
96234+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
96235+ */
96236+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96237+{
96238+ struct mm_struct *mm = vma->vm_mm;
96239+ unsigned long address_m;
96240+ spinlock_t *ptl_m;
96241+ struct vm_area_struct *vma_m;
96242+ pmd_t *pmd_m;
96243+ pte_t *pte_m, entry_m;
96244+
96245+ BUG_ON(!page_m || !PageAnon(page_m));
96246+
96247+ vma_m = pax_find_mirror_vma(vma);
96248+ if (!vma_m)
96249+ return;
96250+
96251+ BUG_ON(!PageLocked(page_m));
96252+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96253+ address_m = address + SEGMEXEC_TASK_SIZE;
96254+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96255+ pte_m = pte_offset_map(pmd_m, address_m);
96256+ ptl_m = pte_lockptr(mm, pmd_m);
96257+ if (ptl != ptl_m) {
96258+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96259+ if (!pte_none(*pte_m))
96260+ goto out;
96261+ }
96262+
96263+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96264+ page_cache_get(page_m);
96265+ page_add_anon_rmap(page_m, vma_m, address_m);
96266+ inc_mm_counter_fast(mm, MM_ANONPAGES);
96267+ set_pte_at(mm, address_m, pte_m, entry_m);
96268+ update_mmu_cache(vma_m, address_m, pte_m);
96269+out:
96270+ if (ptl != ptl_m)
96271+ spin_unlock(ptl_m);
96272+ pte_unmap(pte_m);
96273+ unlock_page(page_m);
96274+}
96275+
96276+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
96277+{
96278+ struct mm_struct *mm = vma->vm_mm;
96279+ unsigned long address_m;
96280+ spinlock_t *ptl_m;
96281+ struct vm_area_struct *vma_m;
96282+ pmd_t *pmd_m;
96283+ pte_t *pte_m, entry_m;
96284+
96285+ BUG_ON(!page_m || PageAnon(page_m));
96286+
96287+ vma_m = pax_find_mirror_vma(vma);
96288+ if (!vma_m)
96289+ return;
96290+
96291+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96292+ address_m = address + SEGMEXEC_TASK_SIZE;
96293+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96294+ pte_m = pte_offset_map(pmd_m, address_m);
96295+ ptl_m = pte_lockptr(mm, pmd_m);
96296+ if (ptl != ptl_m) {
96297+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96298+ if (!pte_none(*pte_m))
96299+ goto out;
96300+ }
96301+
96302+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
96303+ page_cache_get(page_m);
96304+ page_add_file_rmap(page_m);
96305+ inc_mm_counter_fast(mm, MM_FILEPAGES);
96306+ set_pte_at(mm, address_m, pte_m, entry_m);
96307+ update_mmu_cache(vma_m, address_m, pte_m);
96308+out:
96309+ if (ptl != ptl_m)
96310+ spin_unlock(ptl_m);
96311+ pte_unmap(pte_m);
96312+}
96313+
96314+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
96315+{
96316+ struct mm_struct *mm = vma->vm_mm;
96317+ unsigned long address_m;
96318+ spinlock_t *ptl_m;
96319+ struct vm_area_struct *vma_m;
96320+ pmd_t *pmd_m;
96321+ pte_t *pte_m, entry_m;
96322+
96323+ vma_m = pax_find_mirror_vma(vma);
96324+ if (!vma_m)
96325+ return;
96326+
96327+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
96328+ address_m = address + SEGMEXEC_TASK_SIZE;
96329+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
96330+ pte_m = pte_offset_map(pmd_m, address_m);
96331+ ptl_m = pte_lockptr(mm, pmd_m);
96332+ if (ptl != ptl_m) {
96333+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
96334+ if (!pte_none(*pte_m))
96335+ goto out;
96336+ }
96337+
96338+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
96339+ set_pte_at(mm, address_m, pte_m, entry_m);
96340+out:
96341+ if (ptl != ptl_m)
96342+ spin_unlock(ptl_m);
96343+ pte_unmap(pte_m);
96344+}
96345+
96346+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
96347+{
96348+ struct page *page_m;
96349+ pte_t entry;
96350+
96351+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
96352+ goto out;
96353+
96354+ entry = *pte;
96355+ page_m = vm_normal_page(vma, address, entry);
96356+ if (!page_m)
96357+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
96358+ else if (PageAnon(page_m)) {
96359+ if (pax_find_mirror_vma(vma)) {
96360+ pte_unmap_unlock(pte, ptl);
96361+ lock_page(page_m);
96362+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
96363+ if (pte_same(entry, *pte))
96364+ pax_mirror_anon_pte(vma, address, page_m, ptl);
96365+ else
96366+ unlock_page(page_m);
96367+ }
96368+ } else
96369+ pax_mirror_file_pte(vma, address, page_m, ptl);
96370+
96371+out:
96372+ pte_unmap_unlock(pte, ptl);
96373+}
96374+#endif
96375+
96376 /*
96377 * This routine handles present pages, when users try to write
96378 * to a shared page. It is done by copying the page to a new address
96379@@ -2217,6 +2424,12 @@ gotten:
96380 */
96381 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96382 if (likely(pte_same(*page_table, orig_pte))) {
96383+
96384+#ifdef CONFIG_PAX_SEGMEXEC
96385+ if (pax_find_mirror_vma(vma))
96386+ BUG_ON(!trylock_page(new_page));
96387+#endif
96388+
96389 if (old_page) {
96390 if (!PageAnon(old_page)) {
96391 dec_mm_counter_fast(mm, MM_FILEPAGES);
96392@@ -2270,6 +2483,10 @@ gotten:
96393 page_remove_rmap(old_page);
96394 }
96395
96396+#ifdef CONFIG_PAX_SEGMEXEC
96397+ pax_mirror_anon_pte(vma, address, new_page, ptl);
96398+#endif
96399+
96400 /* Free the old page.. */
96401 new_page = old_page;
96402 ret |= VM_FAULT_WRITE;
96403@@ -2544,6 +2761,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96404 swap_free(entry);
96405 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
96406 try_to_free_swap(page);
96407+
96408+#ifdef CONFIG_PAX_SEGMEXEC
96409+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
96410+#endif
96411+
96412 unlock_page(page);
96413 if (page != swapcache) {
96414 /*
96415@@ -2567,6 +2789,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
96416
96417 /* No need to invalidate - it was non-present before */
96418 update_mmu_cache(vma, address, page_table);
96419+
96420+#ifdef CONFIG_PAX_SEGMEXEC
96421+ pax_mirror_anon_pte(vma, address, page, ptl);
96422+#endif
96423+
96424 unlock:
96425 pte_unmap_unlock(page_table, ptl);
96426 out:
96427@@ -2586,40 +2813,6 @@ out_release:
96428 }
96429
96430 /*
96431- * This is like a special single-page "expand_{down|up}wards()",
96432- * except we must first make sure that 'address{-|+}PAGE_SIZE'
96433- * doesn't hit another vma.
96434- */
96435-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
96436-{
96437- address &= PAGE_MASK;
96438- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
96439- struct vm_area_struct *prev = vma->vm_prev;
96440-
96441- /*
96442- * Is there a mapping abutting this one below?
96443- *
96444- * That's only ok if it's the same stack mapping
96445- * that has gotten split..
96446- */
96447- if (prev && prev->vm_end == address)
96448- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
96449-
96450- expand_downwards(vma, address - PAGE_SIZE);
96451- }
96452- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
96453- struct vm_area_struct *next = vma->vm_next;
96454-
96455- /* As VM_GROWSDOWN but s/below/above/ */
96456- if (next && next->vm_start == address + PAGE_SIZE)
96457- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
96458-
96459- expand_upwards(vma, address + PAGE_SIZE);
96460- }
96461- return 0;
96462-}
96463-
96464-/*
96465 * We enter with non-exclusive mmap_sem (to exclude vma changes,
96466 * but allow concurrent faults), and pte mapped but not yet locked.
96467 * We return with mmap_sem still held, but pte unmapped and unlocked.
96468@@ -2629,27 +2822,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96469 unsigned int flags)
96470 {
96471 struct mem_cgroup *memcg;
96472- struct page *page;
96473+ struct page *page = NULL;
96474 spinlock_t *ptl;
96475 pte_t entry;
96476
96477- pte_unmap(page_table);
96478-
96479- /* Check if we need to add a guard page to the stack */
96480- if (check_stack_guard_page(vma, address) < 0)
96481- return VM_FAULT_SIGBUS;
96482-
96483- /* Use the zero-page for reads */
96484 if (!(flags & FAULT_FLAG_WRITE)) {
96485 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
96486 vma->vm_page_prot));
96487- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
96488+ ptl = pte_lockptr(mm, pmd);
96489+ spin_lock(ptl);
96490 if (!pte_none(*page_table))
96491 goto unlock;
96492 goto setpte;
96493 }
96494
96495 /* Allocate our own private page. */
96496+ pte_unmap(page_table);
96497+
96498 if (unlikely(anon_vma_prepare(vma)))
96499 goto oom;
96500 page = alloc_zeroed_user_highpage_movable(vma, address);
96501@@ -2673,6 +2862,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
96502 if (!pte_none(*page_table))
96503 goto release;
96504
96505+#ifdef CONFIG_PAX_SEGMEXEC
96506+ if (pax_find_mirror_vma(vma))
96507+ BUG_ON(!trylock_page(page));
96508+#endif
96509+
96510 inc_mm_counter_fast(mm, MM_ANONPAGES);
96511 page_add_new_anon_rmap(page, vma, address);
96512 mem_cgroup_commit_charge(page, memcg, false);
96513@@ -2682,6 +2876,12 @@ setpte:
96514
96515 /* No need to invalidate - it was non-present before */
96516 update_mmu_cache(vma, address, page_table);
96517+
96518+#ifdef CONFIG_PAX_SEGMEXEC
96519+ if (page)
96520+ pax_mirror_anon_pte(vma, address, page, ptl);
96521+#endif
96522+
96523 unlock:
96524 pte_unmap_unlock(page_table, ptl);
96525 return 0;
96526@@ -2912,6 +3112,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96527 return ret;
96528 }
96529 do_set_pte(vma, address, fault_page, pte, false, false);
96530+
96531+#ifdef CONFIG_PAX_SEGMEXEC
96532+ pax_mirror_file_pte(vma, address, fault_page, ptl);
96533+#endif
96534+
96535 unlock_page(fault_page);
96536 unlock_out:
96537 pte_unmap_unlock(pte, ptl);
96538@@ -2954,7 +3159,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96539 page_cache_release(fault_page);
96540 goto uncharge_out;
96541 }
96542+
96543+#ifdef CONFIG_PAX_SEGMEXEC
96544+ if (pax_find_mirror_vma(vma))
96545+ BUG_ON(!trylock_page(new_page));
96546+#endif
96547+
96548 do_set_pte(vma, address, new_page, pte, true, true);
96549+
96550+#ifdef CONFIG_PAX_SEGMEXEC
96551+ pax_mirror_anon_pte(vma, address, new_page, ptl);
96552+#endif
96553+
96554 mem_cgroup_commit_charge(new_page, memcg, false);
96555 lru_cache_add_active_or_unevictable(new_page, vma);
96556 pte_unmap_unlock(pte, ptl);
96557@@ -3004,6 +3220,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96558 return ret;
96559 }
96560 do_set_pte(vma, address, fault_page, pte, true, false);
96561+
96562+#ifdef CONFIG_PAX_SEGMEXEC
96563+ pax_mirror_file_pte(vma, address, fault_page, ptl);
96564+#endif
96565+
96566 pte_unmap_unlock(pte, ptl);
96567
96568 if (set_page_dirty(fault_page))
96569@@ -3245,6 +3466,12 @@ static int handle_pte_fault(struct mm_struct *mm,
96570 if (flags & FAULT_FLAG_WRITE)
96571 flush_tlb_fix_spurious_fault(vma, address);
96572 }
96573+
96574+#ifdef CONFIG_PAX_SEGMEXEC
96575+ pax_mirror_pte(vma, address, pte, pmd, ptl);
96576+ return 0;
96577+#endif
96578+
96579 unlock:
96580 pte_unmap_unlock(pte, ptl);
96581 return 0;
96582@@ -3264,9 +3491,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
96583 pmd_t *pmd;
96584 pte_t *pte;
96585
96586+#ifdef CONFIG_PAX_SEGMEXEC
96587+ struct vm_area_struct *vma_m;
96588+#endif
96589+
96590 if (unlikely(is_vm_hugetlb_page(vma)))
96591 return hugetlb_fault(mm, vma, address, flags);
96592
96593+#ifdef CONFIG_PAX_SEGMEXEC
96594+ vma_m = pax_find_mirror_vma(vma);
96595+ if (vma_m) {
96596+ unsigned long address_m;
96597+ pgd_t *pgd_m;
96598+ pud_t *pud_m;
96599+ pmd_t *pmd_m;
96600+
96601+ if (vma->vm_start > vma_m->vm_start) {
96602+ address_m = address;
96603+ address -= SEGMEXEC_TASK_SIZE;
96604+ vma = vma_m;
96605+ } else
96606+ address_m = address + SEGMEXEC_TASK_SIZE;
96607+
96608+ pgd_m = pgd_offset(mm, address_m);
96609+ pud_m = pud_alloc(mm, pgd_m, address_m);
96610+ if (!pud_m)
96611+ return VM_FAULT_OOM;
96612+ pmd_m = pmd_alloc(mm, pud_m, address_m);
96613+ if (!pmd_m)
96614+ return VM_FAULT_OOM;
96615+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
96616+ return VM_FAULT_OOM;
96617+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
96618+ }
96619+#endif
96620+
96621 pgd = pgd_offset(mm, address);
96622 pud = pud_alloc(mm, pgd, address);
96623 if (!pud)
96624@@ -3400,6 +3659,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96625 spin_unlock(&mm->page_table_lock);
96626 return 0;
96627 }
96628+
96629+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
96630+{
96631+ pud_t *new = pud_alloc_one(mm, address);
96632+ if (!new)
96633+ return -ENOMEM;
96634+
96635+ smp_wmb(); /* See comment in __pte_alloc */
96636+
96637+ spin_lock(&mm->page_table_lock);
96638+ if (pgd_present(*pgd)) /* Another has populated it */
96639+ pud_free(mm, new);
96640+ else
96641+ pgd_populate_kernel(mm, pgd, new);
96642+ spin_unlock(&mm->page_table_lock);
96643+ return 0;
96644+}
96645 #endif /* __PAGETABLE_PUD_FOLDED */
96646
96647 #ifndef __PAGETABLE_PMD_FOLDED
96648@@ -3430,6 +3706,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
96649 spin_unlock(&mm->page_table_lock);
96650 return 0;
96651 }
96652+
96653+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
96654+{
96655+ pmd_t *new = pmd_alloc_one(mm, address);
96656+ if (!new)
96657+ return -ENOMEM;
96658+
96659+ smp_wmb(); /* See comment in __pte_alloc */
96660+
96661+ spin_lock(&mm->page_table_lock);
96662+#ifndef __ARCH_HAS_4LEVEL_HACK
96663+ if (pud_present(*pud)) /* Another has populated it */
96664+ pmd_free(mm, new);
96665+ else
96666+ pud_populate_kernel(mm, pud, new);
96667+#else
96668+ if (pgd_present(*pud)) /* Another has populated it */
96669+ pmd_free(mm, new);
96670+ else
96671+ pgd_populate_kernel(mm, pud, new);
96672+#endif /* __ARCH_HAS_4LEVEL_HACK */
96673+ spin_unlock(&mm->page_table_lock);
96674+ return 0;
96675+}
96676 #endif /* __PAGETABLE_PMD_FOLDED */
96677
96678 static int __follow_pte(struct mm_struct *mm, unsigned long address,
96679@@ -3539,8 +3839,8 @@ out:
96680 return ret;
96681 }
96682
96683-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96684- void *buf, int len, int write)
96685+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
96686+ void *buf, size_t len, int write)
96687 {
96688 resource_size_t phys_addr;
96689 unsigned long prot = 0;
96690@@ -3566,8 +3866,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
96691 * Access another process' address space as given in mm. If non-NULL, use the
96692 * given task for page fault accounting.
96693 */
96694-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96695- unsigned long addr, void *buf, int len, int write)
96696+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96697+ unsigned long addr, void *buf, size_t len, int write)
96698 {
96699 struct vm_area_struct *vma;
96700 void *old_buf = buf;
96701@@ -3575,7 +3875,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96702 down_read(&mm->mmap_sem);
96703 /* ignore errors, just check how much was successfully transferred */
96704 while (len) {
96705- int bytes, ret, offset;
96706+ ssize_t bytes, ret, offset;
96707 void *maddr;
96708 struct page *page = NULL;
96709
96710@@ -3636,8 +3936,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
96711 *
96712 * The caller must hold a reference on @mm.
96713 */
96714-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96715- void *buf, int len, int write)
96716+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
96717+ void *buf, size_t len, int write)
96718 {
96719 return __access_remote_vm(NULL, mm, addr, buf, len, write);
96720 }
96721@@ -3647,11 +3947,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
96722 * Source/target buffer must be kernel space,
96723 * Do not walk the page table directly, use get_user_pages
96724 */
96725-int access_process_vm(struct task_struct *tsk, unsigned long addr,
96726- void *buf, int len, int write)
96727+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
96728+ void *buf, size_t len, int write)
96729 {
96730 struct mm_struct *mm;
96731- int ret;
96732+ ssize_t ret;
96733
96734 mm = get_task_mm(tsk);
96735 if (!mm)
96736diff --git a/mm/mempolicy.c b/mm/mempolicy.c
96737index 8f5330d..b41914b 100644
96738--- a/mm/mempolicy.c
96739+++ b/mm/mempolicy.c
96740@@ -750,6 +750,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96741 unsigned long vmstart;
96742 unsigned long vmend;
96743
96744+#ifdef CONFIG_PAX_SEGMEXEC
96745+ struct vm_area_struct *vma_m;
96746+#endif
96747+
96748 vma = find_vma(mm, start);
96749 if (!vma || vma->vm_start > start)
96750 return -EFAULT;
96751@@ -793,6 +797,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
96752 err = vma_replace_policy(vma, new_pol);
96753 if (err)
96754 goto out;
96755+
96756+#ifdef CONFIG_PAX_SEGMEXEC
96757+ vma_m = pax_find_mirror_vma(vma);
96758+ if (vma_m) {
96759+ err = vma_replace_policy(vma_m, new_pol);
96760+ if (err)
96761+ goto out;
96762+ }
96763+#endif
96764+
96765 }
96766
96767 out:
96768@@ -1225,6 +1239,17 @@ static long do_mbind(unsigned long start, unsigned long len,
96769
96770 if (end < start)
96771 return -EINVAL;
96772+
96773+#ifdef CONFIG_PAX_SEGMEXEC
96774+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
96775+ if (end > SEGMEXEC_TASK_SIZE)
96776+ return -EINVAL;
96777+ } else
96778+#endif
96779+
96780+ if (end > TASK_SIZE)
96781+ return -EINVAL;
96782+
96783 if (end == start)
96784 return 0;
96785
96786@@ -1450,8 +1475,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96787 */
96788 tcred = __task_cred(task);
96789 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96790- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96791- !capable(CAP_SYS_NICE)) {
96792+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96793 rcu_read_unlock();
96794 err = -EPERM;
96795 goto out_put;
96796@@ -1482,6 +1506,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
96797 goto out;
96798 }
96799
96800+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96801+ if (mm != current->mm &&
96802+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
96803+ mmput(mm);
96804+ err = -EPERM;
96805+ goto out;
96806+ }
96807+#endif
96808+
96809 err = do_migrate_pages(mm, old, new,
96810 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
96811
96812diff --git a/mm/migrate.c b/mm/migrate.c
96813index 0143995..b294728 100644
96814--- a/mm/migrate.c
96815+++ b/mm/migrate.c
96816@@ -1495,8 +1495,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
96817 */
96818 tcred = __task_cred(task);
96819 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
96820- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
96821- !capable(CAP_SYS_NICE)) {
96822+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
96823 rcu_read_unlock();
96824 err = -EPERM;
96825 goto out;
96826diff --git a/mm/mlock.c b/mm/mlock.c
96827index ce84cb0..6d5a9aa 100644
96828--- a/mm/mlock.c
96829+++ b/mm/mlock.c
96830@@ -14,6 +14,7 @@
96831 #include <linux/pagevec.h>
96832 #include <linux/mempolicy.h>
96833 #include <linux/syscalls.h>
96834+#include <linux/security.h>
96835 #include <linux/sched.h>
96836 #include <linux/export.h>
96837 #include <linux/rmap.h>
96838@@ -613,7 +614,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
96839 {
96840 unsigned long nstart, end, tmp;
96841 struct vm_area_struct * vma, * prev;
96842- int error;
96843+ int error = 0;
96844
96845 VM_BUG_ON(start & ~PAGE_MASK);
96846 VM_BUG_ON(len != PAGE_ALIGN(len));
96847@@ -622,6 +623,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
96848 return -EINVAL;
96849 if (end == start)
96850 return 0;
96851+ if (end > TASK_SIZE)
96852+ return -EINVAL;
96853+
96854 vma = find_vma(current->mm, start);
96855 if (!vma || vma->vm_start > start)
96856 return -ENOMEM;
96857@@ -633,6 +637,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
96858 for (nstart = start ; ; ) {
96859 vm_flags_t newflags;
96860
96861+#ifdef CONFIG_PAX_SEGMEXEC
96862+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96863+ break;
96864+#endif
96865+
96866 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
96867
96868 newflags = vma->vm_flags & ~VM_LOCKED;
96869@@ -746,6 +755,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
96870 locked += current->mm->locked_vm;
96871
96872 /* check against resource limits */
96873+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
96874 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
96875 error = do_mlock(start, len, 1);
96876
96877@@ -783,6 +793,11 @@ static int do_mlockall(int flags)
96878 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
96879 vm_flags_t newflags;
96880
96881+#ifdef CONFIG_PAX_SEGMEXEC
96882+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
96883+ break;
96884+#endif
96885+
96886 newflags = vma->vm_flags & ~VM_LOCKED;
96887 if (flags & MCL_CURRENT)
96888 newflags |= VM_LOCKED;
96889@@ -814,8 +829,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
96890 lock_limit >>= PAGE_SHIFT;
96891
96892 ret = -ENOMEM;
96893+
96894+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
96895+
96896 down_write(&current->mm->mmap_sem);
96897-
96898 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
96899 capable(CAP_IPC_LOCK))
96900 ret = do_mlockall(flags);
96901diff --git a/mm/mmap.c b/mm/mmap.c
96902index c0a3637..c760814 100644
96903--- a/mm/mmap.c
96904+++ b/mm/mmap.c
96905@@ -41,6 +41,7 @@
96906 #include <linux/notifier.h>
96907 #include <linux/memory.h>
96908 #include <linux/printk.h>
96909+#include <linux/random.h>
96910
96911 #include <asm/uaccess.h>
96912 #include <asm/cacheflush.h>
96913@@ -57,6 +58,16 @@
96914 #define arch_rebalance_pgtables(addr, len) (addr)
96915 #endif
96916
96917+static inline void verify_mm_writelocked(struct mm_struct *mm)
96918+{
96919+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
96920+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
96921+ up_read(&mm->mmap_sem);
96922+ BUG();
96923+ }
96924+#endif
96925+}
96926+
96927 static void unmap_region(struct mm_struct *mm,
96928 struct vm_area_struct *vma, struct vm_area_struct *prev,
96929 unsigned long start, unsigned long end);
96930@@ -76,16 +87,25 @@ static void unmap_region(struct mm_struct *mm,
96931 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
96932 *
96933 */
96934-pgprot_t protection_map[16] = {
96935+pgprot_t protection_map[16] __read_only = {
96936 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
96937 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
96938 };
96939
96940-pgprot_t vm_get_page_prot(unsigned long vm_flags)
96941+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
96942 {
96943- return __pgprot(pgprot_val(protection_map[vm_flags &
96944+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
96945 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
96946 pgprot_val(arch_vm_get_page_prot(vm_flags)));
96947+
96948+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
96949+ if (!(__supported_pte_mask & _PAGE_NX) &&
96950+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
96951+ (vm_flags & (VM_READ | VM_WRITE)))
96952+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
96953+#endif
96954+
96955+ return prot;
96956 }
96957 EXPORT_SYMBOL(vm_get_page_prot);
96958
96959@@ -95,6 +115,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
96960 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
96961 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
96962 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
96963+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
96964 /*
96965 * Make sure vm_committed_as in one cacheline and not cacheline shared with
96966 * other variables. It can be updated by several CPUs frequently.
96967@@ -255,6 +276,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
96968 struct vm_area_struct *next = vma->vm_next;
96969
96970 might_sleep();
96971+ BUG_ON(vma->vm_mirror);
96972 if (vma->vm_ops && vma->vm_ops->close)
96973 vma->vm_ops->close(vma);
96974 if (vma->vm_file)
96975@@ -299,6 +321,12 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
96976 * not page aligned -Ram Gupta
96977 */
96978 rlim = rlimit(RLIMIT_DATA);
96979+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
96980+ /* force a minimum 16MB brk heap on setuid/setgid binaries */
96981+ if (rlim < PAGE_SIZE && (get_dumpable(mm) != SUID_DUMP_USER) && gr_is_global_nonroot(current_uid()))
96982+ rlim = 4096 * PAGE_SIZE;
96983+#endif
96984+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
96985 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
96986 (mm->end_data - mm->start_data) > rlim)
96987 goto out;
96988@@ -949,6 +977,12 @@ static int
96989 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
96990 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
96991 {
96992+
96993+#ifdef CONFIG_PAX_SEGMEXEC
96994+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
96995+ return 0;
96996+#endif
96997+
96998 if (is_mergeable_vma(vma, file, vm_flags) &&
96999 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
97000 if (vma->vm_pgoff == vm_pgoff)
97001@@ -968,6 +1002,12 @@ static int
97002 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
97003 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
97004 {
97005+
97006+#ifdef CONFIG_PAX_SEGMEXEC
97007+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
97008+ return 0;
97009+#endif
97010+
97011 if (is_mergeable_vma(vma, file, vm_flags) &&
97012 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
97013 pgoff_t vm_pglen;
97014@@ -1010,13 +1050,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
97015 struct vm_area_struct *vma_merge(struct mm_struct *mm,
97016 struct vm_area_struct *prev, unsigned long addr,
97017 unsigned long end, unsigned long vm_flags,
97018- struct anon_vma *anon_vma, struct file *file,
97019+ struct anon_vma *anon_vma, struct file *file,
97020 pgoff_t pgoff, struct mempolicy *policy)
97021 {
97022 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
97023 struct vm_area_struct *area, *next;
97024 int err;
97025
97026+#ifdef CONFIG_PAX_SEGMEXEC
97027+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
97028+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
97029+
97030+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
97031+#endif
97032+
97033 /*
97034 * We later require that vma->vm_flags == vm_flags,
97035 * so this tests vma->vm_flags & VM_SPECIAL, too.
97036@@ -1032,6 +1079,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97037 if (next && next->vm_end == end) /* cases 6, 7, 8 */
97038 next = next->vm_next;
97039
97040+#ifdef CONFIG_PAX_SEGMEXEC
97041+ if (prev)
97042+ prev_m = pax_find_mirror_vma(prev);
97043+ if (area)
97044+ area_m = pax_find_mirror_vma(area);
97045+ if (next)
97046+ next_m = pax_find_mirror_vma(next);
97047+#endif
97048+
97049 /*
97050 * Can it merge with the predecessor?
97051 */
97052@@ -1051,9 +1107,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97053 /* cases 1, 6 */
97054 err = vma_adjust(prev, prev->vm_start,
97055 next->vm_end, prev->vm_pgoff, NULL);
97056- } else /* cases 2, 5, 7 */
97057+
97058+#ifdef CONFIG_PAX_SEGMEXEC
97059+ if (!err && prev_m)
97060+ err = vma_adjust(prev_m, prev_m->vm_start,
97061+ next_m->vm_end, prev_m->vm_pgoff, NULL);
97062+#endif
97063+
97064+ } else { /* cases 2, 5, 7 */
97065 err = vma_adjust(prev, prev->vm_start,
97066 end, prev->vm_pgoff, NULL);
97067+
97068+#ifdef CONFIG_PAX_SEGMEXEC
97069+ if (!err && prev_m)
97070+ err = vma_adjust(prev_m, prev_m->vm_start,
97071+ end_m, prev_m->vm_pgoff, NULL);
97072+#endif
97073+
97074+ }
97075 if (err)
97076 return NULL;
97077 khugepaged_enter_vma_merge(prev);
97078@@ -1067,12 +1138,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
97079 mpol_equal(policy, vma_policy(next)) &&
97080 can_vma_merge_before(next, vm_flags,
97081 anon_vma, file, pgoff+pglen)) {
97082- if (prev && addr < prev->vm_end) /* case 4 */
97083+ if (prev && addr < prev->vm_end) { /* case 4 */
97084 err = vma_adjust(prev, prev->vm_start,
97085 addr, prev->vm_pgoff, NULL);
97086- else /* cases 3, 8 */
97087+
97088+#ifdef CONFIG_PAX_SEGMEXEC
97089+ if (!err && prev_m)
97090+ err = vma_adjust(prev_m, prev_m->vm_start,
97091+ addr_m, prev_m->vm_pgoff, NULL);
97092+#endif
97093+
97094+ } else { /* cases 3, 8 */
97095 err = vma_adjust(area, addr, next->vm_end,
97096 next->vm_pgoff - pglen, NULL);
97097+
97098+#ifdef CONFIG_PAX_SEGMEXEC
97099+ if (!err && area_m)
97100+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
97101+ next_m->vm_pgoff - pglen, NULL);
97102+#endif
97103+
97104+ }
97105 if (err)
97106 return NULL;
97107 khugepaged_enter_vma_merge(area);
97108@@ -1181,8 +1267,10 @@ none:
97109 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97110 struct file *file, long pages)
97111 {
97112- const unsigned long stack_flags
97113- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
97114+
97115+#ifdef CONFIG_PAX_RANDMMAP
97116+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97117+#endif
97118
97119 mm->total_vm += pages;
97120
97121@@ -1190,7 +1278,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
97122 mm->shared_vm += pages;
97123 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
97124 mm->exec_vm += pages;
97125- } else if (flags & stack_flags)
97126+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
97127 mm->stack_vm += pages;
97128 }
97129 #endif /* CONFIG_PROC_FS */
97130@@ -1220,6 +1308,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
97131 locked += mm->locked_vm;
97132 lock_limit = rlimit(RLIMIT_MEMLOCK);
97133 lock_limit >>= PAGE_SHIFT;
97134+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97135 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
97136 return -EAGAIN;
97137 }
97138@@ -1246,7 +1335,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97139 * (the exception is when the underlying filesystem is noexec
97140 * mounted, in which case we dont add PROT_EXEC.)
97141 */
97142- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
97143+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
97144 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
97145 prot |= PROT_EXEC;
97146
97147@@ -1272,7 +1361,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97148 /* Obtain the address to map to. we verify (or select) it and ensure
97149 * that it represents a valid section of the address space.
97150 */
97151- addr = get_unmapped_area(file, addr, len, pgoff, flags);
97152+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
97153 if (addr & ~PAGE_MASK)
97154 return addr;
97155
97156@@ -1283,6 +1372,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97157 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
97158 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
97159
97160+#ifdef CONFIG_PAX_MPROTECT
97161+ if (mm->pax_flags & MF_PAX_MPROTECT) {
97162+
97163+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
97164+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
97165+ mm->binfmt->handle_mmap)
97166+ mm->binfmt->handle_mmap(file);
97167+#endif
97168+
97169+#ifndef CONFIG_PAX_MPROTECT_COMPAT
97170+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
97171+ gr_log_rwxmmap(file);
97172+
97173+#ifdef CONFIG_PAX_EMUPLT
97174+ vm_flags &= ~VM_EXEC;
97175+#else
97176+ return -EPERM;
97177+#endif
97178+
97179+ }
97180+
97181+ if (!(vm_flags & VM_EXEC))
97182+ vm_flags &= ~VM_MAYEXEC;
97183+#else
97184+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
97185+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
97186+#endif
97187+ else
97188+ vm_flags &= ~VM_MAYWRITE;
97189+ }
97190+#endif
97191+
97192+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97193+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
97194+ vm_flags &= ~VM_PAGEEXEC;
97195+#endif
97196+
97197 if (flags & MAP_LOCKED)
97198 if (!can_do_mlock())
97199 return -EPERM;
97200@@ -1370,6 +1496,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
97201 vm_flags |= VM_NORESERVE;
97202 }
97203
97204+ if (!gr_acl_handle_mmap(file, prot))
97205+ return -EACCES;
97206+
97207 addr = mmap_region(file, addr, len, vm_flags, pgoff);
97208 if (!IS_ERR_VALUE(addr) &&
97209 ((vm_flags & VM_LOCKED) ||
97210@@ -1463,7 +1592,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
97211 vm_flags_t vm_flags = vma->vm_flags;
97212
97213 /* If it was private or non-writable, the write bit is already clear */
97214- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
97215+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
97216 return 0;
97217
97218 /* The backer wishes to know when pages are first written to? */
97219@@ -1509,7 +1638,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97220 struct rb_node **rb_link, *rb_parent;
97221 unsigned long charged = 0;
97222
97223+#ifdef CONFIG_PAX_SEGMEXEC
97224+ struct vm_area_struct *vma_m = NULL;
97225+#endif
97226+
97227+ /*
97228+ * mm->mmap_sem is required to protect against another thread
97229+ * changing the mappings in case we sleep.
97230+ */
97231+ verify_mm_writelocked(mm);
97232+
97233 /* Check against address space limit. */
97234+
97235+#ifdef CONFIG_PAX_RANDMMAP
97236+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
97237+#endif
97238+
97239 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
97240 unsigned long nr_pages;
97241
97242@@ -1528,11 +1672,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
97243
97244 /* Clear old maps */
97245 error = -ENOMEM;
97246-munmap_back:
97247 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
97248 if (do_munmap(mm, addr, len))
97249 return -ENOMEM;
97250- goto munmap_back;
97251+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
97252 }
97253
97254 /*
97255@@ -1563,6 +1706,16 @@ munmap_back:
97256 goto unacct_error;
97257 }
97258
97259+#ifdef CONFIG_PAX_SEGMEXEC
97260+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
97261+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
97262+ if (!vma_m) {
97263+ error = -ENOMEM;
97264+ goto free_vma;
97265+ }
97266+ }
97267+#endif
97268+
97269 vma->vm_mm = mm;
97270 vma->vm_start = addr;
97271 vma->vm_end = addr + len;
97272@@ -1593,6 +1746,13 @@ munmap_back:
97273 if (error)
97274 goto unmap_and_free_vma;
97275
97276+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
97277+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
97278+ vma->vm_flags |= VM_PAGEEXEC;
97279+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
97280+ }
97281+#endif
97282+
97283 /* Can addr have changed??
97284 *
97285 * Answer: Yes, several device drivers can do it in their
97286@@ -1626,6 +1786,12 @@ munmap_back:
97287 }
97288
97289 vma_link(mm, vma, prev, rb_link, rb_parent);
97290+
97291+#ifdef CONFIG_PAX_SEGMEXEC
97292+ if (vma_m)
97293+ BUG_ON(pax_mirror_vma(vma_m, vma));
97294+#endif
97295+
97296 /* Once vma denies write, undo our temporary denial count */
97297 if (file) {
97298 if (vm_flags & VM_SHARED)
97299@@ -1638,6 +1804,7 @@ out:
97300 perf_event_mmap(vma);
97301
97302 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
97303+ track_exec_limit(mm, addr, addr + len, vm_flags);
97304 if (vm_flags & VM_LOCKED) {
97305 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
97306 vma == get_gate_vma(current->mm)))
97307@@ -1673,6 +1840,12 @@ allow_write_and_free_vma:
97308 if (vm_flags & VM_DENYWRITE)
97309 allow_write_access(file);
97310 free_vma:
97311+
97312+#ifdef CONFIG_PAX_SEGMEXEC
97313+ if (vma_m)
97314+ kmem_cache_free(vm_area_cachep, vma_m);
97315+#endif
97316+
97317 kmem_cache_free(vm_area_cachep, vma);
97318 unacct_error:
97319 if (charged)
97320@@ -1680,7 +1853,63 @@ unacct_error:
97321 return error;
97322 }
97323
97324-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97325+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
97326+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
97327+{
97328+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
97329+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
97330+
97331+ return 0;
97332+}
97333+#endif
97334+
97335+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
97336+{
97337+ if (!vma) {
97338+#ifdef CONFIG_STACK_GROWSUP
97339+ if (addr > sysctl_heap_stack_gap)
97340+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
97341+ else
97342+ vma = find_vma(current->mm, 0);
97343+ if (vma && (vma->vm_flags & VM_GROWSUP))
97344+ return false;
97345+#endif
97346+ return true;
97347+ }
97348+
97349+ if (addr + len > vma->vm_start)
97350+ return false;
97351+
97352+ if (vma->vm_flags & VM_GROWSDOWN)
97353+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
97354+#ifdef CONFIG_STACK_GROWSUP
97355+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
97356+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
97357+#endif
97358+ else if (offset)
97359+ return offset <= vma->vm_start - addr - len;
97360+
97361+ return true;
97362+}
97363+
97364+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
97365+{
97366+ if (vma->vm_start < len)
97367+ return -ENOMEM;
97368+
97369+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
97370+ if (offset <= vma->vm_start - len)
97371+ return vma->vm_start - len - offset;
97372+ else
97373+ return -ENOMEM;
97374+ }
97375+
97376+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
97377+ return vma->vm_start - len - sysctl_heap_stack_gap;
97378+ return -ENOMEM;
97379+}
97380+
97381+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
97382 {
97383 /*
97384 * We implement the search by looking for an rbtree node that
97385@@ -1728,11 +1957,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
97386 }
97387 }
97388
97389- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
97390+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
97391 check_current:
97392 /* Check if current node has a suitable gap */
97393 if (gap_start > high_limit)
97394 return -ENOMEM;
97395+
97396+ if (gap_end - gap_start > info->threadstack_offset)
97397+ gap_start += info->threadstack_offset;
97398+ else
97399+ gap_start = gap_end;
97400+
97401+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97402+ if (gap_end - gap_start > sysctl_heap_stack_gap)
97403+ gap_start += sysctl_heap_stack_gap;
97404+ else
97405+ gap_start = gap_end;
97406+ }
97407+ if (vma->vm_flags & VM_GROWSDOWN) {
97408+ if (gap_end - gap_start > sysctl_heap_stack_gap)
97409+ gap_end -= sysctl_heap_stack_gap;
97410+ else
97411+ gap_end = gap_start;
97412+ }
97413 if (gap_end >= low_limit && gap_end - gap_start >= length)
97414 goto found;
97415
97416@@ -1782,7 +2029,7 @@ found:
97417 return gap_start;
97418 }
97419
97420-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
97421+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
97422 {
97423 struct mm_struct *mm = current->mm;
97424 struct vm_area_struct *vma;
97425@@ -1836,6 +2083,24 @@ check_current:
97426 gap_end = vma->vm_start;
97427 if (gap_end < low_limit)
97428 return -ENOMEM;
97429+
97430+ if (gap_end - gap_start > info->threadstack_offset)
97431+ gap_end -= info->threadstack_offset;
97432+ else
97433+ gap_end = gap_start;
97434+
97435+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
97436+ if (gap_end - gap_start > sysctl_heap_stack_gap)
97437+ gap_start += sysctl_heap_stack_gap;
97438+ else
97439+ gap_start = gap_end;
97440+ }
97441+ if (vma->vm_flags & VM_GROWSDOWN) {
97442+ if (gap_end - gap_start > sysctl_heap_stack_gap)
97443+ gap_end -= sysctl_heap_stack_gap;
97444+ else
97445+ gap_end = gap_start;
97446+ }
97447 if (gap_start <= high_limit && gap_end - gap_start >= length)
97448 goto found;
97449
97450@@ -1899,6 +2164,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97451 struct mm_struct *mm = current->mm;
97452 struct vm_area_struct *vma;
97453 struct vm_unmapped_area_info info;
97454+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97455
97456 if (len > TASK_SIZE - mmap_min_addr)
97457 return -ENOMEM;
97458@@ -1906,11 +2172,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97459 if (flags & MAP_FIXED)
97460 return addr;
97461
97462+#ifdef CONFIG_PAX_RANDMMAP
97463+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97464+#endif
97465+
97466 if (addr) {
97467 addr = PAGE_ALIGN(addr);
97468 vma = find_vma(mm, addr);
97469 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97470- (!vma || addr + len <= vma->vm_start))
97471+ check_heap_stack_gap(vma, addr, len, offset))
97472 return addr;
97473 }
97474
97475@@ -1919,6 +2189,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
97476 info.low_limit = mm->mmap_base;
97477 info.high_limit = TASK_SIZE;
97478 info.align_mask = 0;
97479+ info.threadstack_offset = offset;
97480 return vm_unmapped_area(&info);
97481 }
97482 #endif
97483@@ -1937,6 +2208,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97484 struct mm_struct *mm = current->mm;
97485 unsigned long addr = addr0;
97486 struct vm_unmapped_area_info info;
97487+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
97488
97489 /* requested length too big for entire address space */
97490 if (len > TASK_SIZE - mmap_min_addr)
97491@@ -1945,12 +2217,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97492 if (flags & MAP_FIXED)
97493 return addr;
97494
97495+#ifdef CONFIG_PAX_RANDMMAP
97496+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
97497+#endif
97498+
97499 /* requesting a specific address */
97500 if (addr) {
97501 addr = PAGE_ALIGN(addr);
97502 vma = find_vma(mm, addr);
97503 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
97504- (!vma || addr + len <= vma->vm_start))
97505+ check_heap_stack_gap(vma, addr, len, offset))
97506 return addr;
97507 }
97508
97509@@ -1959,6 +2235,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97510 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
97511 info.high_limit = mm->mmap_base;
97512 info.align_mask = 0;
97513+ info.threadstack_offset = offset;
97514 addr = vm_unmapped_area(&info);
97515
97516 /*
97517@@ -1971,6 +2248,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
97518 VM_BUG_ON(addr != -ENOMEM);
97519 info.flags = 0;
97520 info.low_limit = TASK_UNMAPPED_BASE;
97521+
97522+#ifdef CONFIG_PAX_RANDMMAP
97523+ if (mm->pax_flags & MF_PAX_RANDMMAP)
97524+ info.low_limit += mm->delta_mmap;
97525+#endif
97526+
97527 info.high_limit = TASK_SIZE;
97528 addr = vm_unmapped_area(&info);
97529 }
97530@@ -2071,6 +2354,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
97531 return vma;
97532 }
97533
97534+#ifdef CONFIG_PAX_SEGMEXEC
97535+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
97536+{
97537+ struct vm_area_struct *vma_m;
97538+
97539+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
97540+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
97541+ BUG_ON(vma->vm_mirror);
97542+ return NULL;
97543+ }
97544+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
97545+ vma_m = vma->vm_mirror;
97546+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
97547+ BUG_ON(vma->vm_file != vma_m->vm_file);
97548+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
97549+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
97550+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
97551+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
97552+ return vma_m;
97553+}
97554+#endif
97555+
97556 /*
97557 * Verify that the stack growth is acceptable and
97558 * update accounting. This is shared with both the
97559@@ -2087,6 +2392,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97560 return -ENOMEM;
97561
97562 /* Stack limit test */
97563+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
97564 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
97565 return -ENOMEM;
97566
97567@@ -2097,6 +2403,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97568 locked = mm->locked_vm + grow;
97569 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
97570 limit >>= PAGE_SHIFT;
97571+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
97572 if (locked > limit && !capable(CAP_IPC_LOCK))
97573 return -ENOMEM;
97574 }
97575@@ -2126,37 +2433,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
97576 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
97577 * vma is the last one with address > vma->vm_end. Have to extend vma.
97578 */
97579+#ifndef CONFIG_IA64
97580+static
97581+#endif
97582 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97583 {
97584 int error;
97585+ bool locknext;
97586
97587 if (!(vma->vm_flags & VM_GROWSUP))
97588 return -EFAULT;
97589
97590+ /* Also guard against wrapping around to address 0. */
97591+ if (address < PAGE_ALIGN(address+1))
97592+ address = PAGE_ALIGN(address+1);
97593+ else
97594+ return -ENOMEM;
97595+
97596 /*
97597 * We must make sure the anon_vma is allocated
97598 * so that the anon_vma locking is not a noop.
97599 */
97600 if (unlikely(anon_vma_prepare(vma)))
97601 return -ENOMEM;
97602+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
97603+ if (locknext && anon_vma_prepare(vma->vm_next))
97604+ return -ENOMEM;
97605 vma_lock_anon_vma(vma);
97606+ if (locknext)
97607+ vma_lock_anon_vma(vma->vm_next);
97608
97609 /*
97610 * vma->vm_start/vm_end cannot change under us because the caller
97611 * is required to hold the mmap_sem in read mode. We need the
97612- * anon_vma lock to serialize against concurrent expand_stacks.
97613- * Also guard against wrapping around to address 0.
97614+ * anon_vma locks to serialize against concurrent expand_stacks
97615+ * and expand_upwards.
97616 */
97617- if (address < PAGE_ALIGN(address+4))
97618- address = PAGE_ALIGN(address+4);
97619- else {
97620- vma_unlock_anon_vma(vma);
97621- return -ENOMEM;
97622- }
97623 error = 0;
97624
97625 /* Somebody else might have raced and expanded it already */
97626- if (address > vma->vm_end) {
97627+ 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)
97628+ error = -ENOMEM;
97629+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
97630 unsigned long size, grow;
97631
97632 size = address - vma->vm_start;
97633@@ -2191,6 +2509,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
97634 }
97635 }
97636 }
97637+ if (locknext)
97638+ vma_unlock_anon_vma(vma->vm_next);
97639 vma_unlock_anon_vma(vma);
97640 khugepaged_enter_vma_merge(vma);
97641 validate_mm(vma->vm_mm);
97642@@ -2205,6 +2525,8 @@ int expand_downwards(struct vm_area_struct *vma,
97643 unsigned long address)
97644 {
97645 int error;
97646+ bool lockprev = false;
97647+ struct vm_area_struct *prev;
97648
97649 /*
97650 * We must make sure the anon_vma is allocated
97651@@ -2218,6 +2540,15 @@ int expand_downwards(struct vm_area_struct *vma,
97652 if (error)
97653 return error;
97654
97655+ prev = vma->vm_prev;
97656+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
97657+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
97658+#endif
97659+ if (lockprev && anon_vma_prepare(prev))
97660+ return -ENOMEM;
97661+ if (lockprev)
97662+ vma_lock_anon_vma(prev);
97663+
97664 vma_lock_anon_vma(vma);
97665
97666 /*
97667@@ -2227,9 +2558,17 @@ int expand_downwards(struct vm_area_struct *vma,
97668 */
97669
97670 /* Somebody else might have raced and expanded it already */
97671- if (address < vma->vm_start) {
97672+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
97673+ error = -ENOMEM;
97674+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
97675 unsigned long size, grow;
97676
97677+#ifdef CONFIG_PAX_SEGMEXEC
97678+ struct vm_area_struct *vma_m;
97679+
97680+ vma_m = pax_find_mirror_vma(vma);
97681+#endif
97682+
97683 size = vma->vm_end - address;
97684 grow = (vma->vm_start - address) >> PAGE_SHIFT;
97685
97686@@ -2254,13 +2593,27 @@ int expand_downwards(struct vm_area_struct *vma,
97687 vma->vm_pgoff -= grow;
97688 anon_vma_interval_tree_post_update_vma(vma);
97689 vma_gap_update(vma);
97690+
97691+#ifdef CONFIG_PAX_SEGMEXEC
97692+ if (vma_m) {
97693+ anon_vma_interval_tree_pre_update_vma(vma_m);
97694+ vma_m->vm_start -= grow << PAGE_SHIFT;
97695+ vma_m->vm_pgoff -= grow;
97696+ anon_vma_interval_tree_post_update_vma(vma_m);
97697+ vma_gap_update(vma_m);
97698+ }
97699+#endif
97700+
97701 spin_unlock(&vma->vm_mm->page_table_lock);
97702
97703+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
97704 perf_event_mmap(vma);
97705 }
97706 }
97707 }
97708 vma_unlock_anon_vma(vma);
97709+ if (lockprev)
97710+ vma_unlock_anon_vma(prev);
97711 khugepaged_enter_vma_merge(vma);
97712 validate_mm(vma->vm_mm);
97713 return error;
97714@@ -2358,6 +2711,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
97715 do {
97716 long nrpages = vma_pages(vma);
97717
97718+#ifdef CONFIG_PAX_SEGMEXEC
97719+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
97720+ vma = remove_vma(vma);
97721+ continue;
97722+ }
97723+#endif
97724+
97725 if (vma->vm_flags & VM_ACCOUNT)
97726 nr_accounted += nrpages;
97727 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
97728@@ -2402,6 +2762,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
97729 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
97730 vma->vm_prev = NULL;
97731 do {
97732+
97733+#ifdef CONFIG_PAX_SEGMEXEC
97734+ if (vma->vm_mirror) {
97735+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
97736+ vma->vm_mirror->vm_mirror = NULL;
97737+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
97738+ vma->vm_mirror = NULL;
97739+ }
97740+#endif
97741+
97742 vma_rb_erase(vma, &mm->mm_rb);
97743 mm->map_count--;
97744 tail_vma = vma;
97745@@ -2429,14 +2799,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
97746 struct vm_area_struct *new;
97747 int err = -ENOMEM;
97748
97749+#ifdef CONFIG_PAX_SEGMEXEC
97750+ struct vm_area_struct *vma_m, *new_m = NULL;
97751+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
97752+#endif
97753+
97754 if (is_vm_hugetlb_page(vma) && (addr &
97755 ~(huge_page_mask(hstate_vma(vma)))))
97756 return -EINVAL;
97757
97758+#ifdef CONFIG_PAX_SEGMEXEC
97759+ vma_m = pax_find_mirror_vma(vma);
97760+#endif
97761+
97762 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97763 if (!new)
97764 goto out_err;
97765
97766+#ifdef CONFIG_PAX_SEGMEXEC
97767+ if (vma_m) {
97768+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
97769+ if (!new_m) {
97770+ kmem_cache_free(vm_area_cachep, new);
97771+ goto out_err;
97772+ }
97773+ }
97774+#endif
97775+
97776 /* most fields are the same, copy all, and then fixup */
97777 *new = *vma;
97778
97779@@ -2449,6 +2838,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
97780 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
97781 }
97782
97783+#ifdef CONFIG_PAX_SEGMEXEC
97784+ if (vma_m) {
97785+ *new_m = *vma_m;
97786+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
97787+ new_m->vm_mirror = new;
97788+ new->vm_mirror = new_m;
97789+
97790+ if (new_below)
97791+ new_m->vm_end = addr_m;
97792+ else {
97793+ new_m->vm_start = addr_m;
97794+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
97795+ }
97796+ }
97797+#endif
97798+
97799 err = vma_dup_policy(vma, new);
97800 if (err)
97801 goto out_free_vma;
97802@@ -2468,6 +2873,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
97803 else
97804 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
97805
97806+#ifdef CONFIG_PAX_SEGMEXEC
97807+ if (!err && vma_m) {
97808+ struct mempolicy *pol = vma_policy(new);
97809+
97810+ if (anon_vma_clone(new_m, vma_m))
97811+ goto out_free_mpol;
97812+
97813+ mpol_get(pol);
97814+ set_vma_policy(new_m, pol);
97815+
97816+ if (new_m->vm_file)
97817+ get_file(new_m->vm_file);
97818+
97819+ if (new_m->vm_ops && new_m->vm_ops->open)
97820+ new_m->vm_ops->open(new_m);
97821+
97822+ if (new_below)
97823+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
97824+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
97825+ else
97826+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
97827+
97828+ if (err) {
97829+ if (new_m->vm_ops && new_m->vm_ops->close)
97830+ new_m->vm_ops->close(new_m);
97831+ if (new_m->vm_file)
97832+ fput(new_m->vm_file);
97833+ mpol_put(pol);
97834+ }
97835+ }
97836+#endif
97837+
97838 /* Success. */
97839 if (!err)
97840 return 0;
97841@@ -2477,10 +2914,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
97842 new->vm_ops->close(new);
97843 if (new->vm_file)
97844 fput(new->vm_file);
97845- unlink_anon_vmas(new);
97846 out_free_mpol:
97847 mpol_put(vma_policy(new));
97848 out_free_vma:
97849+
97850+#ifdef CONFIG_PAX_SEGMEXEC
97851+ if (new_m) {
97852+ unlink_anon_vmas(new_m);
97853+ kmem_cache_free(vm_area_cachep, new_m);
97854+ }
97855+#endif
97856+
97857+ unlink_anon_vmas(new);
97858 kmem_cache_free(vm_area_cachep, new);
97859 out_err:
97860 return err;
97861@@ -2493,6 +2938,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
97862 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97863 unsigned long addr, int new_below)
97864 {
97865+
97866+#ifdef CONFIG_PAX_SEGMEXEC
97867+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
97868+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
97869+ if (mm->map_count >= sysctl_max_map_count-1)
97870+ return -ENOMEM;
97871+ } else
97872+#endif
97873+
97874 if (mm->map_count >= sysctl_max_map_count)
97875 return -ENOMEM;
97876
97877@@ -2504,11 +2958,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
97878 * work. This now handles partial unmappings.
97879 * Jeremy Fitzhardinge <jeremy@goop.org>
97880 */
97881+#ifdef CONFIG_PAX_SEGMEXEC
97882 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97883 {
97884+ int ret = __do_munmap(mm, start, len);
97885+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
97886+ return ret;
97887+
97888+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
97889+}
97890+
97891+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97892+#else
97893+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97894+#endif
97895+{
97896 unsigned long end;
97897 struct vm_area_struct *vma, *prev, *last;
97898
97899+ /*
97900+ * mm->mmap_sem is required to protect against another thread
97901+ * changing the mappings in case we sleep.
97902+ */
97903+ verify_mm_writelocked(mm);
97904+
97905 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
97906 return -EINVAL;
97907
97908@@ -2583,6 +3056,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
97909 /* Fix up all other VM information */
97910 remove_vma_list(mm, vma);
97911
97912+ track_exec_limit(mm, start, end, 0UL);
97913+
97914 return 0;
97915 }
97916
97917@@ -2591,6 +3066,13 @@ int vm_munmap(unsigned long start, size_t len)
97918 int ret;
97919 struct mm_struct *mm = current->mm;
97920
97921+
97922+#ifdef CONFIG_PAX_SEGMEXEC
97923+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
97924+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
97925+ return -EINVAL;
97926+#endif
97927+
97928 down_write(&mm->mmap_sem);
97929 ret = do_munmap(mm, start, len);
97930 up_write(&mm->mmap_sem);
97931@@ -2604,16 +3086,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
97932 return vm_munmap(addr, len);
97933 }
97934
97935-static inline void verify_mm_writelocked(struct mm_struct *mm)
97936-{
97937-#ifdef CONFIG_DEBUG_VM
97938- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
97939- WARN_ON(1);
97940- up_read(&mm->mmap_sem);
97941- }
97942-#endif
97943-}
97944-
97945 /*
97946 * this is really a simplified "do_mmap". it only handles
97947 * anonymous maps. eventually we may be able to do some
97948@@ -2627,6 +3099,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97949 struct rb_node ** rb_link, * rb_parent;
97950 pgoff_t pgoff = addr >> PAGE_SHIFT;
97951 int error;
97952+ unsigned long charged;
97953
97954 len = PAGE_ALIGN(len);
97955 if (!len)
97956@@ -2634,10 +3107,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97957
97958 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
97959
97960+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
97961+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
97962+ flags &= ~VM_EXEC;
97963+
97964+#ifdef CONFIG_PAX_MPROTECT
97965+ if (mm->pax_flags & MF_PAX_MPROTECT)
97966+ flags &= ~VM_MAYEXEC;
97967+#endif
97968+
97969+ }
97970+#endif
97971+
97972 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
97973 if (error & ~PAGE_MASK)
97974 return error;
97975
97976+ charged = len >> PAGE_SHIFT;
97977+
97978 error = mlock_future_check(mm, mm->def_flags, len);
97979 if (error)
97980 return error;
97981@@ -2651,21 +3138,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
97982 /*
97983 * Clear old maps. this also does some error checking for us
97984 */
97985- munmap_back:
97986 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
97987 if (do_munmap(mm, addr, len))
97988 return -ENOMEM;
97989- goto munmap_back;
97990+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
97991 }
97992
97993 /* Check against address space limits *after* clearing old maps... */
97994- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
97995+ if (!may_expand_vm(mm, charged))
97996 return -ENOMEM;
97997
97998 if (mm->map_count > sysctl_max_map_count)
97999 return -ENOMEM;
98000
98001- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
98002+ if (security_vm_enough_memory_mm(mm, charged))
98003 return -ENOMEM;
98004
98005 /* Can we just expand an old private anonymous mapping? */
98006@@ -2679,7 +3165,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98007 */
98008 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98009 if (!vma) {
98010- vm_unacct_memory(len >> PAGE_SHIFT);
98011+ vm_unacct_memory(charged);
98012 return -ENOMEM;
98013 }
98014
98015@@ -2693,10 +3179,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
98016 vma_link(mm, vma, prev, rb_link, rb_parent);
98017 out:
98018 perf_event_mmap(vma);
98019- mm->total_vm += len >> PAGE_SHIFT;
98020+ mm->total_vm += charged;
98021 if (flags & VM_LOCKED)
98022- mm->locked_vm += (len >> PAGE_SHIFT);
98023+ mm->locked_vm += charged;
98024 vma->vm_flags |= VM_SOFTDIRTY;
98025+ track_exec_limit(mm, addr, addr + len, flags);
98026 return addr;
98027 }
98028
98029@@ -2758,6 +3245,7 @@ void exit_mmap(struct mm_struct *mm)
98030 while (vma) {
98031 if (vma->vm_flags & VM_ACCOUNT)
98032 nr_accounted += vma_pages(vma);
98033+ vma->vm_mirror = NULL;
98034 vma = remove_vma(vma);
98035 }
98036 vm_unacct_memory(nr_accounted);
98037@@ -2775,6 +3263,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98038 struct vm_area_struct *prev;
98039 struct rb_node **rb_link, *rb_parent;
98040
98041+#ifdef CONFIG_PAX_SEGMEXEC
98042+ struct vm_area_struct *vma_m = NULL;
98043+#endif
98044+
98045+ if (security_mmap_addr(vma->vm_start))
98046+ return -EPERM;
98047+
98048 /*
98049 * The vm_pgoff of a purely anonymous vma should be irrelevant
98050 * until its first write fault, when page's anon_vma and index
98051@@ -2798,7 +3293,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
98052 security_vm_enough_memory_mm(mm, vma_pages(vma)))
98053 return -ENOMEM;
98054
98055+#ifdef CONFIG_PAX_SEGMEXEC
98056+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
98057+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98058+ if (!vma_m)
98059+ return -ENOMEM;
98060+ }
98061+#endif
98062+
98063 vma_link(mm, vma, prev, rb_link, rb_parent);
98064+
98065+#ifdef CONFIG_PAX_SEGMEXEC
98066+ if (vma_m)
98067+ BUG_ON(pax_mirror_vma(vma_m, vma));
98068+#endif
98069+
98070 return 0;
98071 }
98072
98073@@ -2817,6 +3326,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98074 struct rb_node **rb_link, *rb_parent;
98075 bool faulted_in_anon_vma = true;
98076
98077+ BUG_ON(vma->vm_mirror);
98078+
98079 /*
98080 * If anonymous vma has not yet been faulted, update new pgoff
98081 * to match new location, to increase its chance of merging.
98082@@ -2881,6 +3392,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
98083 return NULL;
98084 }
98085
98086+#ifdef CONFIG_PAX_SEGMEXEC
98087+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
98088+{
98089+ struct vm_area_struct *prev_m;
98090+ struct rb_node **rb_link_m, *rb_parent_m;
98091+ struct mempolicy *pol_m;
98092+
98093+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
98094+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
98095+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
98096+ *vma_m = *vma;
98097+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
98098+ if (anon_vma_clone(vma_m, vma))
98099+ return -ENOMEM;
98100+ pol_m = vma_policy(vma_m);
98101+ mpol_get(pol_m);
98102+ set_vma_policy(vma_m, pol_m);
98103+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
98104+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
98105+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
98106+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
98107+ if (vma_m->vm_file)
98108+ get_file(vma_m->vm_file);
98109+ if (vma_m->vm_ops && vma_m->vm_ops->open)
98110+ vma_m->vm_ops->open(vma_m);
98111+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
98112+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
98113+ vma_m->vm_mirror = vma;
98114+ vma->vm_mirror = vma_m;
98115+ return 0;
98116+}
98117+#endif
98118+
98119 /*
98120 * Return true if the calling process may expand its vm space by the passed
98121 * number of pages
98122@@ -2892,6 +3436,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
98123
98124 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
98125
98126+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
98127 if (cur + npages > lim)
98128 return 0;
98129 return 1;
98130@@ -2974,6 +3519,22 @@ static struct vm_area_struct *__install_special_mapping(
98131 vma->vm_start = addr;
98132 vma->vm_end = addr + len;
98133
98134+#ifdef CONFIG_PAX_MPROTECT
98135+ if (mm->pax_flags & MF_PAX_MPROTECT) {
98136+#ifndef CONFIG_PAX_MPROTECT_COMPAT
98137+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
98138+ return ERR_PTR(-EPERM);
98139+ if (!(vm_flags & VM_EXEC))
98140+ vm_flags &= ~VM_MAYEXEC;
98141+#else
98142+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
98143+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
98144+#endif
98145+ else
98146+ vm_flags &= ~VM_MAYWRITE;
98147+ }
98148+#endif
98149+
98150 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
98151 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
98152
98153diff --git a/mm/mprotect.c b/mm/mprotect.c
98154index c43d557..0b7ccd2 100644
98155--- a/mm/mprotect.c
98156+++ b/mm/mprotect.c
98157@@ -24,10 +24,18 @@
98158 #include <linux/migrate.h>
98159 #include <linux/perf_event.h>
98160 #include <linux/ksm.h>
98161+#include <linux/sched/sysctl.h>
98162+
98163+#ifdef CONFIG_PAX_MPROTECT
98164+#include <linux/elf.h>
98165+#include <linux/binfmts.h>
98166+#endif
98167+
98168 #include <asm/uaccess.h>
98169 #include <asm/pgtable.h>
98170 #include <asm/cacheflush.h>
98171 #include <asm/tlbflush.h>
98172+#include <asm/mmu_context.h>
98173
98174 #ifndef pgprot_modify
98175 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
98176@@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
98177 return pages;
98178 }
98179
98180+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98181+/* called while holding the mmap semaphor for writing except stack expansion */
98182+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
98183+{
98184+ unsigned long oldlimit, newlimit = 0UL;
98185+
98186+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
98187+ return;
98188+
98189+ spin_lock(&mm->page_table_lock);
98190+ oldlimit = mm->context.user_cs_limit;
98191+ if ((prot & VM_EXEC) && oldlimit < end)
98192+ /* USER_CS limit moved up */
98193+ newlimit = end;
98194+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
98195+ /* USER_CS limit moved down */
98196+ newlimit = start;
98197+
98198+ if (newlimit) {
98199+ mm->context.user_cs_limit = newlimit;
98200+
98201+#ifdef CONFIG_SMP
98202+ wmb();
98203+ cpus_clear(mm->context.cpu_user_cs_mask);
98204+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
98205+#endif
98206+
98207+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
98208+ }
98209+ spin_unlock(&mm->page_table_lock);
98210+ if (newlimit == end) {
98211+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
98212+
98213+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
98214+ if (is_vm_hugetlb_page(vma))
98215+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
98216+ else
98217+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
98218+ }
98219+}
98220+#endif
98221+
98222 int
98223 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98224 unsigned long start, unsigned long end, unsigned long newflags)
98225@@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98226 int error;
98227 int dirty_accountable = 0;
98228
98229+#ifdef CONFIG_PAX_SEGMEXEC
98230+ struct vm_area_struct *vma_m = NULL;
98231+ unsigned long start_m, end_m;
98232+
98233+ start_m = start + SEGMEXEC_TASK_SIZE;
98234+ end_m = end + SEGMEXEC_TASK_SIZE;
98235+#endif
98236+
98237 if (newflags == oldflags) {
98238 *pprev = vma;
98239 return 0;
98240 }
98241
98242+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
98243+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
98244+
98245+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
98246+ return -ENOMEM;
98247+
98248+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
98249+ return -ENOMEM;
98250+ }
98251+
98252 /*
98253 * If we make a private mapping writable we increase our commit;
98254 * but (without finer accounting) cannot reduce our commit if we
98255@@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
98256 }
98257 }
98258
98259+#ifdef CONFIG_PAX_SEGMEXEC
98260+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
98261+ if (start != vma->vm_start) {
98262+ error = split_vma(mm, vma, start, 1);
98263+ if (error)
98264+ goto fail;
98265+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
98266+ *pprev = (*pprev)->vm_next;
98267+ }
98268+
98269+ if (end != vma->vm_end) {
98270+ error = split_vma(mm, vma, end, 0);
98271+ if (error)
98272+ goto fail;
98273+ }
98274+
98275+ if (pax_find_mirror_vma(vma)) {
98276+ error = __do_munmap(mm, start_m, end_m - start_m);
98277+ if (error)
98278+ goto fail;
98279+ } else {
98280+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
98281+ if (!vma_m) {
98282+ error = -ENOMEM;
98283+ goto fail;
98284+ }
98285+ vma->vm_flags = newflags;
98286+ error = pax_mirror_vma(vma_m, vma);
98287+ if (error) {
98288+ vma->vm_flags = oldflags;
98289+ goto fail;
98290+ }
98291+ }
98292+ }
98293+#endif
98294+
98295 /*
98296 * First try to merge with previous and/or next vma.
98297 */
98298@@ -319,9 +423,21 @@ success:
98299 * vm_flags and vm_page_prot are protected by the mmap_sem
98300 * held in write mode.
98301 */
98302+
98303+#ifdef CONFIG_PAX_SEGMEXEC
98304+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
98305+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
98306+#endif
98307+
98308 vma->vm_flags = newflags;
98309+
98310+#ifdef CONFIG_PAX_MPROTECT
98311+ if (mm->binfmt && mm->binfmt->handle_mprotect)
98312+ mm->binfmt->handle_mprotect(vma, newflags);
98313+#endif
98314+
98315 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
98316- vm_get_page_prot(newflags));
98317+ vm_get_page_prot(vma->vm_flags));
98318
98319 if (vma_wants_writenotify(vma)) {
98320 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
98321@@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98322 end = start + len;
98323 if (end <= start)
98324 return -ENOMEM;
98325+
98326+#ifdef CONFIG_PAX_SEGMEXEC
98327+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
98328+ if (end > SEGMEXEC_TASK_SIZE)
98329+ return -EINVAL;
98330+ } else
98331+#endif
98332+
98333+ if (end > TASK_SIZE)
98334+ return -EINVAL;
98335+
98336 if (!arch_validate_prot(prot))
98337 return -EINVAL;
98338
98339@@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98340 /*
98341 * Does the application expect PROT_READ to imply PROT_EXEC:
98342 */
98343- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
98344+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
98345 prot |= PROT_EXEC;
98346
98347 vm_flags = calc_vm_prot_bits(prot);
98348@@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98349 if (start > vma->vm_start)
98350 prev = vma;
98351
98352+#ifdef CONFIG_PAX_MPROTECT
98353+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
98354+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
98355+#endif
98356+
98357 for (nstart = start ; ; ) {
98358 unsigned long newflags;
98359
98360@@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98361
98362 /* newflags >> 4 shift VM_MAY% in place of VM_% */
98363 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
98364+ if (prot & (PROT_WRITE | PROT_EXEC))
98365+ gr_log_rwxmprotect(vma);
98366+
98367+ error = -EACCES;
98368+ goto out;
98369+ }
98370+
98371+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
98372 error = -EACCES;
98373 goto out;
98374 }
98375@@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
98376 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
98377 if (error)
98378 goto out;
98379+
98380+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
98381+
98382 nstart = tmp;
98383
98384 if (nstart < prev->vm_end)
98385diff --git a/mm/mremap.c b/mm/mremap.c
98386index 05f1180..c3cde48 100644
98387--- a/mm/mremap.c
98388+++ b/mm/mremap.c
98389@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
98390 continue;
98391 pte = ptep_get_and_clear(mm, old_addr, old_pte);
98392 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
98393+
98394+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
98395+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
98396+ pte = pte_exprotect(pte);
98397+#endif
98398+
98399 pte = move_soft_dirty_pte(pte);
98400 set_pte_at(mm, new_addr, new_pte, pte);
98401 }
98402@@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
98403 if (is_vm_hugetlb_page(vma))
98404 goto Einval;
98405
98406+#ifdef CONFIG_PAX_SEGMEXEC
98407+ if (pax_find_mirror_vma(vma))
98408+ goto Einval;
98409+#endif
98410+
98411 /* We can't remap across vm area boundaries */
98412 if (old_len > vma->vm_end - addr)
98413 goto Efault;
98414@@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
98415 unsigned long ret = -EINVAL;
98416 unsigned long charged = 0;
98417 unsigned long map_flags;
98418+ unsigned long pax_task_size = TASK_SIZE;
98419
98420 if (new_addr & ~PAGE_MASK)
98421 goto out;
98422
98423- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
98424+#ifdef CONFIG_PAX_SEGMEXEC
98425+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
98426+ pax_task_size = SEGMEXEC_TASK_SIZE;
98427+#endif
98428+
98429+ pax_task_size -= PAGE_SIZE;
98430+
98431+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
98432 goto out;
98433
98434 /* Check if the location we're moving into overlaps the
98435 * old location at all, and fail if it does.
98436 */
98437- if ((new_addr <= addr) && (new_addr+new_len) > addr)
98438- goto out;
98439-
98440- if ((addr <= new_addr) && (addr+old_len) > new_addr)
98441+ if (addr + old_len > new_addr && new_addr + new_len > addr)
98442 goto out;
98443
98444 ret = do_munmap(mm, new_addr, new_len);
98445@@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98446 unsigned long ret = -EINVAL;
98447 unsigned long charged = 0;
98448 bool locked = false;
98449+ unsigned long pax_task_size = TASK_SIZE;
98450
98451 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
98452 return ret;
98453@@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98454 if (!new_len)
98455 return ret;
98456
98457+#ifdef CONFIG_PAX_SEGMEXEC
98458+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
98459+ pax_task_size = SEGMEXEC_TASK_SIZE;
98460+#endif
98461+
98462+ pax_task_size -= PAGE_SIZE;
98463+
98464+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
98465+ old_len > pax_task_size || addr > pax_task_size-old_len)
98466+ return ret;
98467+
98468 down_write(&current->mm->mmap_sem);
98469
98470 if (flags & MREMAP_FIXED) {
98471@@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98472 new_addr = addr;
98473 }
98474 ret = addr;
98475+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
98476 goto out;
98477 }
98478 }
98479@@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
98480 goto out;
98481 }
98482
98483+ map_flags = vma->vm_flags;
98484 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
98485+ if (!(ret & ~PAGE_MASK)) {
98486+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
98487+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
98488+ }
98489 }
98490 out:
98491 if (ret & ~PAGE_MASK)
98492diff --git a/mm/nommu.c b/mm/nommu.c
98493index a881d96..e5932cd 100644
98494--- a/mm/nommu.c
98495+++ b/mm/nommu.c
98496@@ -70,7 +70,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
98497 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
98498 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
98499 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
98500-int heap_stack_gap = 0;
98501
98502 atomic_long_t mmap_pages_allocated;
98503
98504@@ -857,15 +856,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
98505 EXPORT_SYMBOL(find_vma);
98506
98507 /*
98508- * find a VMA
98509- * - we don't extend stack VMAs under NOMMU conditions
98510- */
98511-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
98512-{
98513- return find_vma(mm, addr);
98514-}
98515-
98516-/*
98517 * expand a stack to a given address
98518 * - not supported under NOMMU conditions
98519 */
98520@@ -1572,6 +1562,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
98521
98522 /* most fields are the same, copy all, and then fixup */
98523 *new = *vma;
98524+ INIT_LIST_HEAD(&new->anon_vma_chain);
98525 *region = *vma->vm_region;
98526 new->vm_region = region;
98527
98528@@ -2002,8 +1993,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
98529 }
98530 EXPORT_SYMBOL(generic_file_remap_pages);
98531
98532-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98533- unsigned long addr, void *buf, int len, int write)
98534+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98535+ unsigned long addr, void *buf, size_t len, int write)
98536 {
98537 struct vm_area_struct *vma;
98538
98539@@ -2044,8 +2035,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
98540 *
98541 * The caller must hold a reference on @mm.
98542 */
98543-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98544- void *buf, int len, int write)
98545+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
98546+ void *buf, size_t len, int write)
98547 {
98548 return __access_remote_vm(NULL, mm, addr, buf, len, write);
98549 }
98550@@ -2054,7 +2045,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
98551 * Access another process' address space.
98552 * - source/target buffer must be kernel space
98553 */
98554-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
98555+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
98556 {
98557 struct mm_struct *mm;
98558
98559diff --git a/mm/page-writeback.c b/mm/page-writeback.c
98560index ba5fd97..5a95869 100644
98561--- a/mm/page-writeback.c
98562+++ b/mm/page-writeback.c
98563@@ -664,7 +664,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
98564 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
98565 * - the bdi dirty thresh drops quickly due to change of JBOD workload
98566 */
98567-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
98568+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
98569 unsigned long thresh,
98570 unsigned long bg_thresh,
98571 unsigned long dirty,
98572diff --git a/mm/page_alloc.c b/mm/page_alloc.c
98573index 8c5029f..d6907f0 100644
98574--- a/mm/page_alloc.c
98575+++ b/mm/page_alloc.c
98576@@ -61,6 +61,7 @@
98577 #include <linux/page-debug-flags.h>
98578 #include <linux/hugetlb.h>
98579 #include <linux/sched/rt.h>
98580+#include <linux/random.h>
98581
98582 #include <asm/sections.h>
98583 #include <asm/tlbflush.h>
98584@@ -357,7 +358,7 @@ out:
98585 * This usage means that zero-order pages may not be compound.
98586 */
98587
98588-static void free_compound_page(struct page *page)
98589+void free_compound_page(struct page *page)
98590 {
98591 __free_pages_ok(page, compound_order(page));
98592 }
98593@@ -751,6 +752,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98594 int i;
98595 int bad = 0;
98596
98597+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98598+ unsigned long index = 1UL << order;
98599+#endif
98600+
98601 trace_mm_page_free(page, order);
98602 kmemcheck_free_shadow(page, order);
98603
98604@@ -767,6 +772,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
98605 debug_check_no_obj_freed(page_address(page),
98606 PAGE_SIZE << order);
98607 }
98608+
98609+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98610+ for (; index; --index)
98611+ sanitize_highpage(page + index - 1);
98612+#endif
98613+
98614 arch_free_page(page, order);
98615 kernel_map_pages(page, 1 << order, 0);
98616
98617@@ -790,6 +801,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
98618 local_irq_restore(flags);
98619 }
98620
98621+#ifdef CONFIG_PAX_LATENT_ENTROPY
98622+bool __meminitdata extra_latent_entropy;
98623+
98624+static int __init setup_pax_extra_latent_entropy(char *str)
98625+{
98626+ extra_latent_entropy = true;
98627+ return 0;
98628+}
98629+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
98630+
98631+volatile u64 latent_entropy __latent_entropy;
98632+EXPORT_SYMBOL(latent_entropy);
98633+#endif
98634+
98635 void __init __free_pages_bootmem(struct page *page, unsigned int order)
98636 {
98637 unsigned int nr_pages = 1 << order;
98638@@ -805,6 +830,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
98639 __ClearPageReserved(p);
98640 set_page_count(p, 0);
98641
98642+#ifdef CONFIG_PAX_LATENT_ENTROPY
98643+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
98644+ u64 hash = 0;
98645+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
98646+ const u64 *data = lowmem_page_address(page);
98647+
98648+ for (index = 0; index < end; index++)
98649+ hash ^= hash + data[index];
98650+ latent_entropy ^= hash;
98651+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
98652+ }
98653+#endif
98654+
98655 page_zone(page)->managed_pages += nr_pages;
98656 set_page_refcounted(page);
98657 __free_pages(page, order);
98658@@ -933,8 +971,10 @@ static int prep_new_page(struct page *page, unsigned int order, gfp_t gfp_flags)
98659 arch_alloc_page(page, order);
98660 kernel_map_pages(page, 1 << order, 1);
98661
98662+#ifndef CONFIG_PAX_MEMORY_SANITIZE
98663 if (gfp_flags & __GFP_ZERO)
98664 prep_zero_page(page, order, gfp_flags);
98665+#endif
98666
98667 if (order && (gfp_flags & __GFP_COMP))
98668 prep_compound_page(page, order);
98669@@ -1612,7 +1652,7 @@ again:
98670 }
98671
98672 __mod_zone_page_state(zone, NR_ALLOC_BATCH, -(1 << order));
98673- if (atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98674+ if (atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]) <= 0 &&
98675 !zone_is_fair_depleted(zone))
98676 zone_set_flag(zone, ZONE_FAIR_DEPLETED);
98677
98678@@ -1933,7 +1973,7 @@ static void reset_alloc_batches(struct zone *preferred_zone)
98679 do {
98680 mod_zone_page_state(zone, NR_ALLOC_BATCH,
98681 high_wmark_pages(zone) - low_wmark_pages(zone) -
98682- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98683+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98684 zone_clear_flag(zone, ZONE_FAIR_DEPLETED);
98685 } while (zone++ != preferred_zone);
98686 }
98687@@ -5710,7 +5750,7 @@ static void __setup_per_zone_wmarks(void)
98688
98689 __mod_zone_page_state(zone, NR_ALLOC_BATCH,
98690 high_wmark_pages(zone) - low_wmark_pages(zone) -
98691- atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
98692+ atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
98693
98694 setup_zone_migrate_reserve(zone);
98695 spin_unlock_irqrestore(&zone->lock, flags);
98696diff --git a/mm/percpu.c b/mm/percpu.c
98697index 2139e30..1d45bce 100644
98698--- a/mm/percpu.c
98699+++ b/mm/percpu.c
98700@@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
98701 static unsigned int pcpu_high_unit_cpu __read_mostly;
98702
98703 /* the address of the first chunk which starts with the kernel static area */
98704-void *pcpu_base_addr __read_mostly;
98705+void *pcpu_base_addr __read_only;
98706 EXPORT_SYMBOL_GPL(pcpu_base_addr);
98707
98708 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
98709diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
98710index 5077afc..846c9ef 100644
98711--- a/mm/process_vm_access.c
98712+++ b/mm/process_vm_access.c
98713@@ -13,6 +13,7 @@
98714 #include <linux/uio.h>
98715 #include <linux/sched.h>
98716 #include <linux/highmem.h>
98717+#include <linux/security.h>
98718 #include <linux/ptrace.h>
98719 #include <linux/slab.h>
98720 #include <linux/syscalls.h>
98721@@ -157,19 +158,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98722 ssize_t iov_len;
98723 size_t total_len = iov_iter_count(iter);
98724
98725+ return -ENOSYS; // PaX: until properly audited
98726+
98727 /*
98728 * Work out how many pages of struct pages we're going to need
98729 * when eventually calling get_user_pages
98730 */
98731 for (i = 0; i < riovcnt; i++) {
98732 iov_len = rvec[i].iov_len;
98733- if (iov_len > 0) {
98734- nr_pages_iov = ((unsigned long)rvec[i].iov_base
98735- + iov_len)
98736- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
98737- / PAGE_SIZE + 1;
98738- nr_pages = max(nr_pages, nr_pages_iov);
98739- }
98740+ if (iov_len <= 0)
98741+ continue;
98742+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
98743+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
98744+ nr_pages = max(nr_pages, nr_pages_iov);
98745 }
98746
98747 if (nr_pages == 0)
98748@@ -197,6 +198,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
98749 goto free_proc_pages;
98750 }
98751
98752+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
98753+ rc = -EPERM;
98754+ goto put_task_struct;
98755+ }
98756+
98757 mm = mm_access(task, PTRACE_MODE_ATTACH);
98758 if (!mm || IS_ERR(mm)) {
98759 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
98760diff --git a/mm/rmap.c b/mm/rmap.c
98761index e01318d..25117ca 100644
98762--- a/mm/rmap.c
98763+++ b/mm/rmap.c
98764@@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98765 struct anon_vma *anon_vma = vma->anon_vma;
98766 struct anon_vma_chain *avc;
98767
98768+#ifdef CONFIG_PAX_SEGMEXEC
98769+ struct anon_vma_chain *avc_m = NULL;
98770+#endif
98771+
98772 might_sleep();
98773 if (unlikely(!anon_vma)) {
98774 struct mm_struct *mm = vma->vm_mm;
98775@@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98776 if (!avc)
98777 goto out_enomem;
98778
98779+#ifdef CONFIG_PAX_SEGMEXEC
98780+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
98781+ if (!avc_m)
98782+ goto out_enomem_free_avc;
98783+#endif
98784+
98785 anon_vma = find_mergeable_anon_vma(vma);
98786 allocated = NULL;
98787 if (!anon_vma) {
98788@@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98789 /* page_table_lock to protect against threads */
98790 spin_lock(&mm->page_table_lock);
98791 if (likely(!vma->anon_vma)) {
98792+
98793+#ifdef CONFIG_PAX_SEGMEXEC
98794+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
98795+
98796+ if (vma_m) {
98797+ BUG_ON(vma_m->anon_vma);
98798+ vma_m->anon_vma = anon_vma;
98799+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
98800+ avc_m = NULL;
98801+ }
98802+#endif
98803+
98804 vma->anon_vma = anon_vma;
98805 anon_vma_chain_link(vma, avc, anon_vma);
98806 allocated = NULL;
98807@@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
98808
98809 if (unlikely(allocated))
98810 put_anon_vma(allocated);
98811+
98812+#ifdef CONFIG_PAX_SEGMEXEC
98813+ if (unlikely(avc_m))
98814+ anon_vma_chain_free(avc_m);
98815+#endif
98816+
98817 if (unlikely(avc))
98818 anon_vma_chain_free(avc);
98819 }
98820 return 0;
98821
98822 out_enomem_free_avc:
98823+
98824+#ifdef CONFIG_PAX_SEGMEXEC
98825+ if (avc_m)
98826+ anon_vma_chain_free(avc_m);
98827+#endif
98828+
98829 anon_vma_chain_free(avc);
98830 out_enomem:
98831 return -ENOMEM;
98832@@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
98833 * Attach the anon_vmas from src to dst.
98834 * Returns 0 on success, -ENOMEM on failure.
98835 */
98836-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98837+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
98838 {
98839 struct anon_vma_chain *avc, *pavc;
98840 struct anon_vma *root = NULL;
98841@@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
98842 * the corresponding VMA in the parent process is attached to.
98843 * Returns 0 on success, non-zero on failure.
98844 */
98845-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
98846+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
98847 {
98848 struct anon_vma_chain *avc;
98849 struct anon_vma *anon_vma;
98850@@ -374,8 +408,10 @@ static void anon_vma_ctor(void *data)
98851 void __init anon_vma_init(void)
98852 {
98853 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
98854- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
98855- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
98856+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
98857+ anon_vma_ctor);
98858+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
98859+ SLAB_PANIC|SLAB_NO_SANITIZE);
98860 }
98861
98862 /*
98863diff --git a/mm/shmem.c b/mm/shmem.c
98864index 469f90d..34a09ee 100644
98865--- a/mm/shmem.c
98866+++ b/mm/shmem.c
98867@@ -33,7 +33,7 @@
98868 #include <linux/swap.h>
98869 #include <linux/aio.h>
98870
98871-static struct vfsmount *shm_mnt;
98872+struct vfsmount *shm_mnt;
98873
98874 #ifdef CONFIG_SHMEM
98875 /*
98876@@ -80,7 +80,7 @@ static struct vfsmount *shm_mnt;
98877 #define BOGO_DIRENT_SIZE 20
98878
98879 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
98880-#define SHORT_SYMLINK_LEN 128
98881+#define SHORT_SYMLINK_LEN 64
98882
98883 /*
98884 * shmem_fallocate communicates with shmem_fault or shmem_writepage via
98885@@ -2524,6 +2524,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
98886 static int shmem_xattr_validate(const char *name)
98887 {
98888 struct { const char *prefix; size_t len; } arr[] = {
98889+
98890+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98891+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
98892+#endif
98893+
98894 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
98895 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
98896 };
98897@@ -2579,6 +2584,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
98898 if (err)
98899 return err;
98900
98901+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
98902+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
98903+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
98904+ return -EOPNOTSUPP;
98905+ if (size > 8)
98906+ return -EINVAL;
98907+ }
98908+#endif
98909+
98910 return simple_xattr_set(&info->xattrs, name, value, size, flags);
98911 }
98912
98913@@ -2962,8 +2976,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
98914 int err = -ENOMEM;
98915
98916 /* Round up to L1_CACHE_BYTES to resist false sharing */
98917- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
98918- L1_CACHE_BYTES), GFP_KERNEL);
98919+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
98920 if (!sbinfo)
98921 return -ENOMEM;
98922
98923diff --git a/mm/slab.c b/mm/slab.c
98924index 7c52b38..3ccc17e 100644
98925--- a/mm/slab.c
98926+++ b/mm/slab.c
98927@@ -316,10 +316,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
98928 if ((x)->max_freeable < i) \
98929 (x)->max_freeable = i; \
98930 } while (0)
98931-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
98932-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
98933-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
98934-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
98935+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
98936+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
98937+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
98938+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
98939+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
98940+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
98941 #else
98942 #define STATS_INC_ACTIVE(x) do { } while (0)
98943 #define STATS_DEC_ACTIVE(x) do { } while (0)
98944@@ -336,6 +338,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
98945 #define STATS_INC_ALLOCMISS(x) do { } while (0)
98946 #define STATS_INC_FREEHIT(x) do { } while (0)
98947 #define STATS_INC_FREEMISS(x) do { } while (0)
98948+#define STATS_INC_SANITIZED(x) do { } while (0)
98949+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
98950 #endif
98951
98952 #if DEBUG
98953@@ -452,7 +456,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
98954 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
98955 */
98956 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
98957- const struct page *page, void *obj)
98958+ const struct page *page, const void *obj)
98959 {
98960 u32 offset = (obj - page->s_mem);
98961 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
98962@@ -1462,12 +1466,12 @@ void __init kmem_cache_init(void)
98963 */
98964
98965 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
98966- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
98967+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
98968
98969 if (INDEX_AC != INDEX_NODE)
98970 kmalloc_caches[INDEX_NODE] =
98971 create_kmalloc_cache("kmalloc-node",
98972- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
98973+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
98974
98975 slab_early_init = 0;
98976
98977@@ -3384,6 +3388,20 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
98978 struct array_cache *ac = cpu_cache_get(cachep);
98979
98980 check_irq_off();
98981+
98982+#ifdef CONFIG_PAX_MEMORY_SANITIZE
98983+ if (cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))
98984+ STATS_INC_NOT_SANITIZED(cachep);
98985+ else {
98986+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
98987+
98988+ if (cachep->ctor)
98989+ cachep->ctor(objp);
98990+
98991+ STATS_INC_SANITIZED(cachep);
98992+ }
98993+#endif
98994+
98995 kmemleak_free_recursive(objp, cachep->flags);
98996 objp = cache_free_debugcheck(cachep, objp, caller);
98997
98998@@ -3607,6 +3625,7 @@ void kfree(const void *objp)
98999
99000 if (unlikely(ZERO_OR_NULL_PTR(objp)))
99001 return;
99002+ VM_BUG_ON(!virt_addr_valid(objp));
99003 local_irq_save(flags);
99004 kfree_debugcheck(objp);
99005 c = virt_to_cache(objp);
99006@@ -4056,14 +4075,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
99007 }
99008 /* cpu stats */
99009 {
99010- unsigned long allochit = atomic_read(&cachep->allochit);
99011- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
99012- unsigned long freehit = atomic_read(&cachep->freehit);
99013- unsigned long freemiss = atomic_read(&cachep->freemiss);
99014+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
99015+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
99016+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
99017+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
99018
99019 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
99020 allochit, allocmiss, freehit, freemiss);
99021 }
99022+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99023+ {
99024+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
99025+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
99026+
99027+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
99028+ }
99029+#endif
99030 #endif
99031 }
99032
99033@@ -4281,13 +4308,69 @@ static const struct file_operations proc_slabstats_operations = {
99034 static int __init slab_proc_init(void)
99035 {
99036 #ifdef CONFIG_DEBUG_SLAB_LEAK
99037- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
99038+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
99039 #endif
99040 return 0;
99041 }
99042 module_init(slab_proc_init);
99043 #endif
99044
99045+bool is_usercopy_object(const void *ptr)
99046+{
99047+ struct page *page;
99048+ struct kmem_cache *cachep;
99049+
99050+ if (ZERO_OR_NULL_PTR(ptr))
99051+ return false;
99052+
99053+ if (!slab_is_available())
99054+ return false;
99055+
99056+ if (!virt_addr_valid(ptr))
99057+ return false;
99058+
99059+ page = virt_to_head_page(ptr);
99060+
99061+ if (!PageSlab(page))
99062+ return false;
99063+
99064+ cachep = page->slab_cache;
99065+ return cachep->flags & SLAB_USERCOPY;
99066+}
99067+
99068+#ifdef CONFIG_PAX_USERCOPY
99069+const char *check_heap_object(const void *ptr, unsigned long n)
99070+{
99071+ struct page *page;
99072+ struct kmem_cache *cachep;
99073+ unsigned int objnr;
99074+ unsigned long offset;
99075+
99076+ if (ZERO_OR_NULL_PTR(ptr))
99077+ return "<null>";
99078+
99079+ if (!virt_addr_valid(ptr))
99080+ return NULL;
99081+
99082+ page = virt_to_head_page(ptr);
99083+
99084+ if (!PageSlab(page))
99085+ return NULL;
99086+
99087+ cachep = page->slab_cache;
99088+ if (!(cachep->flags & SLAB_USERCOPY))
99089+ return cachep->name;
99090+
99091+ objnr = obj_to_index(cachep, page, ptr);
99092+ BUG_ON(objnr >= cachep->num);
99093+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
99094+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
99095+ return NULL;
99096+
99097+ return cachep->name;
99098+}
99099+#endif
99100+
99101 /**
99102 * ksize - get the actual amount of memory allocated for a given object
99103 * @objp: Pointer to the object
99104diff --git a/mm/slab.h b/mm/slab.h
99105index 0e0fdd3..d0fd761 100644
99106--- a/mm/slab.h
99107+++ b/mm/slab.h
99108@@ -32,6 +32,20 @@ extern struct list_head slab_caches;
99109 /* The slab cache that manages slab cache information */
99110 extern struct kmem_cache *kmem_cache;
99111
99112+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99113+#ifdef CONFIG_X86_64
99114+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
99115+#else
99116+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
99117+#endif
99118+enum pax_sanitize_mode {
99119+ PAX_SANITIZE_SLAB_OFF = 0,
99120+ PAX_SANITIZE_SLAB_FAST,
99121+ PAX_SANITIZE_SLAB_FULL,
99122+};
99123+extern enum pax_sanitize_mode pax_sanitize_slab;
99124+#endif
99125+
99126 unsigned long calculate_alignment(unsigned long flags,
99127 unsigned long align, unsigned long size);
99128
99129@@ -67,7 +81,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99130
99131 /* Legal flag mask for kmem_cache_create(), for various configurations */
99132 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
99133- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
99134+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
99135+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
99136
99137 #if defined(CONFIG_DEBUG_SLAB)
99138 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
99139@@ -251,6 +266,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
99140 return s;
99141
99142 page = virt_to_head_page(x);
99143+
99144+ BUG_ON(!PageSlab(page));
99145+
99146 cachep = page->slab_cache;
99147 if (slab_equal_or_root(cachep, s))
99148 return cachep;
99149diff --git a/mm/slab_common.c b/mm/slab_common.c
99150index d319502..da7714e 100644
99151--- a/mm/slab_common.c
99152+++ b/mm/slab_common.c
99153@@ -25,11 +25,35 @@
99154
99155 #include "slab.h"
99156
99157-enum slab_state slab_state;
99158+enum slab_state slab_state __read_only;
99159 LIST_HEAD(slab_caches);
99160 DEFINE_MUTEX(slab_mutex);
99161 struct kmem_cache *kmem_cache;
99162
99163+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99164+enum pax_sanitize_mode pax_sanitize_slab __read_only = PAX_SANITIZE_SLAB_FAST;
99165+static int __init pax_sanitize_slab_setup(char *str)
99166+{
99167+ if (!str)
99168+ return 0;
99169+
99170+ if (!strcmp(str, "0") || !strcmp(str, "off")) {
99171+ pr_info("PaX slab sanitization: %s\n", "disabled");
99172+ pax_sanitize_slab = PAX_SANITIZE_SLAB_OFF;
99173+ } else if (!strcmp(str, "1") || !strcmp(str, "fast")) {
99174+ pr_info("PaX slab sanitization: %s\n", "fast");
99175+ pax_sanitize_slab = PAX_SANITIZE_SLAB_FAST;
99176+ } else if (!strcmp(str, "full")) {
99177+ pr_info("PaX slab sanitization: %s\n", "full");
99178+ pax_sanitize_slab = PAX_SANITIZE_SLAB_FULL;
99179+ } else
99180+ pr_err("PaX slab sanitization: unsupported option '%s'\n", str);
99181+
99182+ return 0;
99183+}
99184+early_param("pax_sanitize_slab", pax_sanitize_slab_setup);
99185+#endif
99186+
99187 #ifdef CONFIG_DEBUG_VM
99188 static int kmem_cache_sanity_check(const char *name, size_t size)
99189 {
99190@@ -160,7 +184,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
99191 if (err)
99192 goto out_free_cache;
99193
99194- s->refcount = 1;
99195+ atomic_set(&s->refcount, 1);
99196 list_add(&s->list, &slab_caches);
99197 out:
99198 if (err)
99199@@ -222,6 +246,13 @@ kmem_cache_create(const char *name, size_t size, size_t align,
99200 */
99201 flags &= CACHE_CREATE_MASK;
99202
99203+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99204+ if (pax_sanitize_slab == PAX_SANITIZE_SLAB_OFF || (flags & SLAB_DESTROY_BY_RCU))
99205+ flags |= SLAB_NO_SANITIZE;
99206+ else if (pax_sanitize_slab == PAX_SANITIZE_SLAB_FULL)
99207+ flags &= ~SLAB_NO_SANITIZE;
99208+#endif
99209+
99210 s = __kmem_cache_alias(name, size, align, flags, ctor);
99211 if (s)
99212 goto out_unlock;
99213@@ -341,8 +372,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99214
99215 mutex_lock(&slab_mutex);
99216
99217- s->refcount--;
99218- if (s->refcount)
99219+ if (!atomic_dec_and_test(&s->refcount))
99220 goto out_unlock;
99221
99222 if (memcg_cleanup_cache_params(s) != 0)
99223@@ -362,7 +392,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
99224 rcu_barrier();
99225
99226 memcg_free_cache_params(s);
99227-#ifdef SLAB_SUPPORTS_SYSFS
99228+#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99229 sysfs_slab_remove(s);
99230 #else
99231 slab_kmem_cache_release(s);
99232@@ -418,7 +448,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
99233 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
99234 name, size, err);
99235
99236- s->refcount = -1; /* Exempt from merging for now */
99237+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
99238 }
99239
99240 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99241@@ -431,7 +461,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
99242
99243 create_boot_cache(s, name, size, flags);
99244 list_add(&s->list, &slab_caches);
99245- s->refcount = 1;
99246+ atomic_set(&s->refcount, 1);
99247 return s;
99248 }
99249
99250@@ -443,6 +473,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
99251 EXPORT_SYMBOL(kmalloc_dma_caches);
99252 #endif
99253
99254+#ifdef CONFIG_PAX_USERCOPY_SLABS
99255+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
99256+EXPORT_SYMBOL(kmalloc_usercopy_caches);
99257+#endif
99258+
99259 /*
99260 * Conversion table for small slabs sizes / 8 to the index in the
99261 * kmalloc array. This is necessary for slabs < 192 since we have non power
99262@@ -507,6 +542,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
99263 return kmalloc_dma_caches[index];
99264
99265 #endif
99266+
99267+#ifdef CONFIG_PAX_USERCOPY_SLABS
99268+ if (unlikely((flags & GFP_USERCOPY)))
99269+ return kmalloc_usercopy_caches[index];
99270+
99271+#endif
99272+
99273 return kmalloc_caches[index];
99274 }
99275
99276@@ -563,7 +605,7 @@ void __init create_kmalloc_caches(unsigned long flags)
99277 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
99278 if (!kmalloc_caches[i]) {
99279 kmalloc_caches[i] = create_kmalloc_cache(NULL,
99280- 1 << i, flags);
99281+ 1 << i, SLAB_USERCOPY | flags);
99282 }
99283
99284 /*
99285@@ -572,10 +614,10 @@ void __init create_kmalloc_caches(unsigned long flags)
99286 * earlier power of two caches
99287 */
99288 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
99289- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
99290+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
99291
99292 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
99293- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
99294+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
99295 }
99296
99297 /* Kmalloc array is now usable */
99298@@ -608,6 +650,23 @@ void __init create_kmalloc_caches(unsigned long flags)
99299 }
99300 }
99301 #endif
99302+
99303+#ifdef CONFIG_PAX_USERCOPY_SLABS
99304+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
99305+ struct kmem_cache *s = kmalloc_caches[i];
99306+
99307+ if (s) {
99308+ int size = kmalloc_size(i);
99309+ char *n = kasprintf(GFP_NOWAIT,
99310+ "usercopy-kmalloc-%d", size);
99311+
99312+ BUG_ON(!n);
99313+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
99314+ size, SLAB_USERCOPY | flags);
99315+ }
99316+ }
99317+#endif
99318+
99319 }
99320 #endif /* !CONFIG_SLOB */
99321
99322@@ -666,6 +725,9 @@ void print_slabinfo_header(struct seq_file *m)
99323 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
99324 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
99325 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
99326+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99327+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
99328+#endif
99329 #endif
99330 seq_putc(m, '\n');
99331 }
99332diff --git a/mm/slob.c b/mm/slob.c
99333index 21980e0..975f1bf 100644
99334--- a/mm/slob.c
99335+++ b/mm/slob.c
99336@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
99337 /*
99338 * Return the size of a slob block.
99339 */
99340-static slobidx_t slob_units(slob_t *s)
99341+static slobidx_t slob_units(const slob_t *s)
99342 {
99343 if (s->units > 0)
99344 return s->units;
99345@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
99346 /*
99347 * Return the next free slob block pointer after this one.
99348 */
99349-static slob_t *slob_next(slob_t *s)
99350+static slob_t *slob_next(const slob_t *s)
99351 {
99352 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
99353 slobidx_t next;
99354@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
99355 /*
99356 * Returns true if s is the last free block in its page.
99357 */
99358-static int slob_last(slob_t *s)
99359+static int slob_last(const slob_t *s)
99360 {
99361 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
99362 }
99363
99364-static void *slob_new_pages(gfp_t gfp, int order, int node)
99365+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
99366 {
99367- void *page;
99368+ struct page *page;
99369
99370 #ifdef CONFIG_NUMA
99371 if (node != NUMA_NO_NODE)
99372@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
99373 if (!page)
99374 return NULL;
99375
99376- return page_address(page);
99377+ __SetPageSlab(page);
99378+ return page;
99379 }
99380
99381-static void slob_free_pages(void *b, int order)
99382+static void slob_free_pages(struct page *sp, int order)
99383 {
99384 if (current->reclaim_state)
99385 current->reclaim_state->reclaimed_slab += 1 << order;
99386- free_pages((unsigned long)b, order);
99387+ __ClearPageSlab(sp);
99388+ page_mapcount_reset(sp);
99389+ sp->private = 0;
99390+ __free_pages(sp, order);
99391 }
99392
99393 /*
99394@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99395
99396 /* Not enough space: must allocate a new page */
99397 if (!b) {
99398- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99399- if (!b)
99400+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
99401+ if (!sp)
99402 return NULL;
99403- sp = virt_to_page(b);
99404- __SetPageSlab(sp);
99405+ b = page_address(sp);
99406
99407 spin_lock_irqsave(&slob_lock, flags);
99408 sp->units = SLOB_UNITS(PAGE_SIZE);
99409 sp->freelist = b;
99410+ sp->private = 0;
99411 INIT_LIST_HEAD(&sp->lru);
99412 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
99413 set_slob_page_free(sp, slob_list);
99414@@ -337,7 +341,7 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
99415 /*
99416 * slob_free: entry point into the slob allocator.
99417 */
99418-static void slob_free(void *block, int size)
99419+static void slob_free(struct kmem_cache *c, void *block, int size)
99420 {
99421 struct page *sp;
99422 slob_t *prev, *next, *b = (slob_t *)block;
99423@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
99424 if (slob_page_free(sp))
99425 clear_slob_page_free(sp);
99426 spin_unlock_irqrestore(&slob_lock, flags);
99427- __ClearPageSlab(sp);
99428- page_mapcount_reset(sp);
99429- slob_free_pages(b, 0);
99430+ slob_free_pages(sp, 0);
99431 return;
99432 }
99433
99434+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99435+ if (pax_sanitize_slab && !(c && (c->flags & SLAB_NO_SANITIZE)))
99436+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
99437+#endif
99438+
99439 if (!slob_page_free(sp)) {
99440 /* This slob page is about to become partially free. Easy! */
99441 sp->units = units;
99442@@ -424,11 +431,10 @@ out:
99443 */
99444
99445 static __always_inline void *
99446-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99447+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
99448 {
99449- unsigned int *m;
99450- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99451- void *ret;
99452+ slob_t *m;
99453+ void *ret = NULL;
99454
99455 gfp &= gfp_allowed_mask;
99456
99457@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99458
99459 if (!m)
99460 return NULL;
99461- *m = size;
99462+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
99463+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
99464+ m[0].units = size;
99465+ m[1].units = align;
99466 ret = (void *)m + align;
99467
99468 trace_kmalloc_node(caller, ret,
99469 size, size + align, gfp, node);
99470 } else {
99471 unsigned int order = get_order(size);
99472+ struct page *page;
99473
99474 if (likely(order))
99475 gfp |= __GFP_COMP;
99476- ret = slob_new_pages(gfp, order, node);
99477+ page = slob_new_pages(gfp, order, node);
99478+ if (page) {
99479+ ret = page_address(page);
99480+ page->private = size;
99481+ }
99482
99483 trace_kmalloc_node(caller, ret,
99484 size, PAGE_SIZE << order, gfp, node);
99485 }
99486
99487- kmemleak_alloc(ret, size, 1, gfp);
99488+ return ret;
99489+}
99490+
99491+static __always_inline void *
99492+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
99493+{
99494+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99495+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
99496+
99497+ if (!ZERO_OR_NULL_PTR(ret))
99498+ kmemleak_alloc(ret, size, 1, gfp);
99499 return ret;
99500 }
99501
99502@@ -493,34 +517,112 @@ void kfree(const void *block)
99503 return;
99504 kmemleak_free(block);
99505
99506+ VM_BUG_ON(!virt_addr_valid(block));
99507 sp = virt_to_page(block);
99508- if (PageSlab(sp)) {
99509+ VM_BUG_ON(!PageSlab(sp));
99510+ if (!sp->private) {
99511 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99512- unsigned int *m = (unsigned int *)(block - align);
99513- slob_free(m, *m + align);
99514- } else
99515+ slob_t *m = (slob_t *)(block - align);
99516+ slob_free(NULL, m, m[0].units + align);
99517+ } else {
99518+ __ClearPageSlab(sp);
99519+ page_mapcount_reset(sp);
99520+ sp->private = 0;
99521 __free_pages(sp, compound_order(sp));
99522+ }
99523 }
99524 EXPORT_SYMBOL(kfree);
99525
99526+bool is_usercopy_object(const void *ptr)
99527+{
99528+ if (!slab_is_available())
99529+ return false;
99530+
99531+ // PAX: TODO
99532+
99533+ return false;
99534+}
99535+
99536+#ifdef CONFIG_PAX_USERCOPY
99537+const char *check_heap_object(const void *ptr, unsigned long n)
99538+{
99539+ struct page *page;
99540+ const slob_t *free;
99541+ const void *base;
99542+ unsigned long flags;
99543+
99544+ if (ZERO_OR_NULL_PTR(ptr))
99545+ return "<null>";
99546+
99547+ if (!virt_addr_valid(ptr))
99548+ return NULL;
99549+
99550+ page = virt_to_head_page(ptr);
99551+ if (!PageSlab(page))
99552+ return NULL;
99553+
99554+ if (page->private) {
99555+ base = page;
99556+ if (base <= ptr && n <= page->private - (ptr - base))
99557+ return NULL;
99558+ return "<slob>";
99559+ }
99560+
99561+ /* some tricky double walking to find the chunk */
99562+ spin_lock_irqsave(&slob_lock, flags);
99563+ base = (void *)((unsigned long)ptr & PAGE_MASK);
99564+ free = page->freelist;
99565+
99566+ while (!slob_last(free) && (void *)free <= ptr) {
99567+ base = free + slob_units(free);
99568+ free = slob_next(free);
99569+ }
99570+
99571+ while (base < (void *)free) {
99572+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
99573+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
99574+ int offset;
99575+
99576+ if (ptr < base + align)
99577+ break;
99578+
99579+ offset = ptr - base - align;
99580+ if (offset >= m) {
99581+ base += size;
99582+ continue;
99583+ }
99584+
99585+ if (n > m - offset)
99586+ break;
99587+
99588+ spin_unlock_irqrestore(&slob_lock, flags);
99589+ return NULL;
99590+ }
99591+
99592+ spin_unlock_irqrestore(&slob_lock, flags);
99593+ return "<slob>";
99594+}
99595+#endif
99596+
99597 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
99598 size_t ksize(const void *block)
99599 {
99600 struct page *sp;
99601 int align;
99602- unsigned int *m;
99603+ slob_t *m;
99604
99605 BUG_ON(!block);
99606 if (unlikely(block == ZERO_SIZE_PTR))
99607 return 0;
99608
99609 sp = virt_to_page(block);
99610- if (unlikely(!PageSlab(sp)))
99611- return PAGE_SIZE << compound_order(sp);
99612+ VM_BUG_ON(!PageSlab(sp));
99613+ if (sp->private)
99614+ return sp->private;
99615
99616 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
99617- m = (unsigned int *)(block - align);
99618- return SLOB_UNITS(*m) * SLOB_UNIT;
99619+ m = (slob_t *)(block - align);
99620+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
99621 }
99622 EXPORT_SYMBOL(ksize);
99623
99624@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
99625
99626 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
99627 {
99628- void *b;
99629+ void *b = NULL;
99630
99631 flags &= gfp_allowed_mask;
99632
99633 lockdep_trace_alloc(flags);
99634
99635+#ifdef CONFIG_PAX_USERCOPY_SLABS
99636+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
99637+#else
99638 if (c->size < PAGE_SIZE) {
99639 b = slob_alloc(c->size, flags, c->align, node);
99640 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99641 SLOB_UNITS(c->size) * SLOB_UNIT,
99642 flags, node);
99643 } else {
99644- b = slob_new_pages(flags, get_order(c->size), node);
99645+ struct page *sp;
99646+
99647+ sp = slob_new_pages(flags, get_order(c->size), node);
99648+ if (sp) {
99649+ b = page_address(sp);
99650+ sp->private = c->size;
99651+ }
99652 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
99653 PAGE_SIZE << get_order(c->size),
99654 flags, node);
99655 }
99656+#endif
99657
99658 if (b && c->ctor)
99659 c->ctor(b);
99660@@ -582,12 +694,16 @@ void *kmem_cache_alloc_node(struct kmem_cache *cachep, gfp_t gfp, int node)
99661 EXPORT_SYMBOL(kmem_cache_alloc_node);
99662 #endif
99663
99664-static void __kmem_cache_free(void *b, int size)
99665+static void __kmem_cache_free(struct kmem_cache *c, void *b, int size)
99666 {
99667- if (size < PAGE_SIZE)
99668- slob_free(b, size);
99669+ struct page *sp;
99670+
99671+ sp = virt_to_page(b);
99672+ BUG_ON(!PageSlab(sp));
99673+ if (!sp->private)
99674+ slob_free(c, b, size);
99675 else
99676- slob_free_pages(b, get_order(size));
99677+ slob_free_pages(sp, get_order(size));
99678 }
99679
99680 static void kmem_rcu_free(struct rcu_head *head)
99681@@ -595,22 +711,36 @@ static void kmem_rcu_free(struct rcu_head *head)
99682 struct slob_rcu *slob_rcu = (struct slob_rcu *)head;
99683 void *b = (void *)slob_rcu - (slob_rcu->size - sizeof(struct slob_rcu));
99684
99685- __kmem_cache_free(b, slob_rcu->size);
99686+ __kmem_cache_free(NULL, b, slob_rcu->size);
99687 }
99688
99689 void kmem_cache_free(struct kmem_cache *c, void *b)
99690 {
99691+ int size = c->size;
99692+
99693+#ifdef CONFIG_PAX_USERCOPY_SLABS
99694+ if (size + c->align < PAGE_SIZE) {
99695+ size += c->align;
99696+ b -= c->align;
99697+ }
99698+#endif
99699+
99700 kmemleak_free_recursive(b, c->flags);
99701 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
99702 struct slob_rcu *slob_rcu;
99703- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
99704- slob_rcu->size = c->size;
99705+ slob_rcu = b + (size - sizeof(struct slob_rcu));
99706+ slob_rcu->size = size;
99707 call_rcu(&slob_rcu->head, kmem_rcu_free);
99708 } else {
99709- __kmem_cache_free(b, c->size);
99710+ __kmem_cache_free(c, b, size);
99711 }
99712
99713+#ifdef CONFIG_PAX_USERCOPY_SLABS
99714+ trace_kfree(_RET_IP_, b);
99715+#else
99716 trace_kmem_cache_free(_RET_IP_, b);
99717+#endif
99718+
99719 }
99720 EXPORT_SYMBOL(kmem_cache_free);
99721
99722diff --git a/mm/slub.c b/mm/slub.c
99723index 3e8afcc..d6e2c89 100644
99724--- a/mm/slub.c
99725+++ b/mm/slub.c
99726@@ -207,7 +207,7 @@ struct track {
99727
99728 enum track_item { TRACK_ALLOC, TRACK_FREE };
99729
99730-#ifdef CONFIG_SYSFS
99731+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99732 static int sysfs_slab_add(struct kmem_cache *);
99733 static int sysfs_slab_alias(struct kmem_cache *, const char *);
99734 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
99735@@ -545,7 +545,7 @@ static void print_track(const char *s, struct track *t)
99736 if (!t->addr)
99737 return;
99738
99739- pr_err("INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
99740+ pr_err("INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
99741 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
99742 #ifdef CONFIG_STACKTRACE
99743 {
99744@@ -2643,6 +2643,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
99745
99746 slab_free_hook(s, x);
99747
99748+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99749+ if (!(s->flags & SLAB_NO_SANITIZE)) {
99750+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
99751+ if (s->ctor)
99752+ s->ctor(x);
99753+ }
99754+#endif
99755+
99756 redo:
99757 /*
99758 * Determine the currently cpus per cpu slab.
99759@@ -2710,7 +2718,7 @@ static int slub_min_objects;
99760 * Merge control. If this is set then no merging of slab caches will occur.
99761 * (Could be removed. This was introduced to pacify the merge skeptics.)
99762 */
99763-static int slub_nomerge;
99764+static int slub_nomerge = 1;
99765
99766 /*
99767 * Calculate the order of allocation given an slab object size.
99768@@ -2986,6 +2994,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
99769 s->inuse = size;
99770
99771 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
99772+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99773+ (!(flags & SLAB_NO_SANITIZE)) ||
99774+#endif
99775 s->ctor)) {
99776 /*
99777 * Relocate free pointer after the object if it is not
99778@@ -3313,6 +3324,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
99779 EXPORT_SYMBOL(__kmalloc_node);
99780 #endif
99781
99782+bool is_usercopy_object(const void *ptr)
99783+{
99784+ struct page *page;
99785+ struct kmem_cache *s;
99786+
99787+ if (ZERO_OR_NULL_PTR(ptr))
99788+ return false;
99789+
99790+ if (!slab_is_available())
99791+ return false;
99792+
99793+ if (!virt_addr_valid(ptr))
99794+ return false;
99795+
99796+ page = virt_to_head_page(ptr);
99797+
99798+ if (!PageSlab(page))
99799+ return false;
99800+
99801+ s = page->slab_cache;
99802+ return s->flags & SLAB_USERCOPY;
99803+}
99804+
99805+#ifdef CONFIG_PAX_USERCOPY
99806+const char *check_heap_object(const void *ptr, unsigned long n)
99807+{
99808+ struct page *page;
99809+ struct kmem_cache *s;
99810+ unsigned long offset;
99811+
99812+ if (ZERO_OR_NULL_PTR(ptr))
99813+ return "<null>";
99814+
99815+ if (!virt_addr_valid(ptr))
99816+ return NULL;
99817+
99818+ page = virt_to_head_page(ptr);
99819+
99820+ if (!PageSlab(page))
99821+ return NULL;
99822+
99823+ s = page->slab_cache;
99824+ if (!(s->flags & SLAB_USERCOPY))
99825+ return s->name;
99826+
99827+ offset = (ptr - page_address(page)) % s->size;
99828+ if (offset <= s->object_size && n <= s->object_size - offset)
99829+ return NULL;
99830+
99831+ return s->name;
99832+}
99833+#endif
99834+
99835 size_t ksize(const void *object)
99836 {
99837 struct page *page;
99838@@ -3341,6 +3405,7 @@ void kfree(const void *x)
99839 if (unlikely(ZERO_OR_NULL_PTR(x)))
99840 return;
99841
99842+ VM_BUG_ON(!virt_addr_valid(x));
99843 page = virt_to_head_page(x);
99844 if (unlikely(!PageSlab(page))) {
99845 BUG_ON(!PageCompound(page));
99846@@ -3642,7 +3707,7 @@ static int slab_unmergeable(struct kmem_cache *s)
99847 /*
99848 * We may have set a slab to be unmergeable during bootstrap.
99849 */
99850- if (s->refcount < 0)
99851+ if (atomic_read(&s->refcount) < 0)
99852 return 1;
99853
99854 return 0;
99855@@ -3699,7 +3764,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99856 int i;
99857 struct kmem_cache *c;
99858
99859- s->refcount++;
99860+ atomic_inc(&s->refcount);
99861
99862 /*
99863 * Adjust the object sizes so that we clear
99864@@ -3718,7 +3783,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
99865 }
99866
99867 if (sysfs_slab_alias(s, name)) {
99868- s->refcount--;
99869+ atomic_dec(&s->refcount);
99870 s = NULL;
99871 }
99872 }
99873@@ -3835,7 +3900,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
99874 }
99875 #endif
99876
99877-#ifdef CONFIG_SYSFS
99878+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99879 static int count_inuse(struct page *page)
99880 {
99881 return page->inuse;
99882@@ -4116,7 +4181,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
99883 len += sprintf(buf + len, "%7ld ", l->count);
99884
99885 if (l->addr)
99886+#ifdef CONFIG_GRKERNSEC_HIDESYM
99887+ len += sprintf(buf + len, "%pS", NULL);
99888+#else
99889 len += sprintf(buf + len, "%pS", (void *)l->addr);
99890+#endif
99891 else
99892 len += sprintf(buf + len, "<not-available>");
99893
99894@@ -4218,12 +4287,12 @@ static void __init resiliency_test(void)
99895 validate_slab_cache(kmalloc_caches[9]);
99896 }
99897 #else
99898-#ifdef CONFIG_SYSFS
99899+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99900 static void resiliency_test(void) {};
99901 #endif
99902 #endif
99903
99904-#ifdef CONFIG_SYSFS
99905+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99906 enum slab_stat_type {
99907 SL_ALL, /* All slabs */
99908 SL_PARTIAL, /* Only partially allocated slabs */
99909@@ -4460,13 +4529,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
99910 {
99911 if (!s->ctor)
99912 return 0;
99913+#ifdef CONFIG_GRKERNSEC_HIDESYM
99914+ return sprintf(buf, "%pS\n", NULL);
99915+#else
99916 return sprintf(buf, "%pS\n", s->ctor);
99917+#endif
99918 }
99919 SLAB_ATTR_RO(ctor);
99920
99921 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
99922 {
99923- return sprintf(buf, "%d\n", s->refcount < 0 ? 0 : s->refcount - 1);
99924+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) < 0 ? 0 : atomic_read(&s->refcount) - 1);
99925 }
99926 SLAB_ATTR_RO(aliases);
99927
99928@@ -4554,6 +4627,22 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
99929 SLAB_ATTR_RO(cache_dma);
99930 #endif
99931
99932+#ifdef CONFIG_PAX_USERCOPY_SLABS
99933+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
99934+{
99935+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
99936+}
99937+SLAB_ATTR_RO(usercopy);
99938+#endif
99939+
99940+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99941+static ssize_t sanitize_show(struct kmem_cache *s, char *buf)
99942+{
99943+ return sprintf(buf, "%d\n", !(s->flags & SLAB_NO_SANITIZE));
99944+}
99945+SLAB_ATTR_RO(sanitize);
99946+#endif
99947+
99948 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
99949 {
99950 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
99951@@ -4888,6 +4977,12 @@ static struct attribute *slab_attrs[] = {
99952 #ifdef CONFIG_ZONE_DMA
99953 &cache_dma_attr.attr,
99954 #endif
99955+#ifdef CONFIG_PAX_USERCOPY_SLABS
99956+ &usercopy_attr.attr,
99957+#endif
99958+#ifdef CONFIG_PAX_MEMORY_SANITIZE
99959+ &sanitize_attr.attr,
99960+#endif
99961 #ifdef CONFIG_NUMA
99962 &remote_node_defrag_ratio_attr.attr,
99963 #endif
99964@@ -5132,6 +5227,7 @@ static char *create_unique_id(struct kmem_cache *s)
99965 return name;
99966 }
99967
99968+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99969 static int sysfs_slab_add(struct kmem_cache *s)
99970 {
99971 int err;
99972@@ -5205,6 +5301,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
99973 kobject_del(&s->kobj);
99974 kobject_put(&s->kobj);
99975 }
99976+#endif
99977
99978 /*
99979 * Need to buffer aliases during bootup until sysfs becomes
99980@@ -5218,6 +5315,7 @@ struct saved_alias {
99981
99982 static struct saved_alias *alias_list;
99983
99984+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
99985 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
99986 {
99987 struct saved_alias *al;
99988@@ -5240,6 +5338,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
99989 alias_list = al;
99990 return 0;
99991 }
99992+#endif
99993
99994 static int __init slab_sysfs_init(void)
99995 {
99996diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
99997index 4cba9c2..b4f9fcc 100644
99998--- a/mm/sparse-vmemmap.c
99999+++ b/mm/sparse-vmemmap.c
100000@@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
100001 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100002 if (!p)
100003 return NULL;
100004- pud_populate(&init_mm, pud, p);
100005+ pud_populate_kernel(&init_mm, pud, p);
100006 }
100007 return pud;
100008 }
100009@@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
100010 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
100011 if (!p)
100012 return NULL;
100013- pgd_populate(&init_mm, pgd, p);
100014+ pgd_populate_kernel(&init_mm, pgd, p);
100015 }
100016 return pgd;
100017 }
100018diff --git a/mm/sparse.c b/mm/sparse.c
100019index d1b48b6..6e8590e 100644
100020--- a/mm/sparse.c
100021+++ b/mm/sparse.c
100022@@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
100023
100024 for (i = 0; i < PAGES_PER_SECTION; i++) {
100025 if (PageHWPoison(&memmap[i])) {
100026- atomic_long_sub(1, &num_poisoned_pages);
100027+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
100028 ClearPageHWPoison(&memmap[i]);
100029 }
100030 }
100031diff --git a/mm/swap.c b/mm/swap.c
100032index 6b2dc38..46b79ba 100644
100033--- a/mm/swap.c
100034+++ b/mm/swap.c
100035@@ -31,6 +31,7 @@
100036 #include <linux/memcontrol.h>
100037 #include <linux/gfp.h>
100038 #include <linux/uio.h>
100039+#include <linux/hugetlb.h>
100040
100041 #include "internal.h"
100042
100043@@ -77,6 +78,8 @@ static void __put_compound_page(struct page *page)
100044
100045 __page_cache_release(page);
100046 dtor = get_compound_page_dtor(page);
100047+ if (!PageHuge(page))
100048+ BUG_ON(dtor != free_compound_page);
100049 (*dtor)(page);
100050 }
100051
100052diff --git a/mm/swapfile.c b/mm/swapfile.c
100053index 8798b2e..348f9dd 100644
100054--- a/mm/swapfile.c
100055+++ b/mm/swapfile.c
100056@@ -84,7 +84,7 @@ static DEFINE_MUTEX(swapon_mutex);
100057
100058 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
100059 /* Activity counter to indicate that a swapon or swapoff has occurred */
100060-static atomic_t proc_poll_event = ATOMIC_INIT(0);
100061+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
100062
100063 static inline unsigned char swap_count(unsigned char ent)
100064 {
100065@@ -1944,7 +1944,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
100066 spin_unlock(&swap_lock);
100067
100068 err = 0;
100069- atomic_inc(&proc_poll_event);
100070+ atomic_inc_unchecked(&proc_poll_event);
100071 wake_up_interruptible(&proc_poll_wait);
100072
100073 out_dput:
100074@@ -1961,8 +1961,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
100075
100076 poll_wait(file, &proc_poll_wait, wait);
100077
100078- if (seq->poll_event != atomic_read(&proc_poll_event)) {
100079- seq->poll_event = atomic_read(&proc_poll_event);
100080+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
100081+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100082 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
100083 }
100084
100085@@ -2060,7 +2060,7 @@ static int swaps_open(struct inode *inode, struct file *file)
100086 return ret;
100087
100088 seq = file->private_data;
100089- seq->poll_event = atomic_read(&proc_poll_event);
100090+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
100091 return 0;
100092 }
100093
100094@@ -2520,7 +2520,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
100095 (frontswap_map) ? "FS" : "");
100096
100097 mutex_unlock(&swapon_mutex);
100098- atomic_inc(&proc_poll_event);
100099+ atomic_inc_unchecked(&proc_poll_event);
100100 wake_up_interruptible(&proc_poll_wait);
100101
100102 if (S_ISREG(inode->i_mode))
100103diff --git a/mm/util.c b/mm/util.c
100104index 093c973..b70a268 100644
100105--- a/mm/util.c
100106+++ b/mm/util.c
100107@@ -202,6 +202,12 @@ done:
100108 void arch_pick_mmap_layout(struct mm_struct *mm)
100109 {
100110 mm->mmap_base = TASK_UNMAPPED_BASE;
100111+
100112+#ifdef CONFIG_PAX_RANDMMAP
100113+ if (mm->pax_flags & MF_PAX_RANDMMAP)
100114+ mm->mmap_base += mm->delta_mmap;
100115+#endif
100116+
100117 mm->get_unmapped_area = arch_get_unmapped_area;
100118 }
100119 #endif
100120@@ -378,6 +384,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
100121 if (!mm->arg_end)
100122 goto out_mm; /* Shh! No looking before we're done */
100123
100124+ if (gr_acl_handle_procpidmem(task))
100125+ goto out_mm;
100126+
100127 len = mm->arg_end - mm->arg_start;
100128
100129 if (len > buflen)
100130diff --git a/mm/vmalloc.c b/mm/vmalloc.c
100131index 2b0aa54..b451f74 100644
100132--- a/mm/vmalloc.c
100133+++ b/mm/vmalloc.c
100134@@ -40,6 +40,21 @@ struct vfree_deferred {
100135 };
100136 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
100137
100138+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100139+struct stack_deferred_llist {
100140+ struct llist_head list;
100141+ void *stack;
100142+ void *lowmem_stack;
100143+};
100144+
100145+struct stack_deferred {
100146+ struct stack_deferred_llist list;
100147+ struct work_struct wq;
100148+};
100149+
100150+static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
100151+#endif
100152+
100153 static void __vunmap(const void *, int);
100154
100155 static void free_work(struct work_struct *w)
100156@@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
100157 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
100158 struct llist_node *llnode = llist_del_all(&p->list);
100159 while (llnode) {
100160- void *p = llnode;
100161+ void *x = llnode;
100162 llnode = llist_next(llnode);
100163- __vunmap(p, 1);
100164+ __vunmap(x, 1);
100165 }
100166 }
100167
100168+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100169+static void unmap_work(struct work_struct *w)
100170+{
100171+ struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
100172+ struct llist_node *llnode = llist_del_all(&p->list.list);
100173+ while (llnode) {
100174+ struct stack_deferred_llist *x =
100175+ llist_entry((struct llist_head *)llnode,
100176+ struct stack_deferred_llist, list);
100177+ void *stack = ACCESS_ONCE(x->stack);
100178+ void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
100179+ llnode = llist_next(llnode);
100180+ __vunmap(stack, 0);
100181+ free_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
100182+ }
100183+}
100184+#endif
100185+
100186 /*** Page table manipulation functions ***/
100187
100188 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100189@@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
100190
100191 pte = pte_offset_kernel(pmd, addr);
100192 do {
100193- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100194- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100195+
100196+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100197+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
100198+ BUG_ON(!pte_exec(*pte));
100199+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
100200+ continue;
100201+ }
100202+#endif
100203+
100204+ {
100205+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
100206+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
100207+ }
100208 } while (pte++, addr += PAGE_SIZE, addr != end);
100209 }
100210
100211@@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
100212 pte = pte_alloc_kernel(pmd, addr);
100213 if (!pte)
100214 return -ENOMEM;
100215+
100216+ pax_open_kernel();
100217 do {
100218 struct page *page = pages[*nr];
100219
100220- if (WARN_ON(!pte_none(*pte)))
100221+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100222+ if (pgprot_val(prot) & _PAGE_NX)
100223+#endif
100224+
100225+ if (!pte_none(*pte)) {
100226+ pax_close_kernel();
100227+ WARN_ON(1);
100228 return -EBUSY;
100229- if (WARN_ON(!page))
100230+ }
100231+ if (!page) {
100232+ pax_close_kernel();
100233+ WARN_ON(1);
100234 return -ENOMEM;
100235+ }
100236 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
100237 (*nr)++;
100238 } while (pte++, addr += PAGE_SIZE, addr != end);
100239+ pax_close_kernel();
100240 return 0;
100241 }
100242
100243@@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
100244 pmd_t *pmd;
100245 unsigned long next;
100246
100247- pmd = pmd_alloc(&init_mm, pud, addr);
100248+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
100249 if (!pmd)
100250 return -ENOMEM;
100251 do {
100252@@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
100253 pud_t *pud;
100254 unsigned long next;
100255
100256- pud = pud_alloc(&init_mm, pgd, addr);
100257+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
100258 if (!pud)
100259 return -ENOMEM;
100260 do {
100261@@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
100262 if (addr >= MODULES_VADDR && addr < MODULES_END)
100263 return 1;
100264 #endif
100265+
100266+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
100267+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
100268+ return 1;
100269+#endif
100270+
100271 return is_vmalloc_addr(x);
100272 }
100273
100274@@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
100275
100276 if (!pgd_none(*pgd)) {
100277 pud_t *pud = pud_offset(pgd, addr);
100278+#ifdef CONFIG_X86
100279+ if (!pud_large(*pud))
100280+#endif
100281 if (!pud_none(*pud)) {
100282 pmd_t *pmd = pmd_offset(pud, addr);
100283+#ifdef CONFIG_X86
100284+ if (!pmd_large(*pmd))
100285+#endif
100286 if (!pmd_none(*pmd)) {
100287 pte_t *ptep, pte;
100288
100289@@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
100290 for_each_possible_cpu(i) {
100291 struct vmap_block_queue *vbq;
100292 struct vfree_deferred *p;
100293+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100294+ struct stack_deferred *p2;
100295+#endif
100296
100297 vbq = &per_cpu(vmap_block_queue, i);
100298 spin_lock_init(&vbq->lock);
100299 INIT_LIST_HEAD(&vbq->free);
100300+
100301 p = &per_cpu(vfree_deferred, i);
100302 init_llist_head(&p->list);
100303 INIT_WORK(&p->wq, free_work);
100304+
100305+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100306+ p2 = &per_cpu(stack_deferred, i);
100307+ init_llist_head(&p2->list.list);
100308+ INIT_WORK(&p2->wq, unmap_work);
100309+#endif
100310 }
100311
100312 /* Import existing vmlist entries. */
100313@@ -1314,6 +1393,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
100314 struct vm_struct *area;
100315
100316 BUG_ON(in_interrupt());
100317+
100318+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100319+ if (flags & VM_KERNEXEC) {
100320+ if (start != VMALLOC_START || end != VMALLOC_END)
100321+ return NULL;
100322+ start = (unsigned long)MODULES_EXEC_VADDR;
100323+ end = (unsigned long)MODULES_EXEC_END;
100324+ }
100325+#endif
100326+
100327 if (flags & VM_IOREMAP)
100328 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
100329
100330@@ -1519,6 +1608,23 @@ void vunmap(const void *addr)
100331 }
100332 EXPORT_SYMBOL(vunmap);
100333
100334+#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
100335+void unmap_process_stacks(struct task_struct *task)
100336+{
100337+ if (unlikely(in_interrupt())) {
100338+ struct stack_deferred *p = &__get_cpu_var(stack_deferred);
100339+ struct stack_deferred_llist *list = task->stack;
100340+ list->stack = task->stack;
100341+ list->lowmem_stack = task->lowmem_stack;
100342+ if (llist_add((struct llist_node *)&list->list, &p->list.list))
100343+ schedule_work(&p->wq);
100344+ } else {
100345+ __vunmap(task->stack, 0);
100346+ free_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
100347+ }
100348+}
100349+#endif
100350+
100351 /**
100352 * vmap - map an array of pages into virtually contiguous space
100353 * @pages: array of page pointers
100354@@ -1539,6 +1645,11 @@ void *vmap(struct page **pages, unsigned int count,
100355 if (count > totalram_pages)
100356 return NULL;
100357
100358+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100359+ if (!(pgprot_val(prot) & _PAGE_NX))
100360+ flags |= VM_KERNEXEC;
100361+#endif
100362+
100363 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
100364 __builtin_return_address(0));
100365 if (!area)
100366@@ -1641,6 +1752,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
100367 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
100368 goto fail;
100369
100370+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
100371+ if (!(pgprot_val(prot) & _PAGE_NX))
100372+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
100373+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
100374+ else
100375+#endif
100376+
100377 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
100378 start, end, node, gfp_mask, caller);
100379 if (!area)
100380@@ -1817,10 +1935,9 @@ EXPORT_SYMBOL(vzalloc_node);
100381 * For tight control over page level allocator and protection flags
100382 * use __vmalloc() instead.
100383 */
100384-
100385 void *vmalloc_exec(unsigned long size)
100386 {
100387- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
100388+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
100389 NUMA_NO_NODE, __builtin_return_address(0));
100390 }
100391
100392@@ -2127,6 +2244,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
100393 {
100394 struct vm_struct *area;
100395
100396+ BUG_ON(vma->vm_mirror);
100397+
100398 size = PAGE_ALIGN(size);
100399
100400 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
100401@@ -2609,7 +2728,11 @@ static int s_show(struct seq_file *m, void *p)
100402 v->addr, v->addr + v->size, v->size);
100403
100404 if (v->caller)
100405+#ifdef CONFIG_GRKERNSEC_HIDESYM
100406+ seq_printf(m, " %pK", v->caller);
100407+#else
100408 seq_printf(m, " %pS", v->caller);
100409+#endif
100410
100411 if (v->nr_pages)
100412 seq_printf(m, " pages=%d", v->nr_pages);
100413diff --git a/mm/vmstat.c b/mm/vmstat.c
100414index e9ab104..de275bd 100644
100415--- a/mm/vmstat.c
100416+++ b/mm/vmstat.c
100417@@ -20,6 +20,7 @@
100418 #include <linux/writeback.h>
100419 #include <linux/compaction.h>
100420 #include <linux/mm_inline.h>
100421+#include <linux/grsecurity.h>
100422
100423 #include "internal.h"
100424
100425@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
100426 *
100427 * vm_stat contains the global counters
100428 */
100429-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100430+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
100431 EXPORT_SYMBOL(vm_stat);
100432
100433 #ifdef CONFIG_SMP
100434@@ -425,7 +426,7 @@ static inline void fold_diff(int *diff)
100435
100436 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100437 if (diff[i])
100438- atomic_long_add(diff[i], &vm_stat[i]);
100439+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
100440 }
100441
100442 /*
100443@@ -457,7 +458,7 @@ static void refresh_cpu_vm_stats(void)
100444 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
100445 if (v) {
100446
100447- atomic_long_add(v, &zone->vm_stat[i]);
100448+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100449 global_diff[i] += v;
100450 #ifdef CONFIG_NUMA
100451 /* 3 seconds idle till flush */
100452@@ -519,7 +520,7 @@ void cpu_vm_stats_fold(int cpu)
100453
100454 v = p->vm_stat_diff[i];
100455 p->vm_stat_diff[i] = 0;
100456- atomic_long_add(v, &zone->vm_stat[i]);
100457+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100458 global_diff[i] += v;
100459 }
100460 }
100461@@ -539,8 +540,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
100462 if (pset->vm_stat_diff[i]) {
100463 int v = pset->vm_stat_diff[i];
100464 pset->vm_stat_diff[i] = 0;
100465- atomic_long_add(v, &zone->vm_stat[i]);
100466- atomic_long_add(v, &vm_stat[i]);
100467+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
100468+ atomic_long_add_unchecked(v, &vm_stat[i]);
100469 }
100470 }
100471 #endif
100472@@ -1163,10 +1164,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
100473 stat_items_size += sizeof(struct vm_event_state);
100474 #endif
100475
100476- v = kmalloc(stat_items_size, GFP_KERNEL);
100477+ v = kzalloc(stat_items_size, GFP_KERNEL);
100478 m->private = v;
100479 if (!v)
100480 return ERR_PTR(-ENOMEM);
100481+
100482+#ifdef CONFIG_GRKERNSEC_PROC_ADD
100483+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
100484+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
100485+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
100486+ && !in_group_p(grsec_proc_gid)
100487+#endif
100488+ )
100489+ return (unsigned long *)m->private + *pos;
100490+#endif
100491+#endif
100492+
100493 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
100494 v[i] = global_page_state(i);
100495 v += NR_VM_ZONE_STAT_ITEMS;
100496@@ -1315,10 +1328,16 @@ static int __init setup_vmstat(void)
100497 cpu_notifier_register_done();
100498 #endif
100499 #ifdef CONFIG_PROC_FS
100500- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
100501- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
100502- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100503- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
100504+ {
100505+ mode_t gr_mode = S_IRUGO;
100506+#ifdef CONFIG_GRKERNSEC_PROC_ADD
100507+ gr_mode = S_IRUSR;
100508+#endif
100509+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
100510+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
100511+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
100512+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
100513+ }
100514 #endif
100515 return 0;
100516 }
100517diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
100518index 64c6bed..b79a5de 100644
100519--- a/net/8021q/vlan.c
100520+++ b/net/8021q/vlan.c
100521@@ -481,7 +481,7 @@ out:
100522 return NOTIFY_DONE;
100523 }
100524
100525-static struct notifier_block vlan_notifier_block __read_mostly = {
100526+static struct notifier_block vlan_notifier_block = {
100527 .notifier_call = vlan_device_event,
100528 };
100529
100530@@ -556,8 +556,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
100531 err = -EPERM;
100532 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
100533 break;
100534- if ((args.u.name_type >= 0) &&
100535- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
100536+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
100537 struct vlan_net *vn;
100538
100539 vn = net_generic(net, vlan_net_id);
100540diff --git a/net/9p/client.c b/net/9p/client.c
100541index e86a9bea..e91f70e 100644
100542--- a/net/9p/client.c
100543+++ b/net/9p/client.c
100544@@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
100545 len - inline_len);
100546 } else {
100547 err = copy_from_user(ename + inline_len,
100548- uidata, len - inline_len);
100549+ (char __force_user *)uidata, len - inline_len);
100550 if (err) {
100551 err = -EFAULT;
100552 goto out_err;
100553@@ -1570,7 +1570,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
100554 kernel_buf = 1;
100555 indata = data;
100556 } else
100557- indata = (__force char *)udata;
100558+ indata = (__force_kernel char *)udata;
100559 /*
100560 * response header len is 11
100561 * PDU Header(7) + IO Size (4)
100562@@ -1645,7 +1645,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
100563 kernel_buf = 1;
100564 odata = data;
100565 } else
100566- odata = (char *)udata;
100567+ odata = (char __force_kernel *)udata;
100568 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
100569 P9_ZC_HDR_SZ, kernel_buf, "dqd",
100570 fid->fid, offset, rsize);
100571diff --git a/net/9p/mod.c b/net/9p/mod.c
100572index 6ab36ae..6f1841b 100644
100573--- a/net/9p/mod.c
100574+++ b/net/9p/mod.c
100575@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
100576 void v9fs_register_trans(struct p9_trans_module *m)
100577 {
100578 spin_lock(&v9fs_trans_lock);
100579- list_add_tail(&m->list, &v9fs_trans_list);
100580+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
100581 spin_unlock(&v9fs_trans_lock);
100582 }
100583 EXPORT_SYMBOL(v9fs_register_trans);
100584@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
100585 void v9fs_unregister_trans(struct p9_trans_module *m)
100586 {
100587 spin_lock(&v9fs_trans_lock);
100588- list_del_init(&m->list);
100589+ pax_list_del_init((struct list_head *)&m->list);
100590 spin_unlock(&v9fs_trans_lock);
100591 }
100592 EXPORT_SYMBOL(v9fs_unregister_trans);
100593diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
100594index 80d08f6..de63fd1 100644
100595--- a/net/9p/trans_fd.c
100596+++ b/net/9p/trans_fd.c
100597@@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
100598 oldfs = get_fs();
100599 set_fs(get_ds());
100600 /* The cast to a user pointer is valid due to the set_fs() */
100601- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
100602+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
100603 set_fs(oldfs);
100604
100605 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
100606diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
100607index af46bc4..f9adfcd 100644
100608--- a/net/appletalk/atalk_proc.c
100609+++ b/net/appletalk/atalk_proc.c
100610@@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
100611 struct proc_dir_entry *p;
100612 int rc = -ENOMEM;
100613
100614- atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
100615+ atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
100616 if (!atalk_proc_dir)
100617 goto out;
100618
100619diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
100620index 876fbe8..8bbea9f 100644
100621--- a/net/atm/atm_misc.c
100622+++ b/net/atm/atm_misc.c
100623@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
100624 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
100625 return 1;
100626 atm_return(vcc, truesize);
100627- atomic_inc(&vcc->stats->rx_drop);
100628+ atomic_inc_unchecked(&vcc->stats->rx_drop);
100629 return 0;
100630 }
100631 EXPORT_SYMBOL(atm_charge);
100632@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
100633 }
100634 }
100635 atm_return(vcc, guess);
100636- atomic_inc(&vcc->stats->rx_drop);
100637+ atomic_inc_unchecked(&vcc->stats->rx_drop);
100638 return NULL;
100639 }
100640 EXPORT_SYMBOL(atm_alloc_charge);
100641@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
100642
100643 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100644 {
100645-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100646+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100647 __SONET_ITEMS
100648 #undef __HANDLE_ITEM
100649 }
100650@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
100651
100652 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
100653 {
100654-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100655+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
100656 __SONET_ITEMS
100657 #undef __HANDLE_ITEM
100658 }
100659diff --git a/net/atm/lec.c b/net/atm/lec.c
100660index 4b98f89..5a2f6cb 100644
100661--- a/net/atm/lec.c
100662+++ b/net/atm/lec.c
100663@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
100664 }
100665
100666 static struct lane2_ops lane2_ops = {
100667- lane2_resolve, /* resolve, spec 3.1.3 */
100668- lane2_associate_req, /* associate_req, spec 3.1.4 */
100669- NULL /* associate indicator, spec 3.1.5 */
100670+ .resolve = lane2_resolve,
100671+ .associate_req = lane2_associate_req,
100672+ .associate_indicator = NULL
100673 };
100674
100675 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
100676diff --git a/net/atm/lec.h b/net/atm/lec.h
100677index 4149db1..f2ab682 100644
100678--- a/net/atm/lec.h
100679+++ b/net/atm/lec.h
100680@@ -48,7 +48,7 @@ struct lane2_ops {
100681 const u8 *tlvs, u32 sizeoftlvs);
100682 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
100683 const u8 *tlvs, u32 sizeoftlvs);
100684-};
100685+} __no_const;
100686
100687 /*
100688 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
100689diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
100690index d1b2d9a..d549f7f 100644
100691--- a/net/atm/mpoa_caches.c
100692+++ b/net/atm/mpoa_caches.c
100693@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
100694
100695
100696 static struct in_cache_ops ingress_ops = {
100697- in_cache_add_entry, /* add_entry */
100698- in_cache_get, /* get */
100699- in_cache_get_with_mask, /* get_with_mask */
100700- in_cache_get_by_vcc, /* get_by_vcc */
100701- in_cache_put, /* put */
100702- in_cache_remove_entry, /* remove_entry */
100703- cache_hit, /* cache_hit */
100704- clear_count_and_expired, /* clear_count */
100705- check_resolving_entries, /* check_resolving */
100706- refresh_entries, /* refresh */
100707- in_destroy_cache /* destroy_cache */
100708+ .add_entry = in_cache_add_entry,
100709+ .get = in_cache_get,
100710+ .get_with_mask = in_cache_get_with_mask,
100711+ .get_by_vcc = in_cache_get_by_vcc,
100712+ .put = in_cache_put,
100713+ .remove_entry = in_cache_remove_entry,
100714+ .cache_hit = cache_hit,
100715+ .clear_count = clear_count_and_expired,
100716+ .check_resolving = check_resolving_entries,
100717+ .refresh = refresh_entries,
100718+ .destroy_cache = in_destroy_cache
100719 };
100720
100721 static struct eg_cache_ops egress_ops = {
100722- eg_cache_add_entry, /* add_entry */
100723- eg_cache_get_by_cache_id, /* get_by_cache_id */
100724- eg_cache_get_by_tag, /* get_by_tag */
100725- eg_cache_get_by_vcc, /* get_by_vcc */
100726- eg_cache_get_by_src_ip, /* get_by_src_ip */
100727- eg_cache_put, /* put */
100728- eg_cache_remove_entry, /* remove_entry */
100729- update_eg_cache_entry, /* update */
100730- clear_expired, /* clear_expired */
100731- eg_destroy_cache /* destroy_cache */
100732+ .add_entry = eg_cache_add_entry,
100733+ .get_by_cache_id = eg_cache_get_by_cache_id,
100734+ .get_by_tag = eg_cache_get_by_tag,
100735+ .get_by_vcc = eg_cache_get_by_vcc,
100736+ .get_by_src_ip = eg_cache_get_by_src_ip,
100737+ .put = eg_cache_put,
100738+ .remove_entry = eg_cache_remove_entry,
100739+ .update = update_eg_cache_entry,
100740+ .clear_expired = clear_expired,
100741+ .destroy_cache = eg_destroy_cache
100742 };
100743
100744
100745diff --git a/net/atm/proc.c b/net/atm/proc.c
100746index bbb6461..cf04016 100644
100747--- a/net/atm/proc.c
100748+++ b/net/atm/proc.c
100749@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
100750 const struct k_atm_aal_stats *stats)
100751 {
100752 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
100753- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
100754- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
100755- atomic_read(&stats->rx_drop));
100756+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
100757+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
100758+ atomic_read_unchecked(&stats->rx_drop));
100759 }
100760
100761 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
100762diff --git a/net/atm/resources.c b/net/atm/resources.c
100763index 0447d5d..3cf4728 100644
100764--- a/net/atm/resources.c
100765+++ b/net/atm/resources.c
100766@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
100767 static void copy_aal_stats(struct k_atm_aal_stats *from,
100768 struct atm_aal_stats *to)
100769 {
100770-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
100771+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
100772 __AAL_STAT_ITEMS
100773 #undef __HANDLE_ITEM
100774 }
100775@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
100776 static void subtract_aal_stats(struct k_atm_aal_stats *from,
100777 struct atm_aal_stats *to)
100778 {
100779-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
100780+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
100781 __AAL_STAT_ITEMS
100782 #undef __HANDLE_ITEM
100783 }
100784diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
100785index 919a5ce..cc6b444 100644
100786--- a/net/ax25/sysctl_net_ax25.c
100787+++ b/net/ax25/sysctl_net_ax25.c
100788@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
100789 {
100790 char path[sizeof("net/ax25/") + IFNAMSIZ];
100791 int k;
100792- struct ctl_table *table;
100793+ ctl_table_no_const *table;
100794
100795 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
100796 if (!table)
100797diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
100798index 1e80539..676c37a 100644
100799--- a/net/batman-adv/bat_iv_ogm.c
100800+++ b/net/batman-adv/bat_iv_ogm.c
100801@@ -313,7 +313,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
100802
100803 /* randomize initial seqno to avoid collision */
100804 get_random_bytes(&random_seqno, sizeof(random_seqno));
100805- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100806+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
100807
100808 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
100809 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
100810@@ -918,9 +918,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
100811 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
100812
100813 /* change sequence number to network order */
100814- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
100815+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
100816 batadv_ogm_packet->seqno = htonl(seqno);
100817- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
100818+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
100819
100820 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
100821
100822@@ -1597,7 +1597,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
100823 return;
100824
100825 /* could be changed by schedule_own_packet() */
100826- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
100827+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
100828
100829 if (ogm_packet->flags & BATADV_DIRECTLINK)
100830 has_directlink_flag = true;
100831diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
100832index fc1835c..eead856 100644
100833--- a/net/batman-adv/fragmentation.c
100834+++ b/net/batman-adv/fragmentation.c
100835@@ -450,7 +450,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
100836 frag_header.packet_type = BATADV_UNICAST_FRAG;
100837 frag_header.version = BATADV_COMPAT_VERSION;
100838 frag_header.ttl = BATADV_TTL;
100839- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
100840+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
100841 frag_header.reserved = 0;
100842 frag_header.no = 0;
100843 frag_header.total_size = htons(skb->len);
100844diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
100845index 5467955..30cc771 100644
100846--- a/net/batman-adv/soft-interface.c
100847+++ b/net/batman-adv/soft-interface.c
100848@@ -296,7 +296,7 @@ send:
100849 primary_if->net_dev->dev_addr);
100850
100851 /* set broadcast sequence number */
100852- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
100853+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
100854 bcast_packet->seqno = htonl(seqno);
100855
100856 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
100857@@ -761,7 +761,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100858 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
100859
100860 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
100861- atomic_set(&bat_priv->bcast_seqno, 1);
100862+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
100863 atomic_set(&bat_priv->tt.vn, 0);
100864 atomic_set(&bat_priv->tt.local_changes, 0);
100865 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
100866@@ -775,7 +775,7 @@ static int batadv_softif_init_late(struct net_device *dev)
100867
100868 /* randomize initial seqno to avoid collision */
100869 get_random_bytes(&random_seqno, sizeof(random_seqno));
100870- atomic_set(&bat_priv->frag_seqno, random_seqno);
100871+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
100872
100873 bat_priv->primary_if = NULL;
100874 bat_priv->num_ifaces = 0;
100875diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
100876index 8854c05..ee5d5497 100644
100877--- a/net/batman-adv/types.h
100878+++ b/net/batman-adv/types.h
100879@@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
100880 struct batadv_hard_iface_bat_iv {
100881 unsigned char *ogm_buff;
100882 int ogm_buff_len;
100883- atomic_t ogm_seqno;
100884+ atomic_unchecked_t ogm_seqno;
100885 };
100886
100887 /**
100888@@ -768,7 +768,7 @@ struct batadv_priv {
100889 atomic_t bonding;
100890 atomic_t fragmentation;
100891 atomic_t packet_size_max;
100892- atomic_t frag_seqno;
100893+ atomic_unchecked_t frag_seqno;
100894 #ifdef CONFIG_BATMAN_ADV_BLA
100895 atomic_t bridge_loop_avoidance;
100896 #endif
100897@@ -787,7 +787,7 @@ struct batadv_priv {
100898 #endif
100899 uint32_t isolation_mark;
100900 uint32_t isolation_mark_mask;
100901- atomic_t bcast_seqno;
100902+ atomic_unchecked_t bcast_seqno;
100903 atomic_t bcast_queue_left;
100904 atomic_t batman_queue_left;
100905 char num_ifaces;
100906diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
100907index 115f149..f0ba286 100644
100908--- a/net/bluetooth/hci_sock.c
100909+++ b/net/bluetooth/hci_sock.c
100910@@ -1067,7 +1067,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
100911 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
100912 }
100913
100914- len = min_t(unsigned int, len, sizeof(uf));
100915+ len = min((size_t)len, sizeof(uf));
100916 if (copy_from_user(&uf, optval, len)) {
100917 err = -EFAULT;
100918 break;
100919diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
100920index 14ca8ae..262d49a 100644
100921--- a/net/bluetooth/l2cap_core.c
100922+++ b/net/bluetooth/l2cap_core.c
100923@@ -3565,8 +3565,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
100924 break;
100925
100926 case L2CAP_CONF_RFC:
100927- if (olen == sizeof(rfc))
100928- memcpy(&rfc, (void *)val, olen);
100929+ if (olen != sizeof(rfc))
100930+ break;
100931+
100932+ memcpy(&rfc, (void *)val, olen);
100933
100934 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
100935 rfc.mode != chan->mode)
100936diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
100937index 1884f72..b3b71f9 100644
100938--- a/net/bluetooth/l2cap_sock.c
100939+++ b/net/bluetooth/l2cap_sock.c
100940@@ -629,7 +629,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
100941 struct sock *sk = sock->sk;
100942 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
100943 struct l2cap_options opts;
100944- int len, err = 0;
100945+ int err = 0;
100946+ size_t len = optlen;
100947 u32 opt;
100948
100949 BT_DBG("sk %p", sk);
100950@@ -656,7 +657,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
100951 opts.max_tx = chan->max_tx;
100952 opts.txwin_size = chan->tx_win;
100953
100954- len = min_t(unsigned int, sizeof(opts), optlen);
100955+ len = min(sizeof(opts), len);
100956 if (copy_from_user((char *) &opts, optval, len)) {
100957 err = -EFAULT;
100958 break;
100959@@ -743,7 +744,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100960 struct bt_security sec;
100961 struct bt_power pwr;
100962 struct l2cap_conn *conn;
100963- int len, err = 0;
100964+ int err = 0;
100965+ size_t len = optlen;
100966 u32 opt;
100967
100968 BT_DBG("sk %p", sk);
100969@@ -767,7 +769,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100970
100971 sec.level = BT_SECURITY_LOW;
100972
100973- len = min_t(unsigned int, sizeof(sec), optlen);
100974+ len = min(sizeof(sec), len);
100975 if (copy_from_user((char *) &sec, optval, len)) {
100976 err = -EFAULT;
100977 break;
100978@@ -862,7 +864,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
100979
100980 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
100981
100982- len = min_t(unsigned int, sizeof(pwr), optlen);
100983+ len = min(sizeof(pwr), len);
100984 if (copy_from_user((char *) &pwr, optval, len)) {
100985 err = -EFAULT;
100986 break;
100987diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
100988index 8bbbb5e..6fc0950 100644
100989--- a/net/bluetooth/rfcomm/sock.c
100990+++ b/net/bluetooth/rfcomm/sock.c
100991@@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
100992 struct sock *sk = sock->sk;
100993 struct bt_security sec;
100994 int err = 0;
100995- size_t len;
100996+ size_t len = optlen;
100997 u32 opt;
100998
100999 BT_DBG("sk %p", sk);
101000@@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
101001
101002 sec.level = BT_SECURITY_LOW;
101003
101004- len = min_t(unsigned int, sizeof(sec), optlen);
101005+ len = min(sizeof(sec), len);
101006 if (copy_from_user((char *) &sec, optval, len)) {
101007 err = -EFAULT;
101008 break;
101009diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
101010index 8e385a0..a5bdd8e 100644
101011--- a/net/bluetooth/rfcomm/tty.c
101012+++ b/net/bluetooth/rfcomm/tty.c
101013@@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
101014 BT_DBG("tty %p id %d", tty, tty->index);
101015
101016 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
101017- dev->channel, dev->port.count);
101018+ dev->channel, atomic_read(&dev->port.count));
101019
101020 err = tty_port_open(&dev->port, tty, filp);
101021 if (err)
101022@@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
101023 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
101024
101025 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
101026- dev->port.count);
101027+ atomic_read(&dev->port.count));
101028
101029 tty_port_close(&dev->port, tty, filp);
101030 }
101031diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
101032index 6d69631..b8fdc85 100644
101033--- a/net/bridge/netfilter/ebtables.c
101034+++ b/net/bridge/netfilter/ebtables.c
101035@@ -1518,7 +1518,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
101036 tmp.valid_hooks = t->table->valid_hooks;
101037 }
101038 mutex_unlock(&ebt_mutex);
101039- if (copy_to_user(user, &tmp, *len) != 0) {
101040+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101041 BUGPRINT("c2u Didn't work\n");
101042 ret = -EFAULT;
101043 break;
101044@@ -2324,7 +2324,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101045 goto out;
101046 tmp.valid_hooks = t->valid_hooks;
101047
101048- if (copy_to_user(user, &tmp, *len) != 0) {
101049+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101050 ret = -EFAULT;
101051 break;
101052 }
101053@@ -2335,7 +2335,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
101054 tmp.entries_size = t->table->entries_size;
101055 tmp.valid_hooks = t->table->valid_hooks;
101056
101057- if (copy_to_user(user, &tmp, *len) != 0) {
101058+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
101059 ret = -EFAULT;
101060 break;
101061 }
101062diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
101063index f5afda1..dcf770a 100644
101064--- a/net/caif/cfctrl.c
101065+++ b/net/caif/cfctrl.c
101066@@ -10,6 +10,7 @@
101067 #include <linux/spinlock.h>
101068 #include <linux/slab.h>
101069 #include <linux/pkt_sched.h>
101070+#include <linux/sched.h>
101071 #include <net/caif/caif_layer.h>
101072 #include <net/caif/cfpkt.h>
101073 #include <net/caif/cfctrl.h>
101074@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
101075 memset(&dev_info, 0, sizeof(dev_info));
101076 dev_info.id = 0xff;
101077 cfsrvl_init(&this->serv, 0, &dev_info, false);
101078- atomic_set(&this->req_seq_no, 1);
101079- atomic_set(&this->rsp_seq_no, 1);
101080+ atomic_set_unchecked(&this->req_seq_no, 1);
101081+ atomic_set_unchecked(&this->rsp_seq_no, 1);
101082 this->serv.layer.receive = cfctrl_recv;
101083 sprintf(this->serv.layer.name, "ctrl");
101084 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
101085@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
101086 struct cfctrl_request_info *req)
101087 {
101088 spin_lock_bh(&ctrl->info_list_lock);
101089- atomic_inc(&ctrl->req_seq_no);
101090- req->sequence_no = atomic_read(&ctrl->req_seq_no);
101091+ atomic_inc_unchecked(&ctrl->req_seq_no);
101092+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
101093 list_add_tail(&req->list, &ctrl->list);
101094 spin_unlock_bh(&ctrl->info_list_lock);
101095 }
101096@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
101097 if (p != first)
101098 pr_warn("Requests are not received in order\n");
101099
101100- atomic_set(&ctrl->rsp_seq_no,
101101+ atomic_set_unchecked(&ctrl->rsp_seq_no,
101102 p->sequence_no);
101103 list_del(&p->list);
101104 goto out;
101105diff --git a/net/can/af_can.c b/net/can/af_can.c
101106index ce82337..5d17b4d 100644
101107--- a/net/can/af_can.c
101108+++ b/net/can/af_can.c
101109@@ -884,7 +884,7 @@ static const struct net_proto_family can_family_ops = {
101110 };
101111
101112 /* notifier block for netdevice event */
101113-static struct notifier_block can_netdev_notifier __read_mostly = {
101114+static struct notifier_block can_netdev_notifier = {
101115 .notifier_call = can_notifier,
101116 };
101117
101118diff --git a/net/can/bcm.c b/net/can/bcm.c
101119index dcb75c0..24b1b43 100644
101120--- a/net/can/bcm.c
101121+++ b/net/can/bcm.c
101122@@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
101123 }
101124
101125 /* create /proc/net/can-bcm directory */
101126- proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
101127+ proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
101128 return 0;
101129 }
101130
101131diff --git a/net/can/gw.c b/net/can/gw.c
101132index 050a211..bb9fe33 100644
101133--- a/net/can/gw.c
101134+++ b/net/can/gw.c
101135@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
101136 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
101137
101138 static HLIST_HEAD(cgw_list);
101139-static struct notifier_block notifier;
101140
101141 static struct kmem_cache *cgw_cache __read_mostly;
101142
101143@@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
101144 return err;
101145 }
101146
101147+static struct notifier_block notifier = {
101148+ .notifier_call = cgw_notifier
101149+};
101150+
101151 static __init int cgw_module_init(void)
101152 {
101153 /* sanitize given module parameter */
101154@@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
101155 return -ENOMEM;
101156
101157 /* set notifier */
101158- notifier.notifier_call = cgw_notifier;
101159 register_netdevice_notifier(&notifier);
101160
101161 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
101162diff --git a/net/can/proc.c b/net/can/proc.c
101163index 1a19b98..df2b4ec 100644
101164--- a/net/can/proc.c
101165+++ b/net/can/proc.c
101166@@ -514,7 +514,7 @@ static void can_remove_proc_readentry(const char *name)
101167 void can_init_proc(void)
101168 {
101169 /* create /proc/net/can directory */
101170- can_dir = proc_mkdir("can", init_net.proc_net);
101171+ can_dir = proc_mkdir_restrict("can", init_net.proc_net);
101172
101173 if (!can_dir) {
101174 printk(KERN_INFO "can: failed to create /proc/net/can . "
101175diff --git a/net/ceph/crypto.c b/net/ceph/crypto.c
101176index ffeba8f..c0d666a 100644
101177--- a/net/ceph/crypto.c
101178+++ b/net/ceph/crypto.c
101179@@ -90,11 +90,82 @@ static struct crypto_blkcipher *ceph_crypto_alloc_cipher(void)
101180
101181 static const u8 *aes_iv = (u8 *)CEPH_AES_IV;
101182
101183+/*
101184+ * Should be used for buffers allocated with ceph_kvmalloc().
101185+ * Currently these are encrypt out-buffer (ceph_buffer) and decrypt
101186+ * in-buffer (msg front).
101187+ *
101188+ * Dispose of @sgt with teardown_sgtable().
101189+ *
101190+ * @prealloc_sg is to avoid memory allocation inside sg_alloc_table()
101191+ * in cases where a single sg is sufficient. No attempt to reduce the
101192+ * number of sgs by squeezing physically contiguous pages together is
101193+ * made though, for simplicity.
101194+ */
101195+static int setup_sgtable(struct sg_table *sgt, struct scatterlist *prealloc_sg,
101196+ const void *buf, unsigned int buf_len)
101197+{
101198+ struct scatterlist *sg;
101199+ const bool is_vmalloc = is_vmalloc_addr(buf);
101200+ unsigned int off = offset_in_page(buf);
101201+ unsigned int chunk_cnt = 1;
101202+ unsigned int chunk_len = PAGE_ALIGN(off + buf_len);
101203+ int i;
101204+ int ret;
101205+
101206+ if (buf_len == 0) {
101207+ memset(sgt, 0, sizeof(*sgt));
101208+ return -EINVAL;
101209+ }
101210+
101211+ if (is_vmalloc) {
101212+ chunk_cnt = chunk_len >> PAGE_SHIFT;
101213+ chunk_len = PAGE_SIZE;
101214+ }
101215+
101216+ if (chunk_cnt > 1) {
101217+ ret = sg_alloc_table(sgt, chunk_cnt, GFP_NOFS);
101218+ if (ret)
101219+ return ret;
101220+ } else {
101221+ WARN_ON(chunk_cnt != 1);
101222+ sg_init_table(prealloc_sg, 1);
101223+ sgt->sgl = prealloc_sg;
101224+ sgt->nents = sgt->orig_nents = 1;
101225+ }
101226+
101227+ for_each_sg(sgt->sgl, sg, sgt->orig_nents, i) {
101228+ struct page *page;
101229+ unsigned int len = min(chunk_len - off, buf_len);
101230+
101231+ if (is_vmalloc)
101232+ page = vmalloc_to_page(buf);
101233+ else
101234+ page = virt_to_page(buf);
101235+
101236+ sg_set_page(sg, page, len, off);
101237+
101238+ off = 0;
101239+ buf += len;
101240+ buf_len -= len;
101241+ }
101242+ WARN_ON(buf_len != 0);
101243+
101244+ return 0;
101245+}
101246+
101247+static void teardown_sgtable(struct sg_table *sgt)
101248+{
101249+ if (sgt->orig_nents > 1)
101250+ sg_free_table(sgt);
101251+}
101252+
101253 static int ceph_aes_encrypt(const void *key, int key_len,
101254 void *dst, size_t *dst_len,
101255 const void *src, size_t src_len)
101256 {
101257- struct scatterlist sg_in[2], sg_out[1];
101258+ struct scatterlist sg_in[2], prealloc_sg;
101259+ struct sg_table sg_out;
101260 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher();
101261 struct blkcipher_desc desc = { .tfm = tfm, .flags = 0 };
101262 int ret;
101263@@ -110,16 +181,18 @@ static int ceph_aes_encrypt(const void *key, int key_len,
101264
101265 *dst_len = src_len + zero_padding;
101266
101267- crypto_blkcipher_setkey((void *)tfm, key, key_len);
101268 sg_init_table(sg_in, 2);
101269 sg_set_buf(&sg_in[0], src, src_len);
101270 sg_set_buf(&sg_in[1], pad, zero_padding);
101271- sg_init_table(sg_out, 1);
101272- sg_set_buf(sg_out, dst, *dst_len);
101273+ ret = setup_sgtable(&sg_out, &prealloc_sg, dst, *dst_len);
101274+ if (ret)
101275+ goto out_tfm;
101276+
101277+ crypto_blkcipher_setkey((void *)tfm, key, key_len);
101278 iv = crypto_blkcipher_crt(tfm)->iv;
101279 ivsize = crypto_blkcipher_ivsize(tfm);
101280-
101281 memcpy(iv, aes_iv, ivsize);
101282+
101283 /*
101284 print_hex_dump(KERN_ERR, "enc key: ", DUMP_PREFIX_NONE, 16, 1,
101285 key, key_len, 1);
101286@@ -128,16 +201,22 @@ static int ceph_aes_encrypt(const void *key, int key_len,
101287 print_hex_dump(KERN_ERR, "enc pad: ", DUMP_PREFIX_NONE, 16, 1,
101288 pad, zero_padding, 1);
101289 */
101290- ret = crypto_blkcipher_encrypt(&desc, sg_out, sg_in,
101291+ ret = crypto_blkcipher_encrypt(&desc, sg_out.sgl, sg_in,
101292 src_len + zero_padding);
101293- crypto_free_blkcipher(tfm);
101294- if (ret < 0)
101295+ if (ret < 0) {
101296 pr_err("ceph_aes_crypt failed %d\n", ret);
101297+ goto out_sg;
101298+ }
101299 /*
101300 print_hex_dump(KERN_ERR, "enc out: ", DUMP_PREFIX_NONE, 16, 1,
101301 dst, *dst_len, 1);
101302 */
101303- return 0;
101304+
101305+out_sg:
101306+ teardown_sgtable(&sg_out);
101307+out_tfm:
101308+ crypto_free_blkcipher(tfm);
101309+ return ret;
101310 }
101311
101312 static int ceph_aes_encrypt2(const void *key, int key_len, void *dst,
101313@@ -145,7 +224,8 @@ static int ceph_aes_encrypt2(const void *key, int key_len, void *dst,
101314 const void *src1, size_t src1_len,
101315 const void *src2, size_t src2_len)
101316 {
101317- struct scatterlist sg_in[3], sg_out[1];
101318+ struct scatterlist sg_in[3], prealloc_sg;
101319+ struct sg_table sg_out;
101320 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher();
101321 struct blkcipher_desc desc = { .tfm = tfm, .flags = 0 };
101322 int ret;
101323@@ -161,17 +241,19 @@ static int ceph_aes_encrypt2(const void *key, int key_len, void *dst,
101324
101325 *dst_len = src1_len + src2_len + zero_padding;
101326
101327- crypto_blkcipher_setkey((void *)tfm, key, key_len);
101328 sg_init_table(sg_in, 3);
101329 sg_set_buf(&sg_in[0], src1, src1_len);
101330 sg_set_buf(&sg_in[1], src2, src2_len);
101331 sg_set_buf(&sg_in[2], pad, zero_padding);
101332- sg_init_table(sg_out, 1);
101333- sg_set_buf(sg_out, dst, *dst_len);
101334+ ret = setup_sgtable(&sg_out, &prealloc_sg, dst, *dst_len);
101335+ if (ret)
101336+ goto out_tfm;
101337+
101338+ crypto_blkcipher_setkey((void *)tfm, key, key_len);
101339 iv = crypto_blkcipher_crt(tfm)->iv;
101340 ivsize = crypto_blkcipher_ivsize(tfm);
101341-
101342 memcpy(iv, aes_iv, ivsize);
101343+
101344 /*
101345 print_hex_dump(KERN_ERR, "enc key: ", DUMP_PREFIX_NONE, 16, 1,
101346 key, key_len, 1);
101347@@ -182,23 +264,30 @@ static int ceph_aes_encrypt2(const void *key, int key_len, void *dst,
101348 print_hex_dump(KERN_ERR, "enc pad: ", DUMP_PREFIX_NONE, 16, 1,
101349 pad, zero_padding, 1);
101350 */
101351- ret = crypto_blkcipher_encrypt(&desc, sg_out, sg_in,
101352+ ret = crypto_blkcipher_encrypt(&desc, sg_out.sgl, sg_in,
101353 src1_len + src2_len + zero_padding);
101354- crypto_free_blkcipher(tfm);
101355- if (ret < 0)
101356+ if (ret < 0) {
101357 pr_err("ceph_aes_crypt2 failed %d\n", ret);
101358+ goto out_sg;
101359+ }
101360 /*
101361 print_hex_dump(KERN_ERR, "enc out: ", DUMP_PREFIX_NONE, 16, 1,
101362 dst, *dst_len, 1);
101363 */
101364- return 0;
101365+
101366+out_sg:
101367+ teardown_sgtable(&sg_out);
101368+out_tfm:
101369+ crypto_free_blkcipher(tfm);
101370+ return ret;
101371 }
101372
101373 static int ceph_aes_decrypt(const void *key, int key_len,
101374 void *dst, size_t *dst_len,
101375 const void *src, size_t src_len)
101376 {
101377- struct scatterlist sg_in[1], sg_out[2];
101378+ struct sg_table sg_in;
101379+ struct scatterlist sg_out[2], prealloc_sg;
101380 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher();
101381 struct blkcipher_desc desc = { .tfm = tfm };
101382 char pad[16];
101383@@ -210,16 +299,16 @@ static int ceph_aes_decrypt(const void *key, int key_len,
101384 if (IS_ERR(tfm))
101385 return PTR_ERR(tfm);
101386
101387- crypto_blkcipher_setkey((void *)tfm, key, key_len);
101388- sg_init_table(sg_in, 1);
101389 sg_init_table(sg_out, 2);
101390- sg_set_buf(sg_in, src, src_len);
101391 sg_set_buf(&sg_out[0], dst, *dst_len);
101392 sg_set_buf(&sg_out[1], pad, sizeof(pad));
101393+ ret = setup_sgtable(&sg_in, &prealloc_sg, src, src_len);
101394+ if (ret)
101395+ goto out_tfm;
101396
101397+ crypto_blkcipher_setkey((void *)tfm, key, key_len);
101398 iv = crypto_blkcipher_crt(tfm)->iv;
101399 ivsize = crypto_blkcipher_ivsize(tfm);
101400-
101401 memcpy(iv, aes_iv, ivsize);
101402
101403 /*
101404@@ -228,12 +317,10 @@ static int ceph_aes_decrypt(const void *key, int key_len,
101405 print_hex_dump(KERN_ERR, "dec in: ", DUMP_PREFIX_NONE, 16, 1,
101406 src, src_len, 1);
101407 */
101408-
101409- ret = crypto_blkcipher_decrypt(&desc, sg_out, sg_in, src_len);
101410- crypto_free_blkcipher(tfm);
101411+ ret = crypto_blkcipher_decrypt(&desc, sg_out, sg_in.sgl, src_len);
101412 if (ret < 0) {
101413 pr_err("ceph_aes_decrypt failed %d\n", ret);
101414- return ret;
101415+ goto out_sg;
101416 }
101417
101418 if (src_len <= *dst_len)
101419@@ -251,7 +338,12 @@ static int ceph_aes_decrypt(const void *key, int key_len,
101420 print_hex_dump(KERN_ERR, "dec out: ", DUMP_PREFIX_NONE, 16, 1,
101421 dst, *dst_len, 1);
101422 */
101423- return 0;
101424+
101425+out_sg:
101426+ teardown_sgtable(&sg_in);
101427+out_tfm:
101428+ crypto_free_blkcipher(tfm);
101429+ return ret;
101430 }
101431
101432 static int ceph_aes_decrypt2(const void *key, int key_len,
101433@@ -259,7 +351,8 @@ static int ceph_aes_decrypt2(const void *key, int key_len,
101434 void *dst2, size_t *dst2_len,
101435 const void *src, size_t src_len)
101436 {
101437- struct scatterlist sg_in[1], sg_out[3];
101438+ struct sg_table sg_in;
101439+ struct scatterlist sg_out[3], prealloc_sg;
101440 struct crypto_blkcipher *tfm = ceph_crypto_alloc_cipher();
101441 struct blkcipher_desc desc = { .tfm = tfm };
101442 char pad[16];
101443@@ -271,17 +364,17 @@ static int ceph_aes_decrypt2(const void *key, int key_len,
101444 if (IS_ERR(tfm))
101445 return PTR_ERR(tfm);
101446
101447- sg_init_table(sg_in, 1);
101448- sg_set_buf(sg_in, src, src_len);
101449 sg_init_table(sg_out, 3);
101450 sg_set_buf(&sg_out[0], dst1, *dst1_len);
101451 sg_set_buf(&sg_out[1], dst2, *dst2_len);
101452 sg_set_buf(&sg_out[2], pad, sizeof(pad));
101453+ ret = setup_sgtable(&sg_in, &prealloc_sg, src, src_len);
101454+ if (ret)
101455+ goto out_tfm;
101456
101457 crypto_blkcipher_setkey((void *)tfm, key, key_len);
101458 iv = crypto_blkcipher_crt(tfm)->iv;
101459 ivsize = crypto_blkcipher_ivsize(tfm);
101460-
101461 memcpy(iv, aes_iv, ivsize);
101462
101463 /*
101464@@ -290,12 +383,10 @@ static int ceph_aes_decrypt2(const void *key, int key_len,
101465 print_hex_dump(KERN_ERR, "dec in: ", DUMP_PREFIX_NONE, 16, 1,
101466 src, src_len, 1);
101467 */
101468-
101469- ret = crypto_blkcipher_decrypt(&desc, sg_out, sg_in, src_len);
101470- crypto_free_blkcipher(tfm);
101471+ ret = crypto_blkcipher_decrypt(&desc, sg_out, sg_in.sgl, src_len);
101472 if (ret < 0) {
101473 pr_err("ceph_aes_decrypt failed %d\n", ret);
101474- return ret;
101475+ goto out_sg;
101476 }
101477
101478 if (src_len <= *dst1_len)
101479@@ -325,7 +416,11 @@ static int ceph_aes_decrypt2(const void *key, int key_len,
101480 dst2, *dst2_len, 1);
101481 */
101482
101483- return 0;
101484+out_sg:
101485+ teardown_sgtable(&sg_in);
101486+out_tfm:
101487+ crypto_free_blkcipher(tfm);
101488+ return ret;
101489 }
101490
101491
101492diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
101493index 9f02369..e6160e9 100644
101494--- a/net/ceph/messenger.c
101495+++ b/net/ceph/messenger.c
101496@@ -188,7 +188,7 @@ static void con_fault(struct ceph_connection *con);
101497 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
101498
101499 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
101500-static atomic_t addr_str_seq = ATOMIC_INIT(0);
101501+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
101502
101503 static struct page *zero_page; /* used in certain error cases */
101504
101505@@ -199,7 +199,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
101506 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
101507 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
101508
101509- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101510+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
101511 s = addr_str[i];
101512
101513 switch (ss->ss_family) {
101514diff --git a/net/compat.c b/net/compat.c
101515index bc8aeef..f9c070c 100644
101516--- a/net/compat.c
101517+++ b/net/compat.c
101518@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
101519 return -EFAULT;
101520 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
101521 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
101522- kmsg->msg_name = compat_ptr(tmp1);
101523- kmsg->msg_iov = compat_ptr(tmp2);
101524- kmsg->msg_control = compat_ptr(tmp3);
101525+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
101526+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
101527+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
101528 return 0;
101529 }
101530
101531@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101532
101533 if (kern_msg->msg_name && kern_msg->msg_namelen) {
101534 if (mode == VERIFY_READ) {
101535- int err = move_addr_to_kernel(kern_msg->msg_name,
101536+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
101537 kern_msg->msg_namelen,
101538 kern_address);
101539 if (err < 0)
101540@@ -100,7 +100,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101541 }
101542
101543 tot_len = iov_from_user_compat_to_kern(kern_iov,
101544- (struct compat_iovec __user *)kern_msg->msg_iov,
101545+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
101546 kern_msg->msg_iovlen);
101547 if (tot_len >= 0)
101548 kern_msg->msg_iov = kern_iov;
101549@@ -120,20 +120,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
101550
101551 #define CMSG_COMPAT_FIRSTHDR(msg) \
101552 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
101553- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
101554+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
101555 (struct compat_cmsghdr __user *)NULL)
101556
101557 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
101558 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
101559 (ucmlen) <= (unsigned long) \
101560 ((mhdr)->msg_controllen - \
101561- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
101562+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
101563
101564 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
101565 struct compat_cmsghdr __user *cmsg, int cmsg_len)
101566 {
101567 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
101568- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
101569+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
101570 msg->msg_controllen)
101571 return NULL;
101572 return (struct compat_cmsghdr __user *)ptr;
101573@@ -223,7 +223,7 @@ Efault:
101574
101575 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
101576 {
101577- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101578+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101579 struct compat_cmsghdr cmhdr;
101580 struct compat_timeval ctv;
101581 struct compat_timespec cts[3];
101582@@ -279,7 +279,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
101583
101584 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
101585 {
101586- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
101587+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
101588 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
101589 int fdnum = scm->fp->count;
101590 struct file **fp = scm->fp->fp;
101591@@ -367,7 +367,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
101592 return -EFAULT;
101593 old_fs = get_fs();
101594 set_fs(KERNEL_DS);
101595- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
101596+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
101597 set_fs(old_fs);
101598
101599 return err;
101600@@ -428,7 +428,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
101601 len = sizeof(ktime);
101602 old_fs = get_fs();
101603 set_fs(KERNEL_DS);
101604- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
101605+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
101606 set_fs(old_fs);
101607
101608 if (!err) {
101609@@ -571,7 +571,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101610 case MCAST_JOIN_GROUP:
101611 case MCAST_LEAVE_GROUP:
101612 {
101613- struct compat_group_req __user *gr32 = (void *)optval;
101614+ struct compat_group_req __user *gr32 = (void __user *)optval;
101615 struct group_req __user *kgr =
101616 compat_alloc_user_space(sizeof(struct group_req));
101617 u32 interface;
101618@@ -592,7 +592,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101619 case MCAST_BLOCK_SOURCE:
101620 case MCAST_UNBLOCK_SOURCE:
101621 {
101622- struct compat_group_source_req __user *gsr32 = (void *)optval;
101623+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
101624 struct group_source_req __user *kgsr = compat_alloc_user_space(
101625 sizeof(struct group_source_req));
101626 u32 interface;
101627@@ -613,7 +613,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
101628 }
101629 case MCAST_MSFILTER:
101630 {
101631- struct compat_group_filter __user *gf32 = (void *)optval;
101632+ struct compat_group_filter __user *gf32 = (void __user *)optval;
101633 struct group_filter __user *kgf;
101634 u32 interface, fmode, numsrc;
101635
101636@@ -651,7 +651,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
101637 char __user *optval, int __user *optlen,
101638 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
101639 {
101640- struct compat_group_filter __user *gf32 = (void *)optval;
101641+ struct compat_group_filter __user *gf32 = (void __user *)optval;
101642 struct group_filter __user *kgf;
101643 int __user *koptlen;
101644 u32 interface, fmode, numsrc;
101645@@ -804,7 +804,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
101646
101647 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
101648 return -EINVAL;
101649- if (copy_from_user(a, args, nas[call]))
101650+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
101651 return -EFAULT;
101652 a0 = a[0];
101653 a1 = a[1];
101654diff --git a/net/core/datagram.c b/net/core/datagram.c
101655index fdbc9a8..cd6972c 100644
101656--- a/net/core/datagram.c
101657+++ b/net/core/datagram.c
101658@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
101659 }
101660
101661 kfree_skb(skb);
101662- atomic_inc(&sk->sk_drops);
101663+ atomic_inc_unchecked(&sk->sk_drops);
101664 sk_mem_reclaim_partial(sk);
101665
101666 return err;
101667diff --git a/net/core/dev.c b/net/core/dev.c
101668index cf8a95f..2837211 100644
101669--- a/net/core/dev.c
101670+++ b/net/core/dev.c
101671@@ -1683,14 +1683,14 @@ int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
101672 {
101673 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
101674 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
101675- atomic_long_inc(&dev->rx_dropped);
101676+ atomic_long_inc_unchecked(&dev->rx_dropped);
101677 kfree_skb(skb);
101678 return NET_RX_DROP;
101679 }
101680 }
101681
101682 if (unlikely(!is_skb_forwardable(dev, skb))) {
101683- atomic_long_inc(&dev->rx_dropped);
101684+ atomic_long_inc_unchecked(&dev->rx_dropped);
101685 kfree_skb(skb);
101686 return NET_RX_DROP;
101687 }
101688@@ -2487,7 +2487,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
101689
101690 struct dev_gso_cb {
101691 void (*destructor)(struct sk_buff *skb);
101692-};
101693+} __no_const;
101694
101695 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
101696
101697@@ -2952,7 +2952,7 @@ recursion_alert:
101698 rc = -ENETDOWN;
101699 rcu_read_unlock_bh();
101700
101701- atomic_long_inc(&dev->tx_dropped);
101702+ atomic_long_inc_unchecked(&dev->tx_dropped);
101703 kfree_skb(skb);
101704 return rc;
101705 out:
101706@@ -3296,7 +3296,7 @@ enqueue:
101707
101708 local_irq_restore(flags);
101709
101710- atomic_long_inc(&skb->dev->rx_dropped);
101711+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101712 kfree_skb(skb);
101713 return NET_RX_DROP;
101714 }
101715@@ -3373,7 +3373,7 @@ int netif_rx_ni(struct sk_buff *skb)
101716 }
101717 EXPORT_SYMBOL(netif_rx_ni);
101718
101719-static void net_tx_action(struct softirq_action *h)
101720+static __latent_entropy void net_tx_action(void)
101721 {
101722 struct softnet_data *sd = &__get_cpu_var(softnet_data);
101723
101724@@ -3706,7 +3706,7 @@ ncls:
101725 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
101726 } else {
101727 drop:
101728- atomic_long_inc(&skb->dev->rx_dropped);
101729+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
101730 kfree_skb(skb);
101731 /* Jamal, now you will not able to escape explaining
101732 * me how you were going to use this. :-)
101733@@ -4426,7 +4426,7 @@ void netif_napi_del(struct napi_struct *napi)
101734 }
101735 EXPORT_SYMBOL(netif_napi_del);
101736
101737-static void net_rx_action(struct softirq_action *h)
101738+static __latent_entropy void net_rx_action(void)
101739 {
101740 struct softnet_data *sd = &__get_cpu_var(softnet_data);
101741 unsigned long time_limit = jiffies + 2;
101742@@ -6480,8 +6480,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
101743 } else {
101744 netdev_stats_to_stats64(storage, &dev->stats);
101745 }
101746- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
101747- storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
101748+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
101749+ storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
101750 return storage;
101751 }
101752 EXPORT_SYMBOL(dev_get_stats);
101753diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
101754index cf999e0..c59a9754 100644
101755--- a/net/core/dev_ioctl.c
101756+++ b/net/core/dev_ioctl.c
101757@@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
101758 if (no_module && capable(CAP_NET_ADMIN))
101759 no_module = request_module("netdev-%s", name);
101760 if (no_module && capable(CAP_SYS_MODULE)) {
101761+#ifdef CONFIG_GRKERNSEC_MODHARDEN
101762+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
101763+#else
101764 if (!request_module("%s", name))
101765 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
101766 name);
101767+#endif
101768 }
101769 }
101770 EXPORT_SYMBOL(dev_load);
101771diff --git a/net/core/filter.c b/net/core/filter.c
101772index d814b8a..b5ab778 100644
101773--- a/net/core/filter.c
101774+++ b/net/core/filter.c
101775@@ -559,7 +559,11 @@ do_pass:
101776
101777 /* Unkown instruction. */
101778 default:
101779- goto err;
101780+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
101781+ fp->code, fp->jt, fp->jf, fp->k);
101782+ kfree(addrs);
101783+ BUG();
101784+ return -EINVAL;
101785 }
101786
101787 insn++;
101788@@ -606,7 +610,7 @@ static int check_load_and_stores(const struct sock_filter *filter, int flen)
101789 u16 *masks, memvalid = 0; /* One bit per cell, 16 cells */
101790 int pc, ret = 0;
101791
101792- BUILD_BUG_ON(BPF_MEMWORDS > 16);
101793+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
101794
101795 masks = kmalloc_array(flen, sizeof(*masks), GFP_KERNEL);
101796 if (!masks)
101797@@ -933,7 +937,7 @@ static struct bpf_prog *bpf_migrate_filter(struct bpf_prog *fp)
101798
101799 /* Expand fp for appending the new filter representation. */
101800 old_fp = fp;
101801- fp = krealloc(old_fp, bpf_prog_size(new_len), GFP_KERNEL);
101802+ fp = bpf_prog_realloc(old_fp, bpf_prog_size(new_len), 0);
101803 if (!fp) {
101804 /* The old_fp is still around in case we couldn't
101805 * allocate new memory, so uncharge on that one.
101806@@ -1013,11 +1017,11 @@ int bpf_prog_create(struct bpf_prog **pfp, struct sock_fprog_kern *fprog)
101807 if (fprog->filter == NULL)
101808 return -EINVAL;
101809
101810- fp = kmalloc(bpf_prog_size(fprog->len), GFP_KERNEL);
101811+ fp = bpf_prog_alloc(bpf_prog_size(fprog->len), 0);
101812 if (!fp)
101813 return -ENOMEM;
101814
101815- memcpy(fp->insns, fprog->filter, fsize);
101816+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
101817
101818 fp->len = fprog->len;
101819 /* Since unattached filters are not copied back to user
101820@@ -1069,12 +1073,12 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
101821 if (fprog->filter == NULL)
101822 return -EINVAL;
101823
101824- prog = kmalloc(bpf_fsize, GFP_KERNEL);
101825+ prog = bpf_prog_alloc(bpf_fsize, 0);
101826 if (!prog)
101827 return -ENOMEM;
101828
101829 if (copy_from_user(prog->insns, fprog->filter, fsize)) {
101830- kfree(prog);
101831+ __bpf_prog_free(prog);
101832 return -EFAULT;
101833 }
101834
101835@@ -1082,7 +1086,7 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
101836
101837 err = bpf_prog_store_orig_filter(prog, fprog);
101838 if (err) {
101839- kfree(prog);
101840+ __bpf_prog_free(prog);
101841 return -ENOMEM;
101842 }
101843
101844diff --git a/net/core/flow.c b/net/core/flow.c
101845index a0348fd..6951c76 100644
101846--- a/net/core/flow.c
101847+++ b/net/core/flow.c
101848@@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
101849 static int flow_entry_valid(struct flow_cache_entry *fle,
101850 struct netns_xfrm *xfrm)
101851 {
101852- if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
101853+ if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
101854 return 0;
101855 if (fle->object && !fle->object->ops->check(fle->object))
101856 return 0;
101857@@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
101858 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
101859 fcp->hash_count++;
101860 }
101861- } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
101862+ } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
101863 flo = fle->object;
101864 if (!flo)
101865 goto ret_object;
101866@@ -263,7 +263,7 @@ nocache:
101867 }
101868 flo = resolver(net, key, family, dir, flo, ctx);
101869 if (fle) {
101870- fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
101871+ fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
101872 if (!IS_ERR(flo))
101873 fle->object = flo;
101874 else
101875diff --git a/net/core/iovec.c b/net/core/iovec.c
101876index e1ec45a..e5c6f16 100644
101877--- a/net/core/iovec.c
101878+++ b/net/core/iovec.c
101879@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101880 if (m->msg_name && m->msg_namelen) {
101881 if (mode == VERIFY_READ) {
101882 void __user *namep;
101883- namep = (void __user __force *) m->msg_name;
101884+ namep = (void __force_user *) m->msg_name;
101885 err = move_addr_to_kernel(namep, m->msg_namelen,
101886 address);
101887 if (err < 0)
101888@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
101889 }
101890
101891 size = m->msg_iovlen * sizeof(struct iovec);
101892- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
101893+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
101894 return -EFAULT;
101895
101896 m->msg_iov = iov;
101897diff --git a/net/core/neighbour.c b/net/core/neighbour.c
101898index ef31fef..8be66d9 100644
101899--- a/net/core/neighbour.c
101900+++ b/net/core/neighbour.c
101901@@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
101902 void __user *buffer, size_t *lenp, loff_t *ppos)
101903 {
101904 int size, ret;
101905- struct ctl_table tmp = *ctl;
101906+ ctl_table_no_const tmp = *ctl;
101907
101908 tmp.extra1 = &zero;
101909 tmp.extra2 = &unres_qlen_max;
101910@@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
101911 void __user *buffer,
101912 size_t *lenp, loff_t *ppos)
101913 {
101914- struct ctl_table tmp = *ctl;
101915+ ctl_table_no_const tmp = *ctl;
101916 int ret;
101917
101918 tmp.extra1 = &zero;
101919diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
101920index 2bf8329..2eb1423 100644
101921--- a/net/core/net-procfs.c
101922+++ b/net/core/net-procfs.c
101923@@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
101924 struct rtnl_link_stats64 temp;
101925 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
101926
101927- seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101928+ if (gr_proc_is_restricted())
101929+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101930+ "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101931+ dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
101932+ 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
101933+ else
101934+ seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
101935 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
101936 dev->name, stats->rx_bytes, stats->rx_packets,
101937 stats->rx_errors,
101938@@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
101939 return 0;
101940 }
101941
101942-static const struct seq_operations dev_seq_ops = {
101943+const struct seq_operations dev_seq_ops = {
101944 .start = dev_seq_start,
101945 .next = dev_seq_next,
101946 .stop = dev_seq_stop,
101947@@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
101948
101949 static int softnet_seq_open(struct inode *inode, struct file *file)
101950 {
101951- return seq_open(file, &softnet_seq_ops);
101952+ return seq_open_restrict(file, &softnet_seq_ops);
101953 }
101954
101955 static const struct file_operations softnet_seq_fops = {
101956@@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
101957 else
101958 seq_printf(seq, "%04x", ntohs(pt->type));
101959
101960+#ifdef CONFIG_GRKERNSEC_HIDESYM
101961+ seq_printf(seq, " %-8s %pf\n",
101962+ pt->dev ? pt->dev->name : "", NULL);
101963+#else
101964 seq_printf(seq, " %-8s %pf\n",
101965 pt->dev ? pt->dev->name : "", pt->func);
101966+#endif
101967 }
101968
101969 return 0;
101970diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
101971index 9dd0669..c52fb1b 100644
101972--- a/net/core/net-sysfs.c
101973+++ b/net/core/net-sysfs.c
101974@@ -278,7 +278,7 @@ static ssize_t carrier_changes_show(struct device *dev,
101975 {
101976 struct net_device *netdev = to_net_dev(dev);
101977 return sprintf(buf, fmt_dec,
101978- atomic_read(&netdev->carrier_changes));
101979+ atomic_read_unchecked(&netdev->carrier_changes));
101980 }
101981 static DEVICE_ATTR_RO(carrier_changes);
101982
101983diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
101984index 7c6b51a..e9dd57f 100644
101985--- a/net/core/net_namespace.c
101986+++ b/net/core/net_namespace.c
101987@@ -445,7 +445,7 @@ static int __register_pernet_operations(struct list_head *list,
101988 int error;
101989 LIST_HEAD(net_exit_list);
101990
101991- list_add_tail(&ops->list, list);
101992+ pax_list_add_tail((struct list_head *)&ops->list, list);
101993 if (ops->init || (ops->id && ops->size)) {
101994 for_each_net(net) {
101995 error = ops_init(ops, net);
101996@@ -458,7 +458,7 @@ static int __register_pernet_operations(struct list_head *list,
101997
101998 out_undo:
101999 /* If I have an error cleanup all namespaces I initialized */
102000- list_del(&ops->list);
102001+ pax_list_del((struct list_head *)&ops->list);
102002 ops_exit_list(ops, &net_exit_list);
102003 ops_free_list(ops, &net_exit_list);
102004 return error;
102005@@ -469,7 +469,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
102006 struct net *net;
102007 LIST_HEAD(net_exit_list);
102008
102009- list_del(&ops->list);
102010+ pax_list_del((struct list_head *)&ops->list);
102011 for_each_net(net)
102012 list_add_tail(&net->exit_list, &net_exit_list);
102013 ops_exit_list(ops, &net_exit_list);
102014@@ -603,7 +603,7 @@ int register_pernet_device(struct pernet_operations *ops)
102015 mutex_lock(&net_mutex);
102016 error = register_pernet_operations(&pernet_list, ops);
102017 if (!error && (first_device == &pernet_list))
102018- first_device = &ops->list;
102019+ first_device = (struct list_head *)&ops->list;
102020 mutex_unlock(&net_mutex);
102021 return error;
102022 }
102023diff --git a/net/core/netpoll.c b/net/core/netpoll.c
102024index 907fb5e..8260f040b 100644
102025--- a/net/core/netpoll.c
102026+++ b/net/core/netpoll.c
102027@@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
102028 struct udphdr *udph;
102029 struct iphdr *iph;
102030 struct ethhdr *eth;
102031- static atomic_t ip_ident;
102032+ static atomic_unchecked_t ip_ident;
102033 struct ipv6hdr *ip6h;
102034
102035 udp_len = len + sizeof(*udph);
102036@@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
102037 put_unaligned(0x45, (unsigned char *)iph);
102038 iph->tos = 0;
102039 put_unaligned(htons(ip_len), &(iph->tot_len));
102040- iph->id = htons(atomic_inc_return(&ip_ident));
102041+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
102042 iph->frag_off = 0;
102043 iph->ttl = 64;
102044 iph->protocol = IPPROTO_UDP;
102045diff --git a/net/core/pktgen.c b/net/core/pktgen.c
102046index 8b849dd..cd88bfc 100644
102047--- a/net/core/pktgen.c
102048+++ b/net/core/pktgen.c
102049@@ -3723,7 +3723,7 @@ static int __net_init pg_net_init(struct net *net)
102050 pn->net = net;
102051 INIT_LIST_HEAD(&pn->pktgen_threads);
102052 pn->pktgen_exiting = false;
102053- pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
102054+ pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
102055 if (!pn->proc_dir) {
102056 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
102057 return -ENODEV;
102058diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
102059index f0493e3..0f43f7a 100644
102060--- a/net/core/rtnetlink.c
102061+++ b/net/core/rtnetlink.c
102062@@ -58,7 +58,7 @@ struct rtnl_link {
102063 rtnl_doit_func doit;
102064 rtnl_dumpit_func dumpit;
102065 rtnl_calcit_func calcit;
102066-};
102067+} __no_const;
102068
102069 static DEFINE_MUTEX(rtnl_mutex);
102070
102071@@ -304,10 +304,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
102072 * to use the ops for creating device. So do not
102073 * fill up dellink as well. That disables rtnl_dellink.
102074 */
102075- if (ops->setup && !ops->dellink)
102076- ops->dellink = unregister_netdevice_queue;
102077+ if (ops->setup && !ops->dellink) {
102078+ pax_open_kernel();
102079+ *(void **)&ops->dellink = unregister_netdevice_queue;
102080+ pax_close_kernel();
102081+ }
102082
102083- list_add_tail(&ops->list, &link_ops);
102084+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
102085 return 0;
102086 }
102087 EXPORT_SYMBOL_GPL(__rtnl_link_register);
102088@@ -354,7 +357,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
102089 for_each_net(net) {
102090 __rtnl_kill_links(net, ops);
102091 }
102092- list_del(&ops->list);
102093+ pax_list_del((struct list_head *)&ops->list);
102094 }
102095 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
102096
102097@@ -1014,7 +1017,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
102098 (dev->ifalias &&
102099 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
102100 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
102101- atomic_read(&dev->carrier_changes)))
102102+ atomic_read_unchecked(&dev->carrier_changes)))
102103 goto nla_put_failure;
102104
102105 if (1) {
102106diff --git a/net/core/scm.c b/net/core/scm.c
102107index b442e7e..6f5b5a2 100644
102108--- a/net/core/scm.c
102109+++ b/net/core/scm.c
102110@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
102111 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
102112 {
102113 struct cmsghdr __user *cm
102114- = (__force struct cmsghdr __user *)msg->msg_control;
102115+ = (struct cmsghdr __force_user *)msg->msg_control;
102116 struct cmsghdr cmhdr;
102117 int cmlen = CMSG_LEN(len);
102118 int err;
102119@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
102120 err = -EFAULT;
102121 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
102122 goto out;
102123- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
102124+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
102125 goto out;
102126 cmlen = CMSG_SPACE(len);
102127 if (msg->msg_controllen < cmlen)
102128@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
102129 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
102130 {
102131 struct cmsghdr __user *cm
102132- = (__force struct cmsghdr __user*)msg->msg_control;
102133+ = (struct cmsghdr __force_user *)msg->msg_control;
102134
102135 int fdmax = 0;
102136 int fdnum = scm->fp->count;
102137@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
102138 if (fdnum < fdmax)
102139 fdmax = fdnum;
102140
102141- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
102142+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
102143 i++, cmfptr++)
102144 {
102145 struct socket *sock;
102146diff --git a/net/core/skbuff.c b/net/core/skbuff.c
102147index 8d28969..4d36260 100644
102148--- a/net/core/skbuff.c
102149+++ b/net/core/skbuff.c
102150@@ -360,18 +360,29 @@ refill:
102151 goto end;
102152 }
102153 nc->frag.size = PAGE_SIZE << order;
102154-recycle:
102155- atomic_set(&nc->frag.page->_count, NETDEV_PAGECNT_MAX_BIAS);
102156+ /* Even if we own the page, we do not use atomic_set().
102157+ * This would break get_page_unless_zero() users.
102158+ */
102159+ atomic_add(NETDEV_PAGECNT_MAX_BIAS - 1,
102160+ &nc->frag.page->_count);
102161 nc->pagecnt_bias = NETDEV_PAGECNT_MAX_BIAS;
102162 nc->frag.offset = 0;
102163 }
102164
102165 if (nc->frag.offset + fragsz > nc->frag.size) {
102166- /* avoid unnecessary locked operations if possible */
102167- if ((atomic_read(&nc->frag.page->_count) == nc->pagecnt_bias) ||
102168- atomic_sub_and_test(nc->pagecnt_bias, &nc->frag.page->_count))
102169- goto recycle;
102170- goto refill;
102171+ if (atomic_read(&nc->frag.page->_count) != nc->pagecnt_bias) {
102172+ if (!atomic_sub_and_test(nc->pagecnt_bias,
102173+ &nc->frag.page->_count))
102174+ goto refill;
102175+ /* OK, page count is 0, we can safely set it */
102176+ atomic_set(&nc->frag.page->_count,
102177+ NETDEV_PAGECNT_MAX_BIAS);
102178+ } else {
102179+ atomic_add(NETDEV_PAGECNT_MAX_BIAS - nc->pagecnt_bias,
102180+ &nc->frag.page->_count);
102181+ }
102182+ nc->pagecnt_bias = NETDEV_PAGECNT_MAX_BIAS;
102183+ nc->frag.offset = 0;
102184 }
102185
102186 data = page_address(nc->frag.page) + nc->frag.offset;
102187@@ -2011,7 +2022,7 @@ EXPORT_SYMBOL(__skb_checksum);
102188 __wsum skb_checksum(const struct sk_buff *skb, int offset,
102189 int len, __wsum csum)
102190 {
102191- const struct skb_checksum_ops ops = {
102192+ static const struct skb_checksum_ops ops = {
102193 .update = csum_partial_ext,
102194 .combine = csum_block_add_ext,
102195 };
102196@@ -3237,13 +3248,15 @@ void __init skb_init(void)
102197 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
102198 sizeof(struct sk_buff),
102199 0,
102200- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
102201+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
102202+ SLAB_NO_SANITIZE,
102203 NULL);
102204 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
102205 (2*sizeof(struct sk_buff)) +
102206 sizeof(atomic_t),
102207 0,
102208- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
102209+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
102210+ SLAB_NO_SANITIZE,
102211 NULL);
102212 }
102213
102214diff --git a/net/core/sock.c b/net/core/sock.c
102215index 9c3f823..bd8c884 100644
102216--- a/net/core/sock.c
102217+++ b/net/core/sock.c
102218@@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102219 struct sk_buff_head *list = &sk->sk_receive_queue;
102220
102221 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
102222- atomic_inc(&sk->sk_drops);
102223+ atomic_inc_unchecked(&sk->sk_drops);
102224 trace_sock_rcvqueue_full(sk, skb);
102225 return -ENOMEM;
102226 }
102227@@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102228 return err;
102229
102230 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
102231- atomic_inc(&sk->sk_drops);
102232+ atomic_inc_unchecked(&sk->sk_drops);
102233 return -ENOBUFS;
102234 }
102235
102236@@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
102237 skb_dst_force(skb);
102238
102239 spin_lock_irqsave(&list->lock, flags);
102240- skb->dropcount = atomic_read(&sk->sk_drops);
102241+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
102242 __skb_queue_tail(list, skb);
102243 spin_unlock_irqrestore(&list->lock, flags);
102244
102245@@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
102246 skb->dev = NULL;
102247
102248 if (sk_rcvqueues_full(sk, sk->sk_rcvbuf)) {
102249- atomic_inc(&sk->sk_drops);
102250+ atomic_inc_unchecked(&sk->sk_drops);
102251 goto discard_and_relse;
102252 }
102253 if (nested)
102254@@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
102255 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
102256 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
102257 bh_unlock_sock(sk);
102258- atomic_inc(&sk->sk_drops);
102259+ atomic_inc_unchecked(&sk->sk_drops);
102260 goto discard_and_relse;
102261 }
102262
102263@@ -999,12 +999,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102264 struct timeval tm;
102265 } v;
102266
102267- int lv = sizeof(int);
102268- int len;
102269+ unsigned int lv = sizeof(int);
102270+ unsigned int len;
102271
102272 if (get_user(len, optlen))
102273 return -EFAULT;
102274- if (len < 0)
102275+ if (len > INT_MAX)
102276 return -EINVAL;
102277
102278 memset(&v, 0, sizeof(v));
102279@@ -1142,11 +1142,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102280
102281 case SO_PEERNAME:
102282 {
102283- char address[128];
102284+ char address[_K_SS_MAXSIZE];
102285
102286 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
102287 return -ENOTCONN;
102288- if (lv < len)
102289+ if (lv < len || sizeof address < len)
102290 return -EINVAL;
102291 if (copy_to_user(optval, address, len))
102292 return -EFAULT;
102293@@ -1227,7 +1227,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
102294
102295 if (len > lv)
102296 len = lv;
102297- if (copy_to_user(optval, &v, len))
102298+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
102299 return -EFAULT;
102300 lenout:
102301 if (put_user(len, optlen))
102302@@ -1723,6 +1723,8 @@ EXPORT_SYMBOL(sock_kmalloc);
102303 */
102304 void sock_kfree_s(struct sock *sk, void *mem, int size)
102305 {
102306+ if (WARN_ON_ONCE(!mem))
102307+ return;
102308 kfree(mem);
102309 atomic_sub(size, &sk->sk_omem_alloc);
102310 }
102311@@ -2369,7 +2371,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
102312 */
102313 smp_wmb();
102314 atomic_set(&sk->sk_refcnt, 1);
102315- atomic_set(&sk->sk_drops, 0);
102316+ atomic_set_unchecked(&sk->sk_drops, 0);
102317 }
102318 EXPORT_SYMBOL(sock_init_data);
102319
102320@@ -2497,6 +2499,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
102321 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
102322 int level, int type)
102323 {
102324+ struct sock_extended_err ee;
102325 struct sock_exterr_skb *serr;
102326 struct sk_buff *skb, *skb2;
102327 int copied, err;
102328@@ -2518,7 +2521,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
102329 sock_recv_timestamp(msg, sk, skb);
102330
102331 serr = SKB_EXT_ERR(skb);
102332- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
102333+ ee = serr->ee;
102334+ put_cmsg(msg, level, type, sizeof ee, &ee);
102335
102336 msg->msg_flags |= MSG_ERRQUEUE;
102337 err = copied;
102338diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
102339index ad704c7..ca48aff 100644
102340--- a/net/core/sock_diag.c
102341+++ b/net/core/sock_diag.c
102342@@ -9,26 +9,33 @@
102343 #include <linux/inet_diag.h>
102344 #include <linux/sock_diag.h>
102345
102346-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
102347+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
102348 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
102349 static DEFINE_MUTEX(sock_diag_table_mutex);
102350
102351 int sock_diag_check_cookie(void *sk, __u32 *cookie)
102352 {
102353+#ifndef CONFIG_GRKERNSEC_HIDESYM
102354 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
102355 cookie[1] != INET_DIAG_NOCOOKIE) &&
102356 ((u32)(unsigned long)sk != cookie[0] ||
102357 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
102358 return -ESTALE;
102359 else
102360+#endif
102361 return 0;
102362 }
102363 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
102364
102365 void sock_diag_save_cookie(void *sk, __u32 *cookie)
102366 {
102367+#ifdef CONFIG_GRKERNSEC_HIDESYM
102368+ cookie[0] = 0;
102369+ cookie[1] = 0;
102370+#else
102371 cookie[0] = (u32)(unsigned long)sk;
102372 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
102373+#endif
102374 }
102375 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
102376
102377@@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
102378 mutex_lock(&sock_diag_table_mutex);
102379 if (sock_diag_handlers[hndl->family])
102380 err = -EBUSY;
102381- else
102382+ else {
102383+ pax_open_kernel();
102384 sock_diag_handlers[hndl->family] = hndl;
102385+ pax_close_kernel();
102386+ }
102387 mutex_unlock(&sock_diag_table_mutex);
102388
102389 return err;
102390@@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
102391
102392 mutex_lock(&sock_diag_table_mutex);
102393 BUG_ON(sock_diag_handlers[family] != hnld);
102394+ pax_open_kernel();
102395 sock_diag_handlers[family] = NULL;
102396+ pax_close_kernel();
102397 mutex_unlock(&sock_diag_table_mutex);
102398 }
102399 EXPORT_SYMBOL_GPL(sock_diag_unregister);
102400diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
102401index cf9cd13..50683950 100644
102402--- a/net/core/sysctl_net_core.c
102403+++ b/net/core/sysctl_net_core.c
102404@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
102405 {
102406 unsigned int orig_size, size;
102407 int ret, i;
102408- struct ctl_table tmp = {
102409+ ctl_table_no_const tmp = {
102410 .data = &size,
102411 .maxlen = sizeof(size),
102412 .mode = table->mode
102413@@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
102414 void __user *buffer, size_t *lenp, loff_t *ppos)
102415 {
102416 char id[IFNAMSIZ];
102417- struct ctl_table tbl = {
102418+ ctl_table_no_const tbl = {
102419 .data = id,
102420 .maxlen = IFNAMSIZ,
102421 };
102422@@ -263,7 +263,7 @@ static struct ctl_table net_core_table[] = {
102423 .mode = 0644,
102424 .proc_handler = proc_dointvec
102425 },
102426-#ifdef CONFIG_BPF_JIT
102427+#if defined(CONFIG_BPF_JIT) && !defined(CONFIG_GRKERNSEC_BPF_HARDEN)
102428 {
102429 .procname = "bpf_jit_enable",
102430 .data = &bpf_jit_enable,
102431@@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
102432
102433 static __net_init int sysctl_core_net_init(struct net *net)
102434 {
102435- struct ctl_table *tbl;
102436+ ctl_table_no_const *tbl = NULL;
102437
102438 net->core.sysctl_somaxconn = SOMAXCONN;
102439
102440- tbl = netns_core_table;
102441 if (!net_eq(net, &init_net)) {
102442- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
102443+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
102444 if (tbl == NULL)
102445 goto err_dup;
102446
102447@@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
102448 if (net->user_ns != &init_user_ns) {
102449 tbl[0].procname = NULL;
102450 }
102451- }
102452-
102453- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102454+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
102455+ } else
102456+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
102457 if (net->core.sysctl_hdr == NULL)
102458 goto err_reg;
102459
102460 return 0;
102461
102462 err_reg:
102463- if (tbl != netns_core_table)
102464- kfree(tbl);
102465+ kfree(tbl);
102466 err_dup:
102467 return -ENOMEM;
102468 }
102469@@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
102470 kfree(tbl);
102471 }
102472
102473-static __net_initdata struct pernet_operations sysctl_core_ops = {
102474+static __net_initconst struct pernet_operations sysctl_core_ops = {
102475 .init = sysctl_core_net_init,
102476 .exit = sysctl_core_net_exit,
102477 };
102478diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
102479index ae011b4..d2d18bf 100644
102480--- a/net/decnet/af_decnet.c
102481+++ b/net/decnet/af_decnet.c
102482@@ -465,6 +465,7 @@ static struct proto dn_proto = {
102483 .sysctl_rmem = sysctl_decnet_rmem,
102484 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
102485 .obj_size = sizeof(struct dn_sock),
102486+ .slab_flags = SLAB_USERCOPY,
102487 };
102488
102489 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
102490diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
102491index 3b726f3..1af6368 100644
102492--- a/net/decnet/dn_dev.c
102493+++ b/net/decnet/dn_dev.c
102494@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
102495 .extra1 = &min_t3,
102496 .extra2 = &max_t3
102497 },
102498- {0}
102499+ { }
102500 },
102501 };
102502
102503diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
102504index 5325b54..a0d4d69 100644
102505--- a/net/decnet/sysctl_net_decnet.c
102506+++ b/net/decnet/sysctl_net_decnet.c
102507@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
102508
102509 if (len > *lenp) len = *lenp;
102510
102511- if (copy_to_user(buffer, addr, len))
102512+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
102513 return -EFAULT;
102514
102515 *lenp = len;
102516@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
102517
102518 if (len > *lenp) len = *lenp;
102519
102520- if (copy_to_user(buffer, devname, len))
102521+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
102522 return -EFAULT;
102523
102524 *lenp = len;
102525diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
102526index 32755cb..236d827 100644
102527--- a/net/ieee802154/reassembly.c
102528+++ b/net/ieee802154/reassembly.c
102529@@ -433,14 +433,13 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
102530
102531 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102532 {
102533- struct ctl_table *table;
102534+ ctl_table_no_const *table = NULL;
102535 struct ctl_table_header *hdr;
102536 struct netns_ieee802154_lowpan *ieee802154_lowpan =
102537 net_ieee802154_lowpan(net);
102538
102539- table = lowpan_frags_ns_ctl_table;
102540 if (!net_eq(net, &init_net)) {
102541- table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
102542+ table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
102543 GFP_KERNEL);
102544 if (table == NULL)
102545 goto err_alloc;
102546@@ -455,9 +454,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102547 /* Don't export sysctls to unprivileged users */
102548 if (net->user_ns != &init_user_ns)
102549 table[0].procname = NULL;
102550- }
102551-
102552- hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102553+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
102554+ } else
102555+ hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
102556 if (hdr == NULL)
102557 goto err_reg;
102558
102559@@ -465,8 +464,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
102560 return 0;
102561
102562 err_reg:
102563- if (!net_eq(net, &init_net))
102564- kfree(table);
102565+ kfree(table);
102566 err_alloc:
102567 return -ENOMEM;
102568 }
102569diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
102570index 214882e..f958b50 100644
102571--- a/net/ipv4/devinet.c
102572+++ b/net/ipv4/devinet.c
102573@@ -1548,7 +1548,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
102574 idx = 0;
102575 head = &net->dev_index_head[h];
102576 rcu_read_lock();
102577- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102578+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102579 net->dev_base_seq;
102580 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102581 if (idx < s_idx)
102582@@ -1866,7 +1866,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
102583 idx = 0;
102584 head = &net->dev_index_head[h];
102585 rcu_read_lock();
102586- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
102587+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
102588 net->dev_base_seq;
102589 hlist_for_each_entry_rcu(dev, head, index_hlist) {
102590 if (idx < s_idx)
102591@@ -2101,7 +2101,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
102592 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
102593 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
102594
102595-static struct devinet_sysctl_table {
102596+static const struct devinet_sysctl_table {
102597 struct ctl_table_header *sysctl_header;
102598 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
102599 } devinet_sysctl = {
102600@@ -2233,7 +2233,7 @@ static __net_init int devinet_init_net(struct net *net)
102601 int err;
102602 struct ipv4_devconf *all, *dflt;
102603 #ifdef CONFIG_SYSCTL
102604- struct ctl_table *tbl = ctl_forward_entry;
102605+ ctl_table_no_const *tbl = NULL;
102606 struct ctl_table_header *forw_hdr;
102607 #endif
102608
102609@@ -2251,7 +2251,7 @@ static __net_init int devinet_init_net(struct net *net)
102610 goto err_alloc_dflt;
102611
102612 #ifdef CONFIG_SYSCTL
102613- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
102614+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
102615 if (tbl == NULL)
102616 goto err_alloc_ctl;
102617
102618@@ -2271,7 +2271,10 @@ static __net_init int devinet_init_net(struct net *net)
102619 goto err_reg_dflt;
102620
102621 err = -ENOMEM;
102622- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102623+ if (!net_eq(net, &init_net))
102624+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
102625+ else
102626+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
102627 if (forw_hdr == NULL)
102628 goto err_reg_ctl;
102629 net->ipv4.forw_hdr = forw_hdr;
102630@@ -2287,8 +2290,7 @@ err_reg_ctl:
102631 err_reg_dflt:
102632 __devinet_sysctl_unregister(all);
102633 err_reg_all:
102634- if (tbl != ctl_forward_entry)
102635- kfree(tbl);
102636+ kfree(tbl);
102637 err_alloc_ctl:
102638 #endif
102639 if (dflt != &ipv4_devconf_dflt)
102640diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
102641index 255aa99..45c78f8 100644
102642--- a/net/ipv4/fib_frontend.c
102643+++ b/net/ipv4/fib_frontend.c
102644@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
102645 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102646 fib_sync_up(dev);
102647 #endif
102648- atomic_inc(&net->ipv4.dev_addr_genid);
102649+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102650 rt_cache_flush(dev_net(dev));
102651 break;
102652 case NETDEV_DOWN:
102653 fib_del_ifaddr(ifa, NULL);
102654- atomic_inc(&net->ipv4.dev_addr_genid);
102655+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102656 if (ifa->ifa_dev->ifa_list == NULL) {
102657 /* Last address was deleted from this interface.
102658 * Disable IP.
102659@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
102660 #ifdef CONFIG_IP_ROUTE_MULTIPATH
102661 fib_sync_up(dev);
102662 #endif
102663- atomic_inc(&net->ipv4.dev_addr_genid);
102664+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
102665 rt_cache_flush(net);
102666 break;
102667 case NETDEV_DOWN:
102668diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
102669index 4a74ea8..32335a7 100644
102670--- a/net/ipv4/fib_semantics.c
102671+++ b/net/ipv4/fib_semantics.c
102672@@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
102673 nh->nh_saddr = inet_select_addr(nh->nh_dev,
102674 nh->nh_gw,
102675 nh->nh_parent->fib_scope);
102676- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
102677+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
102678
102679 return nh->nh_saddr;
102680 }
102681diff --git a/net/ipv4/gre_offload.c b/net/ipv4/gre_offload.c
102682index dd73bea..a2eec02 100644
102683--- a/net/ipv4/gre_offload.c
102684+++ b/net/ipv4/gre_offload.c
102685@@ -59,13 +59,13 @@ static struct sk_buff *gre_gso_segment(struct sk_buff *skb,
102686 if (csum)
102687 skb->encap_hdr_csum = 1;
102688
102689- if (unlikely(!pskb_may_pull(skb, ghl)))
102690- goto out;
102691-
102692 /* setup inner skb. */
102693 skb->protocol = greh->protocol;
102694 skb->encapsulation = 0;
102695
102696+ if (unlikely(!pskb_may_pull(skb, ghl)))
102697+ goto out;
102698+
102699 __skb_pull(skb, ghl);
102700 skb_reset_mac_header(skb);
102701 skb_set_network_header(skb, skb_inner_network_offset(skb));
102702diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
102703index 43116e8..ba0916a8 100644
102704--- a/net/ipv4/inet_hashtables.c
102705+++ b/net/ipv4/inet_hashtables.c
102706@@ -18,6 +18,7 @@
102707 #include <linux/sched.h>
102708 #include <linux/slab.h>
102709 #include <linux/wait.h>
102710+#include <linux/security.h>
102711
102712 #include <net/inet_connection_sock.h>
102713 #include <net/inet_hashtables.h>
102714@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
102715 return inet_ehashfn(net, laddr, lport, faddr, fport);
102716 }
102717
102718+extern void gr_update_task_in_ip_table(const struct inet_sock *inet);
102719+
102720 /*
102721 * Allocate and initialize a new local port bind bucket.
102722 * The bindhash mutex for snum's hash chain must be held here.
102723@@ -554,6 +557,8 @@ ok:
102724 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
102725 spin_unlock(&head->lock);
102726
102727+ gr_update_task_in_ip_table(inet_sk(sk));
102728+
102729 if (tw) {
102730 inet_twsk_deschedule(tw, death_row);
102731 while (twrefcnt) {
102732diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
102733index bd5f592..e80e605 100644
102734--- a/net/ipv4/inetpeer.c
102735+++ b/net/ipv4/inetpeer.c
102736@@ -482,7 +482,7 @@ relookup:
102737 if (p) {
102738 p->daddr = *daddr;
102739 atomic_set(&p->refcnt, 1);
102740- atomic_set(&p->rid, 0);
102741+ atomic_set_unchecked(&p->rid, 0);
102742 p->metrics[RTAX_LOCK-1] = INETPEER_METRICS_NEW;
102743 p->rate_tokens = 0;
102744 /* 60*HZ is arbitrary, but chosen enough high so that the first
102745diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
102746index 15f0e2b..8cf8177 100644
102747--- a/net/ipv4/ip_fragment.c
102748+++ b/net/ipv4/ip_fragment.c
102749@@ -268,7 +268,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
102750 return 0;
102751
102752 start = qp->rid;
102753- end = atomic_inc_return(&peer->rid);
102754+ end = atomic_inc_return_unchecked(&peer->rid);
102755 qp->rid = end;
102756
102757 rc = qp->q.fragments && (end - start) > max;
102758@@ -746,12 +746,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
102759
102760 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102761 {
102762- struct ctl_table *table;
102763+ ctl_table_no_const *table = NULL;
102764 struct ctl_table_header *hdr;
102765
102766- table = ip4_frags_ns_ctl_table;
102767 if (!net_eq(net, &init_net)) {
102768- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102769+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
102770 if (table == NULL)
102771 goto err_alloc;
102772
102773@@ -765,9 +764,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102774 /* Don't export sysctls to unprivileged users */
102775 if (net->user_ns != &init_user_ns)
102776 table[0].procname = NULL;
102777- }
102778+ hdr = register_net_sysctl(net, "net/ipv4", table);
102779+ } else
102780+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
102781
102782- hdr = register_net_sysctl(net, "net/ipv4", table);
102783 if (hdr == NULL)
102784 goto err_reg;
102785
102786@@ -775,8 +775,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
102787 return 0;
102788
102789 err_reg:
102790- if (!net_eq(net, &init_net))
102791- kfree(table);
102792+ kfree(table);
102793 err_alloc:
102794 return -ENOMEM;
102795 }
102796diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
102797index 9b84254..c776611 100644
102798--- a/net/ipv4/ip_gre.c
102799+++ b/net/ipv4/ip_gre.c
102800@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
102801 module_param(log_ecn_error, bool, 0644);
102802 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102803
102804-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
102805+static struct rtnl_link_ops ipgre_link_ops;
102806 static int ipgre_tunnel_init(struct net_device *dev);
102807
102808 static int ipgre_net_id __read_mostly;
102809@@ -733,7 +733,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
102810 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
102811 };
102812
102813-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102814+static struct rtnl_link_ops ipgre_link_ops = {
102815 .kind = "gre",
102816 .maxtype = IFLA_GRE_MAX,
102817 .policy = ipgre_policy,
102818@@ -747,7 +747,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
102819 .fill_info = ipgre_fill_info,
102820 };
102821
102822-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
102823+static struct rtnl_link_ops ipgre_tap_ops = {
102824 .kind = "gretap",
102825 .maxtype = IFLA_GRE_MAX,
102826 .policy = ipgre_policy,
102827diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
102828index 3d4da2c..40f9c29 100644
102829--- a/net/ipv4/ip_input.c
102830+++ b/net/ipv4/ip_input.c
102831@@ -147,6 +147,10 @@
102832 #include <linux/mroute.h>
102833 #include <linux/netlink.h>
102834
102835+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102836+extern int grsec_enable_blackhole;
102837+#endif
102838+
102839 /*
102840 * Process Router Attention IP option (RFC 2113)
102841 */
102842@@ -223,6 +227,9 @@ static int ip_local_deliver_finish(struct sk_buff *skb)
102843 if (!raw) {
102844 if (xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
102845 IP_INC_STATS_BH(net, IPSTATS_MIB_INUNKNOWNPROTOS);
102846+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
102847+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
102848+#endif
102849 icmp_send(skb, ICMP_DEST_UNREACH,
102850 ICMP_PROT_UNREACH, 0);
102851 }
102852diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c
102853index c43a1e2..73cbbe1 100644
102854--- a/net/ipv4/ip_output.c
102855+++ b/net/ipv4/ip_output.c
102856@@ -231,7 +231,7 @@ static int ip_finish_output_gso(struct sk_buff *skb)
102857 */
102858 features = netif_skb_features(skb);
102859 segs = skb_gso_segment(skb, features & ~NETIF_F_GSO_MASK);
102860- if (IS_ERR(segs)) {
102861+ if (IS_ERR_OR_NULL(segs)) {
102862 kfree_skb(skb);
102863 return -ENOMEM;
102864 }
102865diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
102866index 5cb830c..81a7a56 100644
102867--- a/net/ipv4/ip_sockglue.c
102868+++ b/net/ipv4/ip_sockglue.c
102869@@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102870 len = min_t(unsigned int, len, opt->optlen);
102871 if (put_user(len, optlen))
102872 return -EFAULT;
102873- if (copy_to_user(optval, opt->__data, len))
102874+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
102875+ copy_to_user(optval, opt->__data, len))
102876 return -EFAULT;
102877 return 0;
102878 }
102879@@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
102880 if (sk->sk_type != SOCK_STREAM)
102881 return -ENOPROTOOPT;
102882
102883- msg.msg_control = (__force void *) optval;
102884+ msg.msg_control = (__force_kernel void *) optval;
102885 msg.msg_controllen = len;
102886 msg.msg_flags = flags;
102887
102888diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
102889index e453cb7..3c8d952 100644
102890--- a/net/ipv4/ip_vti.c
102891+++ b/net/ipv4/ip_vti.c
102892@@ -45,7 +45,7 @@
102893 #include <net/net_namespace.h>
102894 #include <net/netns/generic.h>
102895
102896-static struct rtnl_link_ops vti_link_ops __read_mostly;
102897+static struct rtnl_link_ops vti_link_ops;
102898
102899 static int vti_net_id __read_mostly;
102900 static int vti_tunnel_init(struct net_device *dev);
102901@@ -519,7 +519,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
102902 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
102903 };
102904
102905-static struct rtnl_link_ops vti_link_ops __read_mostly = {
102906+static struct rtnl_link_ops vti_link_ops = {
102907 .kind = "vti",
102908 .maxtype = IFLA_VTI_MAX,
102909 .policy = vti_policy,
102910diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
102911index 5bbef4f..5bc4fb6 100644
102912--- a/net/ipv4/ipconfig.c
102913+++ b/net/ipv4/ipconfig.c
102914@@ -332,7 +332,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
102915
102916 mm_segment_t oldfs = get_fs();
102917 set_fs(get_ds());
102918- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102919+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102920 set_fs(oldfs);
102921 return res;
102922 }
102923@@ -343,7 +343,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
102924
102925 mm_segment_t oldfs = get_fs();
102926 set_fs(get_ds());
102927- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
102928+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
102929 set_fs(oldfs);
102930 return res;
102931 }
102932@@ -354,7 +354,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
102933
102934 mm_segment_t oldfs = get_fs();
102935 set_fs(get_ds());
102936- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
102937+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
102938 set_fs(oldfs);
102939 return res;
102940 }
102941diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
102942index 62eaa00..29b2dc2 100644
102943--- a/net/ipv4/ipip.c
102944+++ b/net/ipv4/ipip.c
102945@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
102946 static int ipip_net_id __read_mostly;
102947
102948 static int ipip_tunnel_init(struct net_device *dev);
102949-static struct rtnl_link_ops ipip_link_ops __read_mostly;
102950+static struct rtnl_link_ops ipip_link_ops;
102951
102952 static int ipip_err(struct sk_buff *skb, u32 info)
102953 {
102954@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
102955 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
102956 };
102957
102958-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
102959+static struct rtnl_link_ops ipip_link_ops = {
102960 .kind = "ipip",
102961 .maxtype = IFLA_IPTUN_MAX,
102962 .policy = ipip_policy,
102963diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
102964index f95b6f9..2ee2097 100644
102965--- a/net/ipv4/netfilter/arp_tables.c
102966+++ b/net/ipv4/netfilter/arp_tables.c
102967@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
102968 #endif
102969
102970 static int get_info(struct net *net, void __user *user,
102971- const int *len, int compat)
102972+ int len, int compat)
102973 {
102974 char name[XT_TABLE_MAXNAMELEN];
102975 struct xt_table *t;
102976 int ret;
102977
102978- if (*len != sizeof(struct arpt_getinfo)) {
102979- duprintf("length %u != %Zu\n", *len,
102980+ if (len != sizeof(struct arpt_getinfo)) {
102981+ duprintf("length %u != %Zu\n", len,
102982 sizeof(struct arpt_getinfo));
102983 return -EINVAL;
102984 }
102985@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
102986 info.size = private->size;
102987 strcpy(info.name, name);
102988
102989- if (copy_to_user(user, &info, *len) != 0)
102990+ if (copy_to_user(user, &info, len) != 0)
102991 ret = -EFAULT;
102992 else
102993 ret = 0;
102994@@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
102995
102996 switch (cmd) {
102997 case ARPT_SO_GET_INFO:
102998- ret = get_info(sock_net(sk), user, len, 1);
102999+ ret = get_info(sock_net(sk), user, *len, 1);
103000 break;
103001 case ARPT_SO_GET_ENTRIES:
103002 ret = compat_get_entries(sock_net(sk), user, len);
103003@@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
103004
103005 switch (cmd) {
103006 case ARPT_SO_GET_INFO:
103007- ret = get_info(sock_net(sk), user, len, 0);
103008+ ret = get_info(sock_net(sk), user, *len, 0);
103009 break;
103010
103011 case ARPT_SO_GET_ENTRIES:
103012diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
103013index 99e810f..3711b81 100644
103014--- a/net/ipv4/netfilter/ip_tables.c
103015+++ b/net/ipv4/netfilter/ip_tables.c
103016@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
103017 #endif
103018
103019 static int get_info(struct net *net, void __user *user,
103020- const int *len, int compat)
103021+ int len, int compat)
103022 {
103023 char name[XT_TABLE_MAXNAMELEN];
103024 struct xt_table *t;
103025 int ret;
103026
103027- if (*len != sizeof(struct ipt_getinfo)) {
103028- duprintf("length %u != %zu\n", *len,
103029+ if (len != sizeof(struct ipt_getinfo)) {
103030+ duprintf("length %u != %zu\n", len,
103031 sizeof(struct ipt_getinfo));
103032 return -EINVAL;
103033 }
103034@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
103035 info.size = private->size;
103036 strcpy(info.name, name);
103037
103038- if (copy_to_user(user, &info, *len) != 0)
103039+ if (copy_to_user(user, &info, len) != 0)
103040 ret = -EFAULT;
103041 else
103042 ret = 0;
103043@@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103044
103045 switch (cmd) {
103046 case IPT_SO_GET_INFO:
103047- ret = get_info(sock_net(sk), user, len, 1);
103048+ ret = get_info(sock_net(sk), user, *len, 1);
103049 break;
103050 case IPT_SO_GET_ENTRIES:
103051 ret = compat_get_entries(sock_net(sk), user, len);
103052@@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
103053
103054 switch (cmd) {
103055 case IPT_SO_GET_INFO:
103056- ret = get_info(sock_net(sk), user, len, 0);
103057+ ret = get_info(sock_net(sk), user, *len, 0);
103058 break;
103059
103060 case IPT_SO_GET_ENTRIES:
103061diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
103062index 2510c02..cfb34fa 100644
103063--- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
103064+++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
103065@@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
103066 spin_lock_init(&cn->lock);
103067
103068 #ifdef CONFIG_PROC_FS
103069- cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
103070+ cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
103071 if (!cn->procdir) {
103072 pr_err("Unable to proc dir entry\n");
103073 return -ENOMEM;
103074diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
103075index a3c59a0..ec620a50 100644
103076--- a/net/ipv4/ping.c
103077+++ b/net/ipv4/ping.c
103078@@ -59,7 +59,7 @@ struct ping_table {
103079 };
103080
103081 static struct ping_table ping_table;
103082-struct pingv6_ops pingv6_ops;
103083+struct pingv6_ops *pingv6_ops;
103084 EXPORT_SYMBOL_GPL(pingv6_ops);
103085
103086 static u16 ping_port_rover;
103087@@ -348,7 +348,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
103088 return -ENODEV;
103089 }
103090 }
103091- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
103092+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
103093 scoped);
103094 rcu_read_unlock();
103095
103096@@ -556,7 +556,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
103097 }
103098 #if IS_ENABLED(CONFIG_IPV6)
103099 } else if (skb->protocol == htons(ETH_P_IPV6)) {
103100- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
103101+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
103102 #endif
103103 }
103104
103105@@ -574,7 +574,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
103106 info, (u8 *)icmph);
103107 #if IS_ENABLED(CONFIG_IPV6)
103108 } else if (family == AF_INET6) {
103109- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
103110+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
103111 info, (u8 *)icmph);
103112 #endif
103113 }
103114@@ -858,7 +858,7 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103115 return ip_recv_error(sk, msg, len, addr_len);
103116 #if IS_ENABLED(CONFIG_IPV6)
103117 } else if (family == AF_INET6) {
103118- return pingv6_ops.ipv6_recv_error(sk, msg, len,
103119+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
103120 addr_len);
103121 #endif
103122 }
103123@@ -916,10 +916,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103124 }
103125
103126 if (inet6_sk(sk)->rxopt.all)
103127- pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
103128+ pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
103129 if (skb->protocol == htons(ETH_P_IPV6) &&
103130 inet6_sk(sk)->rxopt.all)
103131- pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
103132+ pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
103133 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
103134 ip_cmsg_recv(msg, skb);
103135 #endif
103136@@ -1111,7 +1111,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
103137 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103138 0, sock_i_ino(sp),
103139 atomic_read(&sp->sk_refcnt), sp,
103140- atomic_read(&sp->sk_drops));
103141+ atomic_read_unchecked(&sp->sk_drops));
103142 }
103143
103144 static int ping_v4_seq_show(struct seq_file *seq, void *v)
103145diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
103146index 739db31..74f0210 100644
103147--- a/net/ipv4/raw.c
103148+++ b/net/ipv4/raw.c
103149@@ -314,7 +314,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
103150 int raw_rcv(struct sock *sk, struct sk_buff *skb)
103151 {
103152 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
103153- atomic_inc(&sk->sk_drops);
103154+ atomic_inc_unchecked(&sk->sk_drops);
103155 kfree_skb(skb);
103156 return NET_RX_DROP;
103157 }
103158@@ -755,16 +755,20 @@ static int raw_init(struct sock *sk)
103159
103160 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
103161 {
103162+ struct icmp_filter filter;
103163+
103164 if (optlen > sizeof(struct icmp_filter))
103165 optlen = sizeof(struct icmp_filter);
103166- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
103167+ if (copy_from_user(&filter, optval, optlen))
103168 return -EFAULT;
103169+ raw_sk(sk)->filter = filter;
103170 return 0;
103171 }
103172
103173 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
103174 {
103175 int len, ret = -EFAULT;
103176+ struct icmp_filter filter;
103177
103178 if (get_user(len, optlen))
103179 goto out;
103180@@ -774,8 +778,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
103181 if (len > sizeof(struct icmp_filter))
103182 len = sizeof(struct icmp_filter);
103183 ret = -EFAULT;
103184- if (put_user(len, optlen) ||
103185- copy_to_user(optval, &raw_sk(sk)->filter, len))
103186+ filter = raw_sk(sk)->filter;
103187+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
103188 goto out;
103189 ret = 0;
103190 out: return ret;
103191@@ -1004,7 +1008,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
103192 0, 0L, 0,
103193 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
103194 0, sock_i_ino(sp),
103195- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
103196+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
103197 }
103198
103199 static int raw_seq_show(struct seq_file *seq, void *v)
103200diff --git a/net/ipv4/route.c b/net/ipv4/route.c
103201index 29836f8..bd1e2ba 100644
103202--- a/net/ipv4/route.c
103203+++ b/net/ipv4/route.c
103204@@ -228,7 +228,7 @@ static const struct seq_operations rt_cache_seq_ops = {
103205
103206 static int rt_cache_seq_open(struct inode *inode, struct file *file)
103207 {
103208- return seq_open(file, &rt_cache_seq_ops);
103209+ return seq_open_restrict(file, &rt_cache_seq_ops);
103210 }
103211
103212 static const struct file_operations rt_cache_seq_fops = {
103213@@ -319,7 +319,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
103214
103215 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
103216 {
103217- return seq_open(file, &rt_cpu_seq_ops);
103218+ return seq_open_restrict(file, &rt_cpu_seq_ops);
103219 }
103220
103221 static const struct file_operations rt_cpu_seq_fops = {
103222@@ -357,7 +357,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
103223
103224 static int rt_acct_proc_open(struct inode *inode, struct file *file)
103225 {
103226- return single_open(file, rt_acct_proc_show, NULL);
103227+ return single_open_restrict(file, rt_acct_proc_show, NULL);
103228 }
103229
103230 static const struct file_operations rt_acct_proc_fops = {
103231@@ -459,11 +459,11 @@ static struct neighbour *ipv4_neigh_lookup(const struct dst_entry *dst,
103232
103233 #define IP_IDENTS_SZ 2048u
103234 struct ip_ident_bucket {
103235- atomic_t id;
103236+ atomic_unchecked_t id;
103237 u32 stamp32;
103238 };
103239
103240-static struct ip_ident_bucket *ip_idents __read_mostly;
103241+static struct ip_ident_bucket ip_idents[IP_IDENTS_SZ] __read_mostly;
103242
103243 /* In order to protect privacy, we add a perturbation to identifiers
103244 * if one generator is seldom used. This makes hard for an attacker
103245@@ -479,7 +479,7 @@ u32 ip_idents_reserve(u32 hash, int segs)
103246 if (old != now && cmpxchg(&bucket->stamp32, old, now) == old)
103247 delta = prandom_u32_max(now - old);
103248
103249- return atomic_add_return(segs + delta, &bucket->id) - segs;
103250+ return atomic_add_return_unchecked(segs + delta, &bucket->id) - segs;
103251 }
103252 EXPORT_SYMBOL(ip_idents_reserve);
103253
103254@@ -2624,34 +2624,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
103255 .maxlen = sizeof(int),
103256 .mode = 0200,
103257 .proc_handler = ipv4_sysctl_rtcache_flush,
103258+ .extra1 = &init_net,
103259 },
103260 { },
103261 };
103262
103263 static __net_init int sysctl_route_net_init(struct net *net)
103264 {
103265- struct ctl_table *tbl;
103266+ ctl_table_no_const *tbl = NULL;
103267
103268- tbl = ipv4_route_flush_table;
103269 if (!net_eq(net, &init_net)) {
103270- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
103271+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
103272 if (tbl == NULL)
103273 goto err_dup;
103274
103275 /* Don't export sysctls to unprivileged users */
103276 if (net->user_ns != &init_user_ns)
103277 tbl[0].procname = NULL;
103278- }
103279- tbl[0].extra1 = net;
103280+ tbl[0].extra1 = net;
103281+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
103282+ } else
103283+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
103284
103285- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
103286 if (net->ipv4.route_hdr == NULL)
103287 goto err_reg;
103288 return 0;
103289
103290 err_reg:
103291- if (tbl != ipv4_route_flush_table)
103292- kfree(tbl);
103293+ kfree(tbl);
103294 err_dup:
103295 return -ENOMEM;
103296 }
103297@@ -2674,8 +2674,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
103298
103299 static __net_init int rt_genid_init(struct net *net)
103300 {
103301- atomic_set(&net->ipv4.rt_genid, 0);
103302- atomic_set(&net->fnhe_genid, 0);
103303+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
103304+ atomic_set_unchecked(&net->fnhe_genid, 0);
103305 get_random_bytes(&net->ipv4.dev_addr_genid,
103306 sizeof(net->ipv4.dev_addr_genid));
103307 return 0;
103308@@ -2718,11 +2718,7 @@ int __init ip_rt_init(void)
103309 {
103310 int rc = 0;
103311
103312- ip_idents = kmalloc(IP_IDENTS_SZ * sizeof(*ip_idents), GFP_KERNEL);
103313- if (!ip_idents)
103314- panic("IP: failed to allocate ip_idents\n");
103315-
103316- prandom_bytes(ip_idents, IP_IDENTS_SZ * sizeof(*ip_idents));
103317+ prandom_bytes(ip_idents, sizeof(ip_idents));
103318
103319 #ifdef CONFIG_IP_ROUTE_CLASSID
103320 ip_rt_acct = __alloc_percpu(256 * sizeof(struct ip_rt_acct), __alignof__(struct ip_rt_acct));
103321diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
103322index 79a007c..5023029 100644
103323--- a/net/ipv4/sysctl_net_ipv4.c
103324+++ b/net/ipv4/sysctl_net_ipv4.c
103325@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
103326 container_of(table->data, struct net, ipv4.ip_local_ports.range);
103327 int ret;
103328 int range[2];
103329- struct ctl_table tmp = {
103330+ ctl_table_no_const tmp = {
103331 .data = &range,
103332 .maxlen = sizeof(range),
103333 .mode = table->mode,
103334@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
103335 int ret;
103336 gid_t urange[2];
103337 kgid_t low, high;
103338- struct ctl_table tmp = {
103339+ ctl_table_no_const tmp = {
103340 .data = &urange,
103341 .maxlen = sizeof(urange),
103342 .mode = table->mode,
103343@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
103344 void __user *buffer, size_t *lenp, loff_t *ppos)
103345 {
103346 char val[TCP_CA_NAME_MAX];
103347- struct ctl_table tbl = {
103348+ ctl_table_no_const tbl = {
103349 .data = val,
103350 .maxlen = TCP_CA_NAME_MAX,
103351 };
103352@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
103353 void __user *buffer, size_t *lenp,
103354 loff_t *ppos)
103355 {
103356- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
103357+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
103358 int ret;
103359
103360 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
103361@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
103362 void __user *buffer, size_t *lenp,
103363 loff_t *ppos)
103364 {
103365- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
103366+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
103367 int ret;
103368
103369 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
103370@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
103371 void __user *buffer, size_t *lenp,
103372 loff_t *ppos)
103373 {
103374- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
103375+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
103376 struct tcp_fastopen_context *ctxt;
103377 int ret;
103378 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
103379@@ -857,13 +857,12 @@ static struct ctl_table ipv4_net_table[] = {
103380
103381 static __net_init int ipv4_sysctl_init_net(struct net *net)
103382 {
103383- struct ctl_table *table;
103384+ ctl_table_no_const *table = NULL;
103385
103386- table = ipv4_net_table;
103387 if (!net_eq(net, &init_net)) {
103388 int i;
103389
103390- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
103391+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
103392 if (table == NULL)
103393 goto err_alloc;
103394
103395@@ -872,7 +871,10 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
103396 table[i].data += (void *)net - (void *)&init_net;
103397 }
103398
103399- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103400+ if (!net_eq(net, &init_net))
103401+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
103402+ else
103403+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
103404 if (net->ipv4.ipv4_hdr == NULL)
103405 goto err_reg;
103406
103407diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
103408index a906e02..f3b6a0f 100644
103409--- a/net/ipv4/tcp_input.c
103410+++ b/net/ipv4/tcp_input.c
103411@@ -755,7 +755,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
103412 * without any lock. We want to make sure compiler wont store
103413 * intermediate values in this location.
103414 */
103415- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
103416+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
103417 sk->sk_max_pacing_rate);
103418 }
103419
103420@@ -4488,7 +4488,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
103421 * simplifies code)
103422 */
103423 static void
103424-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103425+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
103426 struct sk_buff *head, struct sk_buff *tail,
103427 u32 start, u32 end)
103428 {
103429@@ -5546,6 +5546,7 @@ discard:
103430 tcp_paws_reject(&tp->rx_opt, 0))
103431 goto discard_and_undo;
103432
103433+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
103434 if (th->syn) {
103435 /* We see SYN without ACK. It is attempt of
103436 * simultaneous connect with crossed SYNs.
103437@@ -5596,6 +5597,7 @@ discard:
103438 goto discard;
103439 #endif
103440 }
103441+#endif
103442 /* "fifth, if neither of the SYN or RST bits is set then
103443 * drop the segment and return."
103444 */
103445@@ -5642,7 +5644,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
103446 goto discard;
103447
103448 if (th->syn) {
103449- if (th->fin)
103450+ if (th->fin || th->urg || th->psh)
103451 goto discard;
103452 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
103453 return 1;
103454diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
103455index 3f49eae..bde687a 100644
103456--- a/net/ipv4/tcp_ipv4.c
103457+++ b/net/ipv4/tcp_ipv4.c
103458@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
103459 EXPORT_SYMBOL(sysctl_tcp_low_latency);
103460
103461
103462+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103463+extern int grsec_enable_blackhole;
103464+#endif
103465+
103466 #ifdef CONFIG_TCP_MD5SIG
103467 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
103468 __be32 daddr, __be32 saddr, const struct tcphdr *th);
103469@@ -1487,6 +1491,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
103470 return 0;
103471
103472 reset:
103473+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103474+ if (!grsec_enable_blackhole)
103475+#endif
103476 tcp_v4_send_reset(rsk, skb);
103477 discard:
103478 kfree_skb(skb);
103479@@ -1633,12 +1640,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
103480 TCP_SKB_CB(skb)->sacked = 0;
103481
103482 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
103483- if (!sk)
103484+ if (!sk) {
103485+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103486+ ret = 1;
103487+#endif
103488 goto no_tcp_socket;
103489-
103490+ }
103491 process:
103492- if (sk->sk_state == TCP_TIME_WAIT)
103493+ if (sk->sk_state == TCP_TIME_WAIT) {
103494+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103495+ ret = 2;
103496+#endif
103497 goto do_time_wait;
103498+ }
103499
103500 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
103501 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
103502@@ -1704,6 +1718,10 @@ csum_error:
103503 bad_packet:
103504 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
103505 } else {
103506+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103507+ if (!grsec_enable_blackhole || (ret == 1 &&
103508+ (skb->dev->flags & IFF_LOOPBACK)))
103509+#endif
103510 tcp_v4_send_reset(NULL, skb);
103511 }
103512
103513diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
103514index 1649988..6251843 100644
103515--- a/net/ipv4/tcp_minisocks.c
103516+++ b/net/ipv4/tcp_minisocks.c
103517@@ -27,6 +27,10 @@
103518 #include <net/inet_common.h>
103519 #include <net/xfrm.h>
103520
103521+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103522+extern int grsec_enable_blackhole;
103523+#endif
103524+
103525 int sysctl_tcp_syncookies __read_mostly = 1;
103526 EXPORT_SYMBOL(sysctl_tcp_syncookies);
103527
103528@@ -740,7 +744,10 @@ embryonic_reset:
103529 * avoid becoming vulnerable to outside attack aiming at
103530 * resetting legit local connections.
103531 */
103532- req->rsk_ops->send_reset(sk, skb);
103533+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103534+ if (!grsec_enable_blackhole)
103535+#endif
103536+ req->rsk_ops->send_reset(sk, skb);
103537 } else if (fastopen) { /* received a valid RST pkt */
103538 reqsk_fastopen_remove(sk, req, true);
103539 tcp_reset(sk);
103540diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
103541index 3b66610..bfbe23a 100644
103542--- a/net/ipv4/tcp_probe.c
103543+++ b/net/ipv4/tcp_probe.c
103544@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
103545 if (cnt + width >= len)
103546 break;
103547
103548- if (copy_to_user(buf + cnt, tbuf, width))
103549+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
103550 return -EFAULT;
103551 cnt += width;
103552 }
103553diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
103554index df90cd1..9ab2c9b 100644
103555--- a/net/ipv4/tcp_timer.c
103556+++ b/net/ipv4/tcp_timer.c
103557@@ -22,6 +22,10 @@
103558 #include <linux/gfp.h>
103559 #include <net/tcp.h>
103560
103561+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103562+extern int grsec_lastack_retries;
103563+#endif
103564+
103565 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
103566 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
103567 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
103568@@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
103569 }
103570 }
103571
103572+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103573+ if ((sk->sk_state == TCP_LAST_ACK) &&
103574+ (grsec_lastack_retries > 0) &&
103575+ (grsec_lastack_retries < retry_until))
103576+ retry_until = grsec_lastack_retries;
103577+#endif
103578+
103579 if (retransmits_timed_out(sk, retry_until,
103580 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
103581 /* Has it gone just too far? */
103582diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
103583index f57c0e4..cf24bd0 100644
103584--- a/net/ipv4/udp.c
103585+++ b/net/ipv4/udp.c
103586@@ -87,6 +87,7 @@
103587 #include <linux/types.h>
103588 #include <linux/fcntl.h>
103589 #include <linux/module.h>
103590+#include <linux/security.h>
103591 #include <linux/socket.h>
103592 #include <linux/sockios.h>
103593 #include <linux/igmp.h>
103594@@ -113,6 +114,10 @@
103595 #include <net/busy_poll.h>
103596 #include "udp_impl.h"
103597
103598+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103599+extern int grsec_enable_blackhole;
103600+#endif
103601+
103602 struct udp_table udp_table __read_mostly;
103603 EXPORT_SYMBOL(udp_table);
103604
103605@@ -594,6 +599,9 @@ static inline bool __udp_is_mcast_sock(struct net *net, struct sock *sk,
103606 return true;
103607 }
103608
103609+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
103610+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
103611+
103612 /*
103613 * This routine is called by the ICMP module when it gets some
103614 * sort of error condition. If err < 0 then the socket should
103615@@ -931,9 +939,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
103616 dport = usin->sin_port;
103617 if (dport == 0)
103618 return -EINVAL;
103619+
103620+ err = gr_search_udp_sendmsg(sk, usin);
103621+ if (err)
103622+ return err;
103623 } else {
103624 if (sk->sk_state != TCP_ESTABLISHED)
103625 return -EDESTADDRREQ;
103626+
103627+ err = gr_search_udp_sendmsg(sk, NULL);
103628+ if (err)
103629+ return err;
103630+
103631 daddr = inet->inet_daddr;
103632 dport = inet->inet_dport;
103633 /* Open fast path for connected socket.
103634@@ -1181,7 +1198,7 @@ static unsigned int first_packet_length(struct sock *sk)
103635 IS_UDPLITE(sk));
103636 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103637 IS_UDPLITE(sk));
103638- atomic_inc(&sk->sk_drops);
103639+ atomic_inc_unchecked(&sk->sk_drops);
103640 __skb_unlink(skb, rcvq);
103641 __skb_queue_tail(&list_kill, skb);
103642 }
103643@@ -1261,6 +1278,10 @@ try_again:
103644 if (!skb)
103645 goto out;
103646
103647+ err = gr_search_udp_recvmsg(sk, skb);
103648+ if (err)
103649+ goto out_free;
103650+
103651 ulen = skb->len - sizeof(struct udphdr);
103652 copied = len;
103653 if (copied > ulen)
103654@@ -1294,7 +1315,7 @@ try_again:
103655 if (unlikely(err)) {
103656 trace_kfree_skb(skb, udp_recvmsg);
103657 if (!peeked) {
103658- atomic_inc(&sk->sk_drops);
103659+ atomic_inc_unchecked(&sk->sk_drops);
103660 UDP_INC_STATS_USER(sock_net(sk),
103661 UDP_MIB_INERRORS, is_udplite);
103662 }
103663@@ -1591,7 +1612,7 @@ csum_error:
103664 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
103665 drop:
103666 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
103667- atomic_inc(&sk->sk_drops);
103668+ atomic_inc_unchecked(&sk->sk_drops);
103669 kfree_skb(skb);
103670 return -1;
103671 }
103672@@ -1610,7 +1631,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
103673 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
103674
103675 if (!skb1) {
103676- atomic_inc(&sk->sk_drops);
103677+ atomic_inc_unchecked(&sk->sk_drops);
103678 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
103679 IS_UDPLITE(sk));
103680 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
103681@@ -1807,6 +1828,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
103682 goto csum_error;
103683
103684 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
103685+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
103686+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
103687+#endif
103688 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
103689
103690 /*
103691@@ -2393,7 +2417,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
103692 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
103693 0, sock_i_ino(sp),
103694 atomic_read(&sp->sk_refcnt), sp,
103695- atomic_read(&sp->sk_drops));
103696+ atomic_read_unchecked(&sp->sk_drops));
103697 }
103698
103699 int udp4_seq_show(struct seq_file *seq, void *v)
103700diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
103701index 6156f68..d6ab46d 100644
103702--- a/net/ipv4/xfrm4_policy.c
103703+++ b/net/ipv4/xfrm4_policy.c
103704@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
103705 fl4->flowi4_tos = iph->tos;
103706 }
103707
103708-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
103709+static int xfrm4_garbage_collect(struct dst_ops *ops)
103710 {
103711 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
103712
103713- xfrm4_policy_afinfo.garbage_collect(net);
103714+ xfrm_garbage_collect_deferred(net);
103715 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
103716 }
103717
103718@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
103719
103720 static int __net_init xfrm4_net_init(struct net *net)
103721 {
103722- struct ctl_table *table;
103723+ ctl_table_no_const *table = NULL;
103724 struct ctl_table_header *hdr;
103725
103726- table = xfrm4_policy_table;
103727 if (!net_eq(net, &init_net)) {
103728- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103729+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
103730 if (!table)
103731 goto err_alloc;
103732
103733 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
103734- }
103735-
103736- hdr = register_net_sysctl(net, "net/ipv4", table);
103737+ hdr = register_net_sysctl(net, "net/ipv4", table);
103738+ } else
103739+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
103740 if (!hdr)
103741 goto err_reg;
103742
103743@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
103744 return 0;
103745
103746 err_reg:
103747- if (!net_eq(net, &init_net))
103748- kfree(table);
103749+ kfree(table);
103750 err_alloc:
103751 return -ENOMEM;
103752 }
103753diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
103754index 3e118df..27b16cf 100644
103755--- a/net/ipv6/addrconf.c
103756+++ b/net/ipv6/addrconf.c
103757@@ -604,7 +604,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
103758 idx = 0;
103759 head = &net->dev_index_head[h];
103760 rcu_read_lock();
103761- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
103762+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
103763 net->dev_base_seq;
103764 hlist_for_each_entry_rcu(dev, head, index_hlist) {
103765 if (idx < s_idx)
103766@@ -2396,7 +2396,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
103767 p.iph.ihl = 5;
103768 p.iph.protocol = IPPROTO_IPV6;
103769 p.iph.ttl = 64;
103770- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
103771+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
103772
103773 if (ops->ndo_do_ioctl) {
103774 mm_segment_t oldfs = get_fs();
103775@@ -3531,16 +3531,23 @@ static const struct file_operations if6_fops = {
103776 .release = seq_release_net,
103777 };
103778
103779+extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
103780+extern void unregister_ipv6_seq_ops_addr(void);
103781+
103782 static int __net_init if6_proc_net_init(struct net *net)
103783 {
103784- if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
103785+ register_ipv6_seq_ops_addr(&if6_seq_ops);
103786+ if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
103787+ unregister_ipv6_seq_ops_addr();
103788 return -ENOMEM;
103789+ }
103790 return 0;
103791 }
103792
103793 static void __net_exit if6_proc_net_exit(struct net *net)
103794 {
103795 remove_proc_entry("if_inet6", net->proc_net);
103796+ unregister_ipv6_seq_ops_addr();
103797 }
103798
103799 static struct pernet_operations if6_proc_net_ops = {
103800@@ -4156,7 +4163,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
103801 s_ip_idx = ip_idx = cb->args[2];
103802
103803 rcu_read_lock();
103804- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103805+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
103806 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
103807 idx = 0;
103808 head = &net->dev_index_head[h];
103809@@ -4784,7 +4791,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103810 rt_genid_bump_ipv6(net);
103811 break;
103812 }
103813- atomic_inc(&net->ipv6.dev_addr_genid);
103814+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
103815 }
103816
103817 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
103818@@ -4804,7 +4811,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
103819 int *valp = ctl->data;
103820 int val = *valp;
103821 loff_t pos = *ppos;
103822- struct ctl_table lctl;
103823+ ctl_table_no_const lctl;
103824 int ret;
103825
103826 /*
103827@@ -4889,7 +4896,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
103828 int *valp = ctl->data;
103829 int val = *valp;
103830 loff_t pos = *ppos;
103831- struct ctl_table lctl;
103832+ ctl_table_no_const lctl;
103833 int ret;
103834
103835 /*
103836diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
103837index 2daa3a1..341066c 100644
103838--- a/net/ipv6/af_inet6.c
103839+++ b/net/ipv6/af_inet6.c
103840@@ -766,7 +766,7 @@ static int __net_init inet6_net_init(struct net *net)
103841 net->ipv6.sysctl.icmpv6_time = 1*HZ;
103842 net->ipv6.sysctl.flowlabel_consistency = 1;
103843 net->ipv6.sysctl.auto_flowlabels = 0;
103844- atomic_set(&net->ipv6.rt_genid, 0);
103845+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
103846
103847 err = ipv6_init_mibs(net);
103848 if (err)
103849diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
103850index 2753319..b7e625c 100644
103851--- a/net/ipv6/datagram.c
103852+++ b/net/ipv6/datagram.c
103853@@ -939,5 +939,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
103854 0,
103855 sock_i_ino(sp),
103856 atomic_read(&sp->sk_refcnt), sp,
103857- atomic_read(&sp->sk_drops));
103858+ atomic_read_unchecked(&sp->sk_drops));
103859 }
103860diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
103861index 06ba3e5..5c08d38 100644
103862--- a/net/ipv6/icmp.c
103863+++ b/net/ipv6/icmp.c
103864@@ -993,7 +993,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
103865
103866 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
103867 {
103868- struct ctl_table *table;
103869+ ctl_table_no_const *table;
103870
103871 table = kmemdup(ipv6_icmp_table_template,
103872 sizeof(ipv6_icmp_table_template),
103873diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
103874index 97299d7..c8e6894 100644
103875--- a/net/ipv6/ip6_gre.c
103876+++ b/net/ipv6/ip6_gre.c
103877@@ -71,8 +71,8 @@ struct ip6gre_net {
103878 struct net_device *fb_tunnel_dev;
103879 };
103880
103881-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
103882-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly;
103883+static struct rtnl_link_ops ip6gre_link_ops;
103884+static struct rtnl_link_ops ip6gre_tap_ops;
103885 static int ip6gre_tunnel_init(struct net_device *dev);
103886 static void ip6gre_tunnel_setup(struct net_device *dev);
103887 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
103888@@ -1286,7 +1286,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
103889 }
103890
103891
103892-static struct inet6_protocol ip6gre_protocol __read_mostly = {
103893+static struct inet6_protocol ip6gre_protocol = {
103894 .handler = ip6gre_rcv,
103895 .err_handler = ip6gre_err,
103896 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
103897@@ -1645,7 +1645,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
103898 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
103899 };
103900
103901-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103902+static struct rtnl_link_ops ip6gre_link_ops = {
103903 .kind = "ip6gre",
103904 .maxtype = IFLA_GRE_MAX,
103905 .policy = ip6gre_policy,
103906@@ -1659,7 +1659,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
103907 .fill_info = ip6gre_fill_info,
103908 };
103909
103910-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
103911+static struct rtnl_link_ops ip6gre_tap_ops = {
103912 .kind = "ip6gretap",
103913 .maxtype = IFLA_GRE_MAX,
103914 .policy = ip6gre_policy,
103915diff --git a/net/ipv6/ip6_offload.c b/net/ipv6/ip6_offload.c
103916index 65eda2a..620a102 100644
103917--- a/net/ipv6/ip6_offload.c
103918+++ b/net/ipv6/ip6_offload.c
103919@@ -46,6 +46,7 @@ static int ipv6_gso_pull_exthdrs(struct sk_buff *skb, int proto)
103920 if (unlikely(!pskb_may_pull(skb, len)))
103921 break;
103922
103923+ opth = (void *)skb->data;
103924 proto = opth->nexthdr;
103925 __skb_pull(skb, len);
103926 }
103927diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
103928index 69a84b4..881c319 100644
103929--- a/net/ipv6/ip6_tunnel.c
103930+++ b/net/ipv6/ip6_tunnel.c
103931@@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103932
103933 static int ip6_tnl_dev_init(struct net_device *dev);
103934 static void ip6_tnl_dev_setup(struct net_device *dev);
103935-static struct rtnl_link_ops ip6_link_ops __read_mostly;
103936+static struct rtnl_link_ops ip6_link_ops;
103937
103938 static int ip6_tnl_net_id __read_mostly;
103939 struct ip6_tnl_net {
103940@@ -1714,7 +1714,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
103941 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
103942 };
103943
103944-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
103945+static struct rtnl_link_ops ip6_link_ops = {
103946 .kind = "ip6tnl",
103947 .maxtype = IFLA_IPTUN_MAX,
103948 .policy = ip6_tnl_policy,
103949diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
103950index 5833a22..6631377 100644
103951--- a/net/ipv6/ip6_vti.c
103952+++ b/net/ipv6/ip6_vti.c
103953@@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
103954
103955 static int vti6_dev_init(struct net_device *dev);
103956 static void vti6_dev_setup(struct net_device *dev);
103957-static struct rtnl_link_ops vti6_link_ops __read_mostly;
103958+static struct rtnl_link_ops vti6_link_ops;
103959
103960 static int vti6_net_id __read_mostly;
103961 struct vti6_net {
103962@@ -981,7 +981,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
103963 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
103964 };
103965
103966-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
103967+static struct rtnl_link_ops vti6_link_ops = {
103968 .kind = "vti6",
103969 .maxtype = IFLA_VTI_MAX,
103970 .policy = vti6_policy,
103971diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
103972index 0c28998..d0a2ecd 100644
103973--- a/net/ipv6/ipv6_sockglue.c
103974+++ b/net/ipv6/ipv6_sockglue.c
103975@@ -995,7 +995,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
103976 if (sk->sk_type != SOCK_STREAM)
103977 return -ENOPROTOOPT;
103978
103979- msg.msg_control = optval;
103980+ msg.msg_control = (void __force_kernel *)optval;
103981 msg.msg_controllen = len;
103982 msg.msg_flags = flags;
103983
103984diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
103985index e080fbb..412b3cf 100644
103986--- a/net/ipv6/netfilter/ip6_tables.c
103987+++ b/net/ipv6/netfilter/ip6_tables.c
103988@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
103989 #endif
103990
103991 static int get_info(struct net *net, void __user *user,
103992- const int *len, int compat)
103993+ int len, int compat)
103994 {
103995 char name[XT_TABLE_MAXNAMELEN];
103996 struct xt_table *t;
103997 int ret;
103998
103999- if (*len != sizeof(struct ip6t_getinfo)) {
104000- duprintf("length %u != %zu\n", *len,
104001+ if (len != sizeof(struct ip6t_getinfo)) {
104002+ duprintf("length %u != %zu\n", len,
104003 sizeof(struct ip6t_getinfo));
104004 return -EINVAL;
104005 }
104006@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
104007 info.size = private->size;
104008 strcpy(info.name, name);
104009
104010- if (copy_to_user(user, &info, *len) != 0)
104011+ if (copy_to_user(user, &info, len) != 0)
104012 ret = -EFAULT;
104013 else
104014 ret = 0;
104015@@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
104016
104017 switch (cmd) {
104018 case IP6T_SO_GET_INFO:
104019- ret = get_info(sock_net(sk), user, len, 1);
104020+ ret = get_info(sock_net(sk), user, *len, 1);
104021 break;
104022 case IP6T_SO_GET_ENTRIES:
104023 ret = compat_get_entries(sock_net(sk), user, len);
104024@@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
104025
104026 switch (cmd) {
104027 case IP6T_SO_GET_INFO:
104028- ret = get_info(sock_net(sk), user, len, 0);
104029+ ret = get_info(sock_net(sk), user, *len, 0);
104030 break;
104031
104032 case IP6T_SO_GET_ENTRIES:
104033diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
104034index 6f187c8..34b367f 100644
104035--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
104036+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
104037@@ -96,12 +96,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
104038
104039 static int nf_ct_frag6_sysctl_register(struct net *net)
104040 {
104041- struct ctl_table *table;
104042+ ctl_table_no_const *table = NULL;
104043 struct ctl_table_header *hdr;
104044
104045- table = nf_ct_frag6_sysctl_table;
104046 if (!net_eq(net, &init_net)) {
104047- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
104048+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
104049 GFP_KERNEL);
104050 if (table == NULL)
104051 goto err_alloc;
104052@@ -112,9 +111,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
104053 table[2].data = &net->nf_frag.frags.high_thresh;
104054 table[2].extra1 = &net->nf_frag.frags.low_thresh;
104055 table[2].extra2 = &init_net.nf_frag.frags.high_thresh;
104056- }
104057-
104058- hdr = register_net_sysctl(net, "net/netfilter", table);
104059+ hdr = register_net_sysctl(net, "net/netfilter", table);
104060+ } else
104061+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
104062 if (hdr == NULL)
104063 goto err_reg;
104064
104065@@ -122,8 +121,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
104066 return 0;
104067
104068 err_reg:
104069- if (!net_eq(net, &init_net))
104070- kfree(table);
104071+ kfree(table);
104072 err_alloc:
104073 return -ENOMEM;
104074 }
104075diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
104076index 5b7a1ed..d9da205 100644
104077--- a/net/ipv6/ping.c
104078+++ b/net/ipv6/ping.c
104079@@ -240,6 +240,24 @@ static struct pernet_operations ping_v6_net_ops = {
104080 };
104081 #endif
104082
104083+static struct pingv6_ops real_pingv6_ops = {
104084+ .ipv6_recv_error = ipv6_recv_error,
104085+ .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
104086+ .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
104087+ .icmpv6_err_convert = icmpv6_err_convert,
104088+ .ipv6_icmp_error = ipv6_icmp_error,
104089+ .ipv6_chk_addr = ipv6_chk_addr,
104090+};
104091+
104092+static struct pingv6_ops dummy_pingv6_ops = {
104093+ .ipv6_recv_error = dummy_ipv6_recv_error,
104094+ .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
104095+ .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
104096+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
104097+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
104098+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
104099+};
104100+
104101 int __init pingv6_init(void)
104102 {
104103 #ifdef CONFIG_PROC_FS
104104@@ -247,13 +265,7 @@ int __init pingv6_init(void)
104105 if (ret)
104106 return ret;
104107 #endif
104108- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
104109- pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
104110- pingv6_ops.ip6_datagram_recv_specific_ctl =
104111- ip6_datagram_recv_specific_ctl;
104112- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
104113- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
104114- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
104115+ pingv6_ops = &real_pingv6_ops;
104116 return inet6_register_protosw(&pingv6_protosw);
104117 }
104118
104119@@ -262,14 +274,9 @@ int __init pingv6_init(void)
104120 */
104121 void pingv6_exit(void)
104122 {
104123- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
104124- pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
104125- pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
104126- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
104127- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
104128- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
104129 #ifdef CONFIG_PROC_FS
104130 unregister_pernet_subsys(&ping_v6_net_ops);
104131 #endif
104132+ pingv6_ops = &dummy_pingv6_ops;
104133 inet6_unregister_protosw(&pingv6_protosw);
104134 }
104135diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
104136index 2d6f860..b0165f5 100644
104137--- a/net/ipv6/proc.c
104138+++ b/net/ipv6/proc.c
104139@@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
104140 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
104141 goto proc_snmp6_fail;
104142
104143- net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
104144+ net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
104145 if (!net->mib.proc_net_devsnmp6)
104146 goto proc_dev_snmp6_fail;
104147 return 0;
104148diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
104149index 39d4422..b0979547 100644
104150--- a/net/ipv6/raw.c
104151+++ b/net/ipv6/raw.c
104152@@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
104153 {
104154 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
104155 skb_checksum_complete(skb)) {
104156- atomic_inc(&sk->sk_drops);
104157+ atomic_inc_unchecked(&sk->sk_drops);
104158 kfree_skb(skb);
104159 return NET_RX_DROP;
104160 }
104161@@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
104162 struct raw6_sock *rp = raw6_sk(sk);
104163
104164 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
104165- atomic_inc(&sk->sk_drops);
104166+ atomic_inc_unchecked(&sk->sk_drops);
104167 kfree_skb(skb);
104168 return NET_RX_DROP;
104169 }
104170@@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
104171
104172 if (inet->hdrincl) {
104173 if (skb_checksum_complete(skb)) {
104174- atomic_inc(&sk->sk_drops);
104175+ atomic_inc_unchecked(&sk->sk_drops);
104176 kfree_skb(skb);
104177 return NET_RX_DROP;
104178 }
104179@@ -608,7 +608,7 @@ out:
104180 return err;
104181 }
104182
104183-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
104184+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
104185 struct flowi6 *fl6, struct dst_entry **dstp,
104186 unsigned int flags)
104187 {
104188@@ -914,12 +914,15 @@ do_confirm:
104189 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
104190 char __user *optval, int optlen)
104191 {
104192+ struct icmp6_filter filter;
104193+
104194 switch (optname) {
104195 case ICMPV6_FILTER:
104196 if (optlen > sizeof(struct icmp6_filter))
104197 optlen = sizeof(struct icmp6_filter);
104198- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
104199+ if (copy_from_user(&filter, optval, optlen))
104200 return -EFAULT;
104201+ raw6_sk(sk)->filter = filter;
104202 return 0;
104203 default:
104204 return -ENOPROTOOPT;
104205@@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
104206 char __user *optval, int __user *optlen)
104207 {
104208 int len;
104209+ struct icmp6_filter filter;
104210
104211 switch (optname) {
104212 case ICMPV6_FILTER:
104213@@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
104214 len = sizeof(struct icmp6_filter);
104215 if (put_user(len, optlen))
104216 return -EFAULT;
104217- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
104218+ filter = raw6_sk(sk)->filter;
104219+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
104220 return -EFAULT;
104221 return 0;
104222 default:
104223diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
104224index c6557d9..173e728 100644
104225--- a/net/ipv6/reassembly.c
104226+++ b/net/ipv6/reassembly.c
104227@@ -627,12 +627,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
104228
104229 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104230 {
104231- struct ctl_table *table;
104232+ ctl_table_no_const *table = NULL;
104233 struct ctl_table_header *hdr;
104234
104235- table = ip6_frags_ns_ctl_table;
104236 if (!net_eq(net, &init_net)) {
104237- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104238+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
104239 if (table == NULL)
104240 goto err_alloc;
104241
104242@@ -646,9 +645,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104243 /* Don't export sysctls to unprivileged users */
104244 if (net->user_ns != &init_user_ns)
104245 table[0].procname = NULL;
104246- }
104247+ hdr = register_net_sysctl(net, "net/ipv6", table);
104248+ } else
104249+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
104250
104251- hdr = register_net_sysctl(net, "net/ipv6", table);
104252 if (hdr == NULL)
104253 goto err_reg;
104254
104255@@ -656,8 +656,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
104256 return 0;
104257
104258 err_reg:
104259- if (!net_eq(net, &init_net))
104260- kfree(table);
104261+ kfree(table);
104262 err_alloc:
104263 return -ENOMEM;
104264 }
104265diff --git a/net/ipv6/route.c b/net/ipv6/route.c
104266index bafde82..af2c91f 100644
104267--- a/net/ipv6/route.c
104268+++ b/net/ipv6/route.c
104269@@ -2967,7 +2967,7 @@ struct ctl_table ipv6_route_table_template[] = {
104270
104271 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
104272 {
104273- struct ctl_table *table;
104274+ ctl_table_no_const *table;
104275
104276 table = kmemdup(ipv6_route_table_template,
104277 sizeof(ipv6_route_table_template),
104278diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
104279index 6163f85..0070823 100644
104280--- a/net/ipv6/sit.c
104281+++ b/net/ipv6/sit.c
104282@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
104283 static void ipip6_dev_free(struct net_device *dev);
104284 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
104285 __be32 *v4dst);
104286-static struct rtnl_link_ops sit_link_ops __read_mostly;
104287+static struct rtnl_link_ops sit_link_ops;
104288
104289 static int sit_net_id __read_mostly;
104290 struct sit_net {
104291@@ -485,11 +485,11 @@ static void ipip6_tunnel_uninit(struct net_device *dev)
104292 */
104293 static int ipip6_err_gen_icmpv6_unreach(struct sk_buff *skb)
104294 {
104295- const struct iphdr *iph = (const struct iphdr *) skb->data;
104296+ int ihl = ((const struct iphdr *)skb->data)->ihl*4;
104297 struct rt6_info *rt;
104298 struct sk_buff *skb2;
104299
104300- if (!pskb_may_pull(skb, iph->ihl * 4 + sizeof(struct ipv6hdr) + 8))
104301+ if (!pskb_may_pull(skb, ihl + sizeof(struct ipv6hdr) + 8))
104302 return 1;
104303
104304 skb2 = skb_clone(skb, GFP_ATOMIC);
104305@@ -498,7 +498,7 @@ static int ipip6_err_gen_icmpv6_unreach(struct sk_buff *skb)
104306 return 1;
104307
104308 skb_dst_drop(skb2);
104309- skb_pull(skb2, iph->ihl * 4);
104310+ skb_pull(skb2, ihl);
104311 skb_reset_network_header(skb2);
104312
104313 rt = rt6_lookup(dev_net(skb->dev), &ipv6_hdr(skb2)->saddr, NULL, 0, 0);
104314@@ -1662,7 +1662,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
104315 unregister_netdevice_queue(dev, head);
104316 }
104317
104318-static struct rtnl_link_ops sit_link_ops __read_mostly = {
104319+static struct rtnl_link_ops sit_link_ops = {
104320 .kind = "sit",
104321 .maxtype = IFLA_IPTUN_MAX,
104322 .policy = ipip6_policy,
104323diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
104324index 0c56c93..ece50df 100644
104325--- a/net/ipv6/sysctl_net_ipv6.c
104326+++ b/net/ipv6/sysctl_net_ipv6.c
104327@@ -68,7 +68,7 @@ static struct ctl_table ipv6_rotable[] = {
104328
104329 static int __net_init ipv6_sysctl_net_init(struct net *net)
104330 {
104331- struct ctl_table *ipv6_table;
104332+ ctl_table_no_const *ipv6_table;
104333 struct ctl_table *ipv6_route_table;
104334 struct ctl_table *ipv6_icmp_table;
104335 int err;
104336diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
104337index 264c0f2..b6512c6 100644
104338--- a/net/ipv6/tcp_ipv6.c
104339+++ b/net/ipv6/tcp_ipv6.c
104340@@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
104341 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
104342 }
104343
104344+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104345+extern int grsec_enable_blackhole;
104346+#endif
104347+
104348 static void tcp_v6_hash(struct sock *sk)
104349 {
104350 if (sk->sk_state != TCP_CLOSE) {
104351@@ -1333,6 +1337,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
104352 return 0;
104353
104354 reset:
104355+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104356+ if (!grsec_enable_blackhole)
104357+#endif
104358 tcp_v6_send_reset(sk, skb);
104359 discard:
104360 if (opt_skb)
104361@@ -1417,12 +1424,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
104362 TCP_SKB_CB(skb)->sacked = 0;
104363
104364 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
104365- if (!sk)
104366+ if (!sk) {
104367+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104368+ ret = 1;
104369+#endif
104370 goto no_tcp_socket;
104371+ }
104372
104373 process:
104374- if (sk->sk_state == TCP_TIME_WAIT)
104375+ if (sk->sk_state == TCP_TIME_WAIT) {
104376+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104377+ ret = 2;
104378+#endif
104379 goto do_time_wait;
104380+ }
104381
104382 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
104383 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
104384@@ -1479,6 +1494,10 @@ csum_error:
104385 bad_packet:
104386 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
104387 } else {
104388+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104389+ if (!grsec_enable_blackhole || (ret == 1 &&
104390+ (skb->dev->flags & IFF_LOOPBACK)))
104391+#endif
104392 tcp_v6_send_reset(NULL, skb);
104393 }
104394
104395diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
104396index 4836af8..0e52bbd 100644
104397--- a/net/ipv6/udp.c
104398+++ b/net/ipv6/udp.c
104399@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
104400 udp_ipv6_hash_secret + net_hash_mix(net));
104401 }
104402
104403+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104404+extern int grsec_enable_blackhole;
104405+#endif
104406+
104407 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
104408 {
104409 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
104410@@ -434,7 +438,7 @@ try_again:
104411 if (unlikely(err)) {
104412 trace_kfree_skb(skb, udpv6_recvmsg);
104413 if (!peeked) {
104414- atomic_inc(&sk->sk_drops);
104415+ atomic_inc_unchecked(&sk->sk_drops);
104416 if (is_udp4)
104417 UDP_INC_STATS_USER(sock_net(sk),
104418 UDP_MIB_INERRORS,
104419@@ -701,7 +705,7 @@ csum_error:
104420 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
104421 drop:
104422 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
104423- atomic_inc(&sk->sk_drops);
104424+ atomic_inc_unchecked(&sk->sk_drops);
104425 kfree_skb(skb);
104426 return -1;
104427 }
104428@@ -740,7 +744,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
104429 if (likely(skb1 == NULL))
104430 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
104431 if (!skb1) {
104432- atomic_inc(&sk->sk_drops);
104433+ atomic_inc_unchecked(&sk->sk_drops);
104434 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
104435 IS_UDPLITE(sk));
104436 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
104437@@ -915,6 +919,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
104438 goto csum_error;
104439
104440 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
104441+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
104442+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
104443+#endif
104444 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
104445
104446 kfree_skb(skb);
104447diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
104448index 2a0bbda..442240d 100644
104449--- a/net/ipv6/xfrm6_policy.c
104450+++ b/net/ipv6/xfrm6_policy.c
104451@@ -170,8 +170,10 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104452 case IPPROTO_DCCP:
104453 if (!onlyproto && (nh + offset + 4 < skb->data ||
104454 pskb_may_pull(skb, nh + offset + 4 - skb->data))) {
104455- __be16 *ports = (__be16 *)exthdr;
104456+ __be16 *ports;
104457
104458+ nh = skb_network_header(skb);
104459+ ports = (__be16 *)(nh + offset);
104460 fl6->fl6_sport = ports[!!reverse];
104461 fl6->fl6_dport = ports[!reverse];
104462 }
104463@@ -180,8 +182,10 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104464
104465 case IPPROTO_ICMPV6:
104466 if (!onlyproto && pskb_may_pull(skb, nh + offset + 2 - skb->data)) {
104467- u8 *icmp = (u8 *)exthdr;
104468+ u8 *icmp;
104469
104470+ nh = skb_network_header(skb);
104471+ icmp = (u8 *)(nh + offset);
104472 fl6->fl6_icmp_type = icmp[0];
104473 fl6->fl6_icmp_code = icmp[1];
104474 }
104475@@ -192,8 +196,9 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104476 case IPPROTO_MH:
104477 if (!onlyproto && pskb_may_pull(skb, nh + offset + 3 - skb->data)) {
104478 struct ip6_mh *mh;
104479- mh = (struct ip6_mh *)exthdr;
104480
104481+ nh = skb_network_header(skb);
104482+ mh = (struct ip6_mh *)(nh + offset);
104483 fl6->fl6_mh_type = mh->ip6mh_type;
104484 }
104485 fl6->flowi6_proto = nexthdr;
104486@@ -212,11 +217,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
104487 }
104488 }
104489
104490-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
104491+static int xfrm6_garbage_collect(struct dst_ops *ops)
104492 {
104493 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
104494
104495- xfrm6_policy_afinfo.garbage_collect(net);
104496+ xfrm_garbage_collect_deferred(net);
104497 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
104498 }
104499
104500@@ -329,19 +334,19 @@ static struct ctl_table xfrm6_policy_table[] = {
104501
104502 static int __net_init xfrm6_net_init(struct net *net)
104503 {
104504- struct ctl_table *table;
104505+ ctl_table_no_const *table = NULL;
104506 struct ctl_table_header *hdr;
104507
104508- table = xfrm6_policy_table;
104509 if (!net_eq(net, &init_net)) {
104510- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104511+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
104512 if (!table)
104513 goto err_alloc;
104514
104515 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
104516- }
104517+ hdr = register_net_sysctl(net, "net/ipv6", table);
104518+ } else
104519+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
104520
104521- hdr = register_net_sysctl(net, "net/ipv6", table);
104522 if (!hdr)
104523 goto err_reg;
104524
104525@@ -349,8 +354,7 @@ static int __net_init xfrm6_net_init(struct net *net)
104526 return 0;
104527
104528 err_reg:
104529- if (!net_eq(net, &init_net))
104530- kfree(table);
104531+ kfree(table);
104532 err_alloc:
104533 return -ENOMEM;
104534 }
104535diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
104536index e15c16a..7cf07aa 100644
104537--- a/net/ipx/ipx_proc.c
104538+++ b/net/ipx/ipx_proc.c
104539@@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
104540 struct proc_dir_entry *p;
104541 int rc = -ENOMEM;
104542
104543- ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
104544+ ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
104545
104546 if (!ipx_proc_dir)
104547 goto out;
104548diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
104549index 61ceb4c..e788eb8 100644
104550--- a/net/irda/ircomm/ircomm_tty.c
104551+++ b/net/irda/ircomm/ircomm_tty.c
104552@@ -317,10 +317,10 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104553 add_wait_queue(&port->open_wait, &wait);
104554
104555 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
104556- __FILE__, __LINE__, tty->driver->name, port->count);
104557+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104558
104559 spin_lock_irqsave(&port->lock, flags);
104560- port->count--;
104561+ atomic_dec(&port->count);
104562 port->blocked_open++;
104563 spin_unlock_irqrestore(&port->lock, flags);
104564
104565@@ -355,7 +355,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104566 }
104567
104568 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
104569- __FILE__, __LINE__, tty->driver->name, port->count);
104570+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104571
104572 schedule();
104573 }
104574@@ -365,12 +365,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
104575
104576 spin_lock_irqsave(&port->lock, flags);
104577 if (!tty_hung_up_p(filp))
104578- port->count++;
104579+ atomic_inc(&port->count);
104580 port->blocked_open--;
104581 spin_unlock_irqrestore(&port->lock, flags);
104582
104583 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
104584- __FILE__, __LINE__, tty->driver->name, port->count);
104585+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
104586
104587 if (!retval)
104588 port->flags |= ASYNC_NORMAL_ACTIVE;
104589@@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
104590
104591 /* ++ is not atomic, so this should be protected - Jean II */
104592 spin_lock_irqsave(&self->port.lock, flags);
104593- self->port.count++;
104594+ atomic_inc(&self->port.count);
104595 spin_unlock_irqrestore(&self->port.lock, flags);
104596 tty_port_tty_set(&self->port, tty);
104597
104598 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
104599- self->line, self->port.count);
104600+ self->line, atomic_read(&self->port.count));
104601
104602 /* Not really used by us, but lets do it anyway */
104603 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
104604@@ -985,7 +985,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
104605 tty_kref_put(port->tty);
104606 }
104607 port->tty = NULL;
104608- port->count = 0;
104609+ atomic_set(&port->count, 0);
104610 spin_unlock_irqrestore(&port->lock, flags);
104611
104612 wake_up_interruptible(&port->open_wait);
104613@@ -1342,7 +1342,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
104614 seq_putc(m, '\n');
104615
104616 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
104617- seq_printf(m, "Open count: %d\n", self->port.count);
104618+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
104619 seq_printf(m, "Max data size: %d\n", self->max_data_size);
104620 seq_printf(m, "Max header size: %d\n", self->max_header_size);
104621
104622diff --git a/net/irda/irproc.c b/net/irda/irproc.c
104623index b9ac598..f88cc56 100644
104624--- a/net/irda/irproc.c
104625+++ b/net/irda/irproc.c
104626@@ -66,7 +66,7 @@ void __init irda_proc_register(void)
104627 {
104628 int i;
104629
104630- proc_irda = proc_mkdir("irda", init_net.proc_net);
104631+ proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
104632 if (proc_irda == NULL)
104633 return;
104634
104635diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
104636index a089b6b..3ca3b60 100644
104637--- a/net/iucv/af_iucv.c
104638+++ b/net/iucv/af_iucv.c
104639@@ -686,10 +686,10 @@ static void __iucv_auto_name(struct iucv_sock *iucv)
104640 {
104641 char name[12];
104642
104643- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
104644+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104645 while (__iucv_get_sock_by_name(name)) {
104646 sprintf(name, "%08x",
104647- atomic_inc_return(&iucv_sk_list.autobind_name));
104648+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
104649 }
104650 memcpy(iucv->src_name, name, 8);
104651 }
104652diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
104653index da78793..bdd78cf 100644
104654--- a/net/iucv/iucv.c
104655+++ b/net/iucv/iucv.c
104656@@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
104657 return NOTIFY_OK;
104658 }
104659
104660-static struct notifier_block __refdata iucv_cpu_notifier = {
104661+static struct notifier_block iucv_cpu_notifier = {
104662 .notifier_call = iucv_cpu_notify,
104663 };
104664
104665diff --git a/net/key/af_key.c b/net/key/af_key.c
104666index 1847ec4..26ef732 100644
104667--- a/net/key/af_key.c
104668+++ b/net/key/af_key.c
104669@@ -3049,10 +3049,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
104670 static u32 get_acqseq(void)
104671 {
104672 u32 res;
104673- static atomic_t acqseq;
104674+ static atomic_unchecked_t acqseq;
104675
104676 do {
104677- res = atomic_inc_return(&acqseq);
104678+ res = atomic_inc_return_unchecked(&acqseq);
104679 } while (!res);
104680 return res;
104681 }
104682diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
104683index edb78e6..8dc654a 100644
104684--- a/net/l2tp/l2tp_eth.c
104685+++ b/net/l2tp/l2tp_eth.c
104686@@ -42,12 +42,12 @@ struct l2tp_eth {
104687 struct sock *tunnel_sock;
104688 struct l2tp_session *session;
104689 struct list_head list;
104690- atomic_long_t tx_bytes;
104691- atomic_long_t tx_packets;
104692- atomic_long_t tx_dropped;
104693- atomic_long_t rx_bytes;
104694- atomic_long_t rx_packets;
104695- atomic_long_t rx_errors;
104696+ atomic_long_unchecked_t tx_bytes;
104697+ atomic_long_unchecked_t tx_packets;
104698+ atomic_long_unchecked_t tx_dropped;
104699+ atomic_long_unchecked_t rx_bytes;
104700+ atomic_long_unchecked_t rx_packets;
104701+ atomic_long_unchecked_t rx_errors;
104702 };
104703
104704 /* via l2tp_session_priv() */
104705@@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
104706 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
104707
104708 if (likely(ret == NET_XMIT_SUCCESS)) {
104709- atomic_long_add(len, &priv->tx_bytes);
104710- atomic_long_inc(&priv->tx_packets);
104711+ atomic_long_add_unchecked(len, &priv->tx_bytes);
104712+ atomic_long_inc_unchecked(&priv->tx_packets);
104713 } else {
104714- atomic_long_inc(&priv->tx_dropped);
104715+ atomic_long_inc_unchecked(&priv->tx_dropped);
104716 }
104717 return NETDEV_TX_OK;
104718 }
104719@@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
104720 {
104721 struct l2tp_eth *priv = netdev_priv(dev);
104722
104723- stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
104724- stats->tx_packets = atomic_long_read(&priv->tx_packets);
104725- stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
104726- stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
104727- stats->rx_packets = atomic_long_read(&priv->rx_packets);
104728- stats->rx_errors = atomic_long_read(&priv->rx_errors);
104729+ stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
104730+ stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
104731+ stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
104732+ stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
104733+ stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
104734+ stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
104735 return stats;
104736 }
104737
104738@@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
104739 nf_reset(skb);
104740
104741 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
104742- atomic_long_inc(&priv->rx_packets);
104743- atomic_long_add(data_len, &priv->rx_bytes);
104744+ atomic_long_inc_unchecked(&priv->rx_packets);
104745+ atomic_long_add_unchecked(data_len, &priv->rx_bytes);
104746 } else {
104747- atomic_long_inc(&priv->rx_errors);
104748+ atomic_long_inc_unchecked(&priv->rx_errors);
104749 }
104750 return;
104751
104752 error:
104753- atomic_long_inc(&priv->rx_errors);
104754+ atomic_long_inc_unchecked(&priv->rx_errors);
104755 kfree_skb(skb);
104756 }
104757
104758diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
104759index 1a3c7e0..80f8b0c 100644
104760--- a/net/llc/llc_proc.c
104761+++ b/net/llc/llc_proc.c
104762@@ -247,7 +247,7 @@ int __init llc_proc_init(void)
104763 int rc = -ENOMEM;
104764 struct proc_dir_entry *p;
104765
104766- llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
104767+ llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
104768 if (!llc_proc_dir)
104769 goto out;
104770
104771diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
104772index 927b4ea..88a30e2 100644
104773--- a/net/mac80211/cfg.c
104774+++ b/net/mac80211/cfg.c
104775@@ -540,7 +540,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
104776 ret = ieee80211_vif_use_channel(sdata, chandef,
104777 IEEE80211_CHANCTX_EXCLUSIVE);
104778 }
104779- } else if (local->open_count == local->monitors) {
104780+ } else if (local_read(&local->open_count) == local->monitors) {
104781 local->_oper_chandef = *chandef;
104782 ieee80211_hw_config(local, 0);
104783 }
104784@@ -3286,7 +3286,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
104785 else
104786 local->probe_req_reg--;
104787
104788- if (!local->open_count)
104789+ if (!local_read(&local->open_count))
104790 break;
104791
104792 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
104793@@ -3420,8 +3420,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
104794 if (chanctx_conf) {
104795 *chandef = chanctx_conf->def;
104796 ret = 0;
104797- } else if (local->open_count > 0 &&
104798- local->open_count == local->monitors &&
104799+ } else if (local_read(&local->open_count) > 0 &&
104800+ local_read(&local->open_count) == local->monitors &&
104801 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
104802 if (local->use_chanctx)
104803 *chandef = local->monitor_chandef;
104804diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
104805index ef7a089..fe1caf7 100644
104806--- a/net/mac80211/ieee80211_i.h
104807+++ b/net/mac80211/ieee80211_i.h
104808@@ -28,6 +28,7 @@
104809 #include <net/ieee80211_radiotap.h>
104810 #include <net/cfg80211.h>
104811 #include <net/mac80211.h>
104812+#include <asm/local.h>
104813 #include "key.h"
104814 #include "sta_info.h"
104815 #include "debug.h"
104816@@ -1055,7 +1056,7 @@ struct ieee80211_local {
104817 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
104818 spinlock_t queue_stop_reason_lock;
104819
104820- int open_count;
104821+ local_t open_count;
104822 int monitors, cooked_mntrs;
104823 /* number of interfaces with corresponding FIF_ flags */
104824 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
104825diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
104826index f75e5f1..3d9ad4f 100644
104827--- a/net/mac80211/iface.c
104828+++ b/net/mac80211/iface.c
104829@@ -531,7 +531,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104830 break;
104831 }
104832
104833- if (local->open_count == 0) {
104834+ if (local_read(&local->open_count) == 0) {
104835 res = drv_start(local);
104836 if (res)
104837 goto err_del_bss;
104838@@ -578,7 +578,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104839 res = drv_add_interface(local, sdata);
104840 if (res)
104841 goto err_stop;
104842- } else if (local->monitors == 0 && local->open_count == 0) {
104843+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
104844 res = ieee80211_add_virtual_monitor(local);
104845 if (res)
104846 goto err_stop;
104847@@ -687,7 +687,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104848 atomic_inc(&local->iff_promiscs);
104849
104850 if (coming_up)
104851- local->open_count++;
104852+ local_inc(&local->open_count);
104853
104854 if (hw_reconf_flags)
104855 ieee80211_hw_config(local, hw_reconf_flags);
104856@@ -725,7 +725,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
104857 err_del_interface:
104858 drv_remove_interface(local, sdata);
104859 err_stop:
104860- if (!local->open_count)
104861+ if (!local_read(&local->open_count))
104862 drv_stop(local);
104863 err_del_bss:
104864 sdata->bss = NULL;
104865@@ -889,7 +889,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104866 }
104867
104868 if (going_down)
104869- local->open_count--;
104870+ local_dec(&local->open_count);
104871
104872 switch (sdata->vif.type) {
104873 case NL80211_IFTYPE_AP_VLAN:
104874@@ -950,7 +950,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104875 }
104876 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
104877
104878- if (local->open_count == 0)
104879+ if (local_read(&local->open_count) == 0)
104880 ieee80211_clear_tx_pending(local);
104881
104882 /*
104883@@ -990,7 +990,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104884
104885 ieee80211_recalc_ps(local, -1);
104886
104887- if (local->open_count == 0) {
104888+ if (local_read(&local->open_count) == 0) {
104889 ieee80211_stop_device(local);
104890
104891 /* no reconfiguring after stop! */
104892@@ -1001,7 +1001,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
104893 ieee80211_configure_filter(local);
104894 ieee80211_hw_config(local, hw_reconf_flags);
104895
104896- if (local->monitors == local->open_count)
104897+ if (local->monitors == local_read(&local->open_count))
104898 ieee80211_add_virtual_monitor(local);
104899 }
104900
104901diff --git a/net/mac80211/main.c b/net/mac80211/main.c
104902index e0ab432..36b7b94 100644
104903--- a/net/mac80211/main.c
104904+++ b/net/mac80211/main.c
104905@@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
104906 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
104907 IEEE80211_CONF_CHANGE_POWER);
104908
104909- if (changed && local->open_count) {
104910+ if (changed && local_read(&local->open_count)) {
104911 ret = drv_config(local, changed);
104912 /*
104913 * Goal:
104914diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
104915index 4c5192e..04cc0d8 100644
104916--- a/net/mac80211/pm.c
104917+++ b/net/mac80211/pm.c
104918@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104919 struct ieee80211_sub_if_data *sdata;
104920 struct sta_info *sta;
104921
104922- if (!local->open_count)
104923+ if (!local_read(&local->open_count))
104924 goto suspend;
104925
104926 ieee80211_scan_cancel(local);
104927@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104928 cancel_work_sync(&local->dynamic_ps_enable_work);
104929 del_timer_sync(&local->dynamic_ps_timer);
104930
104931- local->wowlan = wowlan && local->open_count;
104932+ local->wowlan = wowlan && local_read(&local->open_count);
104933 if (local->wowlan) {
104934 int err = drv_suspend(local, wowlan);
104935 if (err < 0) {
104936@@ -125,7 +125,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
104937 WARN_ON(!list_empty(&local->chanctx_list));
104938
104939 /* stop hardware - this must stop RX */
104940- if (local->open_count)
104941+ if (local_read(&local->open_count))
104942 ieee80211_stop_device(local);
104943
104944 suspend:
104945diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
104946index 6081329..ab23834 100644
104947--- a/net/mac80211/rate.c
104948+++ b/net/mac80211/rate.c
104949@@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
104950
104951 ASSERT_RTNL();
104952
104953- if (local->open_count)
104954+ if (local_read(&local->open_count))
104955 return -EBUSY;
104956
104957 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
104958diff --git a/net/mac80211/util.c b/net/mac80211/util.c
104959index 725af7a..a21a20a 100644
104960--- a/net/mac80211/util.c
104961+++ b/net/mac80211/util.c
104962@@ -1643,7 +1643,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104963 }
104964 #endif
104965 /* everything else happens only if HW was up & running */
104966- if (!local->open_count)
104967+ if (!local_read(&local->open_count))
104968 goto wake_up;
104969
104970 /*
104971@@ -1869,7 +1869,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
104972 local->in_reconfig = false;
104973 barrier();
104974
104975- if (local->monitors == local->open_count && local->monitors > 0)
104976+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
104977 ieee80211_add_virtual_monitor(local);
104978
104979 /*
104980diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
104981index 6d77cce..36e2fc3 100644
104982--- a/net/netfilter/Kconfig
104983+++ b/net/netfilter/Kconfig
104984@@ -1096,6 +1096,16 @@ config NETFILTER_XT_MATCH_ESP
104985
104986 To compile it as a module, choose M here. If unsure, say N.
104987
104988+config NETFILTER_XT_MATCH_GRADM
104989+ tristate '"gradm" match support'
104990+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
104991+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
104992+ ---help---
104993+ The gradm match allows to match on grsecurity RBAC being enabled.
104994+ It is useful when iptables rules are applied early on bootup to
104995+ prevent connections to the machine (except from a trusted host)
104996+ while the RBAC system is disabled.
104997+
104998 config NETFILTER_XT_MATCH_HASHLIMIT
104999 tristate '"hashlimit" match support'
105000 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
105001diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
105002index fad5fdb..ba3672a 100644
105003--- a/net/netfilter/Makefile
105004+++ b/net/netfilter/Makefile
105005@@ -136,6 +136,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
105006 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
105007 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
105008 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
105009+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
105010 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
105011 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
105012 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
105013diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
105014index ec8114f..6b2bfba 100644
105015--- a/net/netfilter/ipset/ip_set_core.c
105016+++ b/net/netfilter/ipset/ip_set_core.c
105017@@ -1921,7 +1921,7 @@ done:
105018 return ret;
105019 }
105020
105021-static struct nf_sockopt_ops so_set __read_mostly = {
105022+static struct nf_sockopt_ops so_set = {
105023 .pf = PF_INET,
105024 .get_optmin = SO_IP_SET,
105025 .get_optmax = SO_IP_SET + 1,
105026diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
105027index 610e19c..08d0c3f 100644
105028--- a/net/netfilter/ipvs/ip_vs_conn.c
105029+++ b/net/netfilter/ipvs/ip_vs_conn.c
105030@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
105031 /* Increase the refcnt counter of the dest */
105032 ip_vs_dest_hold(dest);
105033
105034- conn_flags = atomic_read(&dest->conn_flags);
105035+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
105036 if (cp->protocol != IPPROTO_UDP)
105037 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
105038 flags = cp->flags;
105039@@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
105040
105041 cp->control = NULL;
105042 atomic_set(&cp->n_control, 0);
105043- atomic_set(&cp->in_pkts, 0);
105044+ atomic_set_unchecked(&cp->in_pkts, 0);
105045
105046 cp->packet_xmit = NULL;
105047 cp->app = NULL;
105048@@ -1187,7 +1187,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
105049
105050 /* Don't drop the entry if its number of incoming packets is not
105051 located in [0, 8] */
105052- i = atomic_read(&cp->in_pkts);
105053+ i = atomic_read_unchecked(&cp->in_pkts);
105054 if (i > 8 || i < 0) return 0;
105055
105056 if (!todrop_rate[i]) return 0;
105057diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
105058index 5c34e8d..0d8eb7f 100644
105059--- a/net/netfilter/ipvs/ip_vs_core.c
105060+++ b/net/netfilter/ipvs/ip_vs_core.c
105061@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
105062 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
105063 /* do not touch skb anymore */
105064
105065- atomic_inc(&cp->in_pkts);
105066+ atomic_inc_unchecked(&cp->in_pkts);
105067 ip_vs_conn_put(cp);
105068 return ret;
105069 }
105070@@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
105071 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
105072 pkts = sysctl_sync_threshold(ipvs);
105073 else
105074- pkts = atomic_add_return(1, &cp->in_pkts);
105075+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105076
105077 if (ipvs->sync_state & IP_VS_STATE_MASTER)
105078 ip_vs_sync_conn(net, cp, pkts);
105079diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
105080index fd3f444..ab28fa24 100644
105081--- a/net/netfilter/ipvs/ip_vs_ctl.c
105082+++ b/net/netfilter/ipvs/ip_vs_ctl.c
105083@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
105084 */
105085 ip_vs_rs_hash(ipvs, dest);
105086 }
105087- atomic_set(&dest->conn_flags, conn_flags);
105088+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
105089
105090 /* bind the service */
105091 old_svc = rcu_dereference_protected(dest->svc, 1);
105092@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
105093 * align with netns init in ip_vs_control_net_init()
105094 */
105095
105096-static struct ctl_table vs_vars[] = {
105097+static ctl_table_no_const vs_vars[] __read_only = {
105098 {
105099 .procname = "amemthresh",
105100 .maxlen = sizeof(int),
105101@@ -1989,7 +1989,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
105102 " %-7s %-6d %-10d %-10d\n",
105103 &dest->addr.in6,
105104 ntohs(dest->port),
105105- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
105106+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
105107 atomic_read(&dest->weight),
105108 atomic_read(&dest->activeconns),
105109 atomic_read(&dest->inactconns));
105110@@ -2000,7 +2000,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
105111 "%-7s %-6d %-10d %-10d\n",
105112 ntohl(dest->addr.ip),
105113 ntohs(dest->port),
105114- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
105115+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
105116 atomic_read(&dest->weight),
105117 atomic_read(&dest->activeconns),
105118 atomic_read(&dest->inactconns));
105119@@ -2471,7 +2471,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
105120
105121 entry.addr = dest->addr.ip;
105122 entry.port = dest->port;
105123- entry.conn_flags = atomic_read(&dest->conn_flags);
105124+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
105125 entry.weight = atomic_read(&dest->weight);
105126 entry.u_threshold = dest->u_threshold;
105127 entry.l_threshold = dest->l_threshold;
105128@@ -3010,7 +3010,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
105129 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
105130 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
105131 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
105132- (atomic_read(&dest->conn_flags) &
105133+ (atomic_read_unchecked(&dest->conn_flags) &
105134 IP_VS_CONN_F_FWD_MASK)) ||
105135 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
105136 atomic_read(&dest->weight)) ||
105137@@ -3600,7 +3600,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
105138 {
105139 int idx;
105140 struct netns_ipvs *ipvs = net_ipvs(net);
105141- struct ctl_table *tbl;
105142+ ctl_table_no_const *tbl;
105143
105144 atomic_set(&ipvs->dropentry, 0);
105145 spin_lock_init(&ipvs->dropentry_lock);
105146diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
105147index 547ff33..c8c8117 100644
105148--- a/net/netfilter/ipvs/ip_vs_lblc.c
105149+++ b/net/netfilter/ipvs/ip_vs_lblc.c
105150@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
105151 * IPVS LBLC sysctl table
105152 */
105153 #ifdef CONFIG_SYSCTL
105154-static struct ctl_table vs_vars_table[] = {
105155+static ctl_table_no_const vs_vars_table[] __read_only = {
105156 {
105157 .procname = "lblc_expiration",
105158 .data = NULL,
105159diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
105160index 3f21a2f..a112e85 100644
105161--- a/net/netfilter/ipvs/ip_vs_lblcr.c
105162+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
105163@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
105164 * IPVS LBLCR sysctl table
105165 */
105166
105167-static struct ctl_table vs_vars_table[] = {
105168+static ctl_table_no_const vs_vars_table[] __read_only = {
105169 {
105170 .procname = "lblcr_expiration",
105171 .data = NULL,
105172diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
105173index eadffb2..c2feeae 100644
105174--- a/net/netfilter/ipvs/ip_vs_sync.c
105175+++ b/net/netfilter/ipvs/ip_vs_sync.c
105176@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
105177 cp = cp->control;
105178 if (cp) {
105179 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
105180- pkts = atomic_add_return(1, &cp->in_pkts);
105181+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105182 else
105183 pkts = sysctl_sync_threshold(ipvs);
105184 ip_vs_sync_conn(net, cp->control, pkts);
105185@@ -771,7 +771,7 @@ control:
105186 if (!cp)
105187 return;
105188 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
105189- pkts = atomic_add_return(1, &cp->in_pkts);
105190+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
105191 else
105192 pkts = sysctl_sync_threshold(ipvs);
105193 goto sloop;
105194@@ -894,7 +894,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
105195
105196 if (opt)
105197 memcpy(&cp->in_seq, opt, sizeof(*opt));
105198- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
105199+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
105200 cp->state = state;
105201 cp->old_state = cp->state;
105202 /*
105203diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
105204index 56896a4..dfe3806 100644
105205--- a/net/netfilter/ipvs/ip_vs_xmit.c
105206+++ b/net/netfilter/ipvs/ip_vs_xmit.c
105207@@ -1114,7 +1114,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
105208 else
105209 rc = NF_ACCEPT;
105210 /* do not touch skb anymore */
105211- atomic_inc(&cp->in_pkts);
105212+ atomic_inc_unchecked(&cp->in_pkts);
105213 goto out;
105214 }
105215
105216@@ -1206,7 +1206,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
105217 else
105218 rc = NF_ACCEPT;
105219 /* do not touch skb anymore */
105220- atomic_inc(&cp->in_pkts);
105221+ atomic_inc_unchecked(&cp->in_pkts);
105222 goto out;
105223 }
105224
105225diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
105226index a4b5e2a..13b1de3 100644
105227--- a/net/netfilter/nf_conntrack_acct.c
105228+++ b/net/netfilter/nf_conntrack_acct.c
105229@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
105230 #ifdef CONFIG_SYSCTL
105231 static int nf_conntrack_acct_init_sysctl(struct net *net)
105232 {
105233- struct ctl_table *table;
105234+ ctl_table_no_const *table;
105235
105236 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
105237 GFP_KERNEL);
105238diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
105239index de88c4a..ec84234 100644
105240--- a/net/netfilter/nf_conntrack_core.c
105241+++ b/net/netfilter/nf_conntrack_core.c
105242@@ -1739,6 +1739,10 @@ void nf_conntrack_init_end(void)
105243 #define DYING_NULLS_VAL ((1<<30)+1)
105244 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
105245
105246+#ifdef CONFIG_GRKERNSEC_HIDESYM
105247+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
105248+#endif
105249+
105250 int nf_conntrack_init_net(struct net *net)
105251 {
105252 int ret = -ENOMEM;
105253@@ -1764,7 +1768,11 @@ int nf_conntrack_init_net(struct net *net)
105254 if (!net->ct.stat)
105255 goto err_pcpu_lists;
105256
105257+#ifdef CONFIG_GRKERNSEC_HIDESYM
105258+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
105259+#else
105260 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
105261+#endif
105262 if (!net->ct.slabname)
105263 goto err_slabname;
105264
105265diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
105266index 4e78c57..ec8fb74 100644
105267--- a/net/netfilter/nf_conntrack_ecache.c
105268+++ b/net/netfilter/nf_conntrack_ecache.c
105269@@ -264,7 +264,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
105270 #ifdef CONFIG_SYSCTL
105271 static int nf_conntrack_event_init_sysctl(struct net *net)
105272 {
105273- struct ctl_table *table;
105274+ ctl_table_no_const *table;
105275
105276 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
105277 GFP_KERNEL);
105278diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
105279index 5b3eae7..dd4b8fe 100644
105280--- a/net/netfilter/nf_conntrack_helper.c
105281+++ b/net/netfilter/nf_conntrack_helper.c
105282@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
105283
105284 static int nf_conntrack_helper_init_sysctl(struct net *net)
105285 {
105286- struct ctl_table *table;
105287+ ctl_table_no_const *table;
105288
105289 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
105290 GFP_KERNEL);
105291diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
105292index b65d586..beec902 100644
105293--- a/net/netfilter/nf_conntrack_proto.c
105294+++ b/net/netfilter/nf_conntrack_proto.c
105295@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
105296
105297 static void
105298 nf_ct_unregister_sysctl(struct ctl_table_header **header,
105299- struct ctl_table **table,
105300+ ctl_table_no_const **table,
105301 unsigned int users)
105302 {
105303 if (users > 0)
105304diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
105305index f641751..d3c5b51 100644
105306--- a/net/netfilter/nf_conntrack_standalone.c
105307+++ b/net/netfilter/nf_conntrack_standalone.c
105308@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
105309
105310 static int nf_conntrack_standalone_init_sysctl(struct net *net)
105311 {
105312- struct ctl_table *table;
105313+ ctl_table_no_const *table;
105314
105315 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
105316 GFP_KERNEL);
105317diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
105318index 7a394df..bd91a8a 100644
105319--- a/net/netfilter/nf_conntrack_timestamp.c
105320+++ b/net/netfilter/nf_conntrack_timestamp.c
105321@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
105322 #ifdef CONFIG_SYSCTL
105323 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
105324 {
105325- struct ctl_table *table;
105326+ ctl_table_no_const *table;
105327
105328 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
105329 GFP_KERNEL);
105330diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
105331index daad602..384be13 100644
105332--- a/net/netfilter/nf_log.c
105333+++ b/net/netfilter/nf_log.c
105334@@ -353,7 +353,7 @@ static const struct file_operations nflog_file_ops = {
105335
105336 #ifdef CONFIG_SYSCTL
105337 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
105338-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
105339+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
105340
105341 static int nf_log_proc_dostring(struct ctl_table *table, int write,
105342 void __user *buffer, size_t *lenp, loff_t *ppos)
105343@@ -384,14 +384,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
105344 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
105345 mutex_unlock(&nf_log_mutex);
105346 } else {
105347+ ctl_table_no_const nf_log_table = *table;
105348+
105349 mutex_lock(&nf_log_mutex);
105350 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
105351 lockdep_is_held(&nf_log_mutex));
105352 if (!logger)
105353- table->data = "NONE";
105354+ nf_log_table.data = "NONE";
105355 else
105356- table->data = logger->name;
105357- r = proc_dostring(table, write, buffer, lenp, ppos);
105358+ nf_log_table.data = logger->name;
105359+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
105360 mutex_unlock(&nf_log_mutex);
105361 }
105362
105363diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
105364index c68c1e5..8b5d670 100644
105365--- a/net/netfilter/nf_sockopt.c
105366+++ b/net/netfilter/nf_sockopt.c
105367@@ -43,7 +43,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
105368 }
105369 }
105370
105371- list_add(&reg->list, &nf_sockopts);
105372+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
105373 out:
105374 mutex_unlock(&nf_sockopt_mutex);
105375 return ret;
105376@@ -53,7 +53,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
105377 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
105378 {
105379 mutex_lock(&nf_sockopt_mutex);
105380- list_del(&reg->list);
105381+ pax_list_del((struct list_head *)&reg->list);
105382 mutex_unlock(&nf_sockopt_mutex);
105383 }
105384 EXPORT_SYMBOL(nf_unregister_sockopt);
105385diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
105386index a11c5ff..aa413a7 100644
105387--- a/net/netfilter/nfnetlink_log.c
105388+++ b/net/netfilter/nfnetlink_log.c
105389@@ -79,7 +79,7 @@ static int nfnl_log_net_id __read_mostly;
105390 struct nfnl_log_net {
105391 spinlock_t instances_lock;
105392 struct hlist_head instance_table[INSTANCE_BUCKETS];
105393- atomic_t global_seq;
105394+ atomic_unchecked_t global_seq;
105395 };
105396
105397 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
105398@@ -561,7 +561,7 @@ __build_packet_message(struct nfnl_log_net *log,
105399 /* global sequence number */
105400 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
105401 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
105402- htonl(atomic_inc_return(&log->global_seq))))
105403+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
105404 goto nla_put_failure;
105405
105406 if (data_len) {
105407diff --git a/net/netfilter/nfnetlink_queue_core.c b/net/netfilter/nfnetlink_queue_core.c
105408index 108120f..5b169db 100644
105409--- a/net/netfilter/nfnetlink_queue_core.c
105410+++ b/net/netfilter/nfnetlink_queue_core.c
105411@@ -665,7 +665,7 @@ nfqnl_enqueue_packet(struct nf_queue_entry *entry, unsigned int queuenum)
105412 * returned by nf_queue. For instance, callers rely on -ECANCELED to
105413 * mean 'ignore this hook'.
105414 */
105415- if (IS_ERR(segs))
105416+ if (IS_ERR_OR_NULL(segs))
105417 goto out_err;
105418 queued = 0;
105419 err = 0;
105420diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
105421index 1840989..6895744 100644
105422--- a/net/netfilter/nft_compat.c
105423+++ b/net/netfilter/nft_compat.c
105424@@ -225,7 +225,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
105425 /* We want to reuse existing compat_to_user */
105426 old_fs = get_fs();
105427 set_fs(KERNEL_DS);
105428- t->compat_to_user(out, in);
105429+ t->compat_to_user((void __force_user *)out, in);
105430 set_fs(old_fs);
105431 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
105432 kfree(out);
105433@@ -421,7 +421,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
105434 /* We want to reuse existing compat_to_user */
105435 old_fs = get_fs();
105436 set_fs(KERNEL_DS);
105437- m->compat_to_user(out, in);
105438+ m->compat_to_user((void __force_user *)out, in);
105439 set_fs(old_fs);
105440 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
105441 kfree(out);
105442diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
105443new file mode 100644
105444index 0000000..c566332
105445--- /dev/null
105446+++ b/net/netfilter/xt_gradm.c
105447@@ -0,0 +1,51 @@
105448+/*
105449+ * gradm match for netfilter
105450